Add HostLinuxOSs (#3217)

* Add HostLinuxOSs

* Add test for PlatformFromHost

* Add sles, gentoo and kali on linux host OSs
This commit is contained in:
Lucas Manuel Rodriguez 2021-12-07 15:37:00 -03:00 committed by GitHub
parent 04fe0a42b5
commit 8cea7f480a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 5 deletions

View file

@ -0,0 +1,2 @@
* Add missing software inventory and `disk_space_unix` for Debian hosts. Unify definition of linux hosts.

View file

@ -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 ""

View file

@ -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)
}
}

View file

@ -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,
}