diff --git a/changes/issue-add-missing-platforms b/changes/issue-add-missing-platforms new file mode 100644 index 0000000000..b1ee72f1be --- /dev/null +++ b/changes/issue-add-missing-platforms @@ -0,0 +1,2 @@ +* Add missing software inventory and `disk_space_unix` for Debian hosts. Unify definition of linux hosts. + diff --git a/server/fleet/hosts.go b/server/fleet/hosts.go index 7bee5b40dc..26873fb642 100644 --- a/server/fleet/hosts.go +++ b/server/fleet/hosts.go @@ -216,6 +216,20 @@ func (h *Host) FleetPlatform() string { return PlatformFromHost(h.Platform) } +// HostLinuxOSs are the possible linux values for Host.Platform. +var HostLinuxOSs = []string{ + "linux", "ubuntu", "debian", "rhel", "centos", "sles", "kali", "gentoo", +} + +func isLinux(hostPlatform string) bool { + for _, linuxPlatform := range HostLinuxOSs { + if linuxPlatform == hostPlatform { + return true + } + } + return false +} + // PlatformFromHost converts the given host platform into // the generic platforms known by osquery // https://osquery.readthedocs.io/en/stable/deployment/configuration/ @@ -223,10 +237,10 @@ func (h *Host) FleetPlatform() string { // // Returns empty string if hostPlatform is unknnown. func PlatformFromHost(hostPlatform string) string { - switch hostPlatform { - case "ubuntu", "rhel", "debian": + switch { + case isLinux(hostPlatform): return "linux" - case "darwin", "windows": + case hostPlatform == "darwin", hostPlatform == "windows": return hostPlatform default: return "" diff --git a/server/fleet/hosts_test.go b/server/fleet/hosts_test.go index 1d67519a94..2d92121163 100644 --- a/server/fleet/hosts_test.go +++ b/server/fleet/hosts_test.go @@ -6,6 +6,7 @@ import ( "github.com/WatchBeam/clock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestHostStatus(t *testing.T) { @@ -60,3 +61,63 @@ func TestHostIsNew(t *testing.T) { host.CreatedAt = mockClock.Now().AddDate(0, 0, -2) assert.False(t, host.IsNew(mockClock.Now())) } + +func TestPlatformFromHost(t *testing.T) { + for _, tc := range []struct { + host string + expPlatform string + }{ + { + host: "unknown", + expPlatform: "", + }, + { + host: "", + expPlatform: "", + }, + { + host: "linux", + expPlatform: "linux", + }, + { + host: "ubuntu", + expPlatform: "linux", + }, + { + host: "debian", + expPlatform: "linux", + }, + { + host: "rhel", + expPlatform: "linux", + }, + { + host: "centos", + expPlatform: "linux", + }, + { + host: "sles", + expPlatform: "linux", + }, + { + host: "kali", + expPlatform: "linux", + }, + { + host: "gentoo", + expPlatform: "linux", + }, + { + host: "darwin", + expPlatform: "darwin", + }, + { + host: "windows", + expPlatform: "windows", + }, + } { + fleetPlatform := PlatformFromHost(tc.host) + require.Equal(t, tc.expPlatform, fleetPlatform) + + } +} diff --git a/server/service/osquery_utils/queries.go b/server/service/osquery_utils/queries.go index eee2584728..5257df1def 100644 --- a/server/service/osquery_utils/queries.go +++ b/server/service/osquery_utils/queries.go @@ -339,7 +339,7 @@ var detailQueries = map[string]DetailQuery{ SELECT (blocks_available * 100 / blocks) AS percent_disk_space_available, round((blocks_available * blocks_size *10e-10),2) AS gigs_disk_space_available FROM mounts WHERE path = '/' LIMIT 1;`, - Platforms: []string{"darwin", "linux", "rhel", "ubuntu", "centos"}, + Platforms: append(fleet.HostLinuxOSs, "darwin"), IngestFunc: ingestDiskSpace, }, "disk_space_windows": { @@ -450,7 +450,7 @@ SELECT 'python_packages' AS source FROM python_packages; `, - Platforms: []string{"linux", "rhel", "ubuntu", "centos"}, + Platforms: fleet.HostLinuxOSs, IngestFunc: ingestSoftware, }