Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always lowercase FQDN #180

Merged
merged 8 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/180.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
Lowercase the returned OS.Hostname and FQDN values as per Elastic
Common Schema (ECS) guidelines for the `host.name` field.
```
3 changes: 2 additions & 1 deletion providers/aix/host_aix_ppc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/joeshaw/multierror"
Expand Down Expand Up @@ -173,7 +174,7 @@ func (r *reader) hostname(h *host) {
if r.addErr(err) {
return
}
h.info.Hostname = v
h.info.Hostname = strings.ToLower(v)
}

func (r *reader) network(h *host) {
Expand Down
3 changes: 2 additions & 1 deletion providers/darwin/host_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/joeshaw/multierror"
Expand Down Expand Up @@ -213,7 +214,7 @@ func (r *reader) hostname(h *host) {
if r.addErr(err) {
return
}
h.info.Hostname = v
h.info.Hostname = strings.ToLower(v)
}

func (r *reader) network(h *host) {
Expand Down
3 changes: 2 additions & 1 deletion providers/linux/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"

"github.com/joeshaw/multierror"
Expand Down Expand Up @@ -212,7 +213,7 @@ func (r *reader) hostname(h *host) {
if r.addErr(err) {
return
}
h.info.Hostname = v
h.info.Hostname = strings.ToLower(v)
}

func (r *reader) network(h *host) {
Expand Down
4 changes: 2 additions & 2 deletions providers/shared/fqdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func fqdn(hostname string) (string, error) {
err)
}
if cname != "" {
return strings.TrimSuffix(cname, "."), nil
return strings.ToLower(strings.TrimSuffix(cname, ".")), nil
}

ips, err := net.LookupIP(hostname)
Expand All @@ -70,7 +70,7 @@ func fqdn(hostname string) (string, error) {
if err != nil || len(names) == 0 {
continue
}
return strings.TrimSuffix(names[0], "."), nil
return strings.ToLower(strings.TrimSuffix(names[0], ".")), nil
}

return "", errs
Expand Down
5 changes: 5 additions & 0 deletions providers/shared/fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func TestFQDN(t *testing.T) {
expectedFQDN: "",
expectedErrRegex: makeErrorRegex("foobarbaz"),
},
"long_mixed_case_hostname": {
osHostname: "eLaSTic.co",
expectedFQDN: "elastic.co",
expectedErrRegex: "",
},
}

for name, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions providers/windows/host_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (h *host) FQDN() (string, error) {
return "", fmt.Errorf("could not get windows FQDN: %s", err)
}

return strings.TrimSuffix(fqdn, "."), nil
return strings.ToLower(strings.TrimSuffix(fqdn, ".")), nil
}

func newHost() (*host, error) {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *reader) hostname(h *host) {
if r.addErr(err) {
return
}
h.info.Hostname = v
h.info.Hostname = strings.ToLower(v)
}

func getComputerNameEx(name uint32) (string, error) {
Expand Down
4 changes: 3 additions & 1 deletion types/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Host interface {
CPUTimer
Info() HostInfo
Memory() (*HostMemoryInfo, error)

// FQDN returns the fully-qualified domain name of the host, lowercased.
FQDN() (string, error)
}

Expand Down Expand Up @@ -67,7 +69,7 @@ type HostInfo struct {
Architecture string `json:"architecture"` // Hardware architecture (e.g. x86_64, arm, ppc, mips).
BootTime time.Time `json:"boot_time"` // Host boot time.
Containerized *bool `json:"containerized,omitempty"` // Is the process containerized.
Hostname string `json:"name"` // Hostname
Hostname string `json:"name"` // Hostname, lowercased.
IPs []string `json:"ip,omitempty"` // List of all IPs.
KernelVersion string `json:"kernel_version"` // Kernel version.
MACs []string `json:"mac"` // List of MAC addresses.
Expand Down