mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Add HostLinuxOSs (#3217)
* Add HostLinuxOSs * Add test for PlatformFromHost * Add sles, gentoo and kali on linux host OSs
This commit is contained in:
parent
04fe0a42b5
commit
8cea7f480a
4 changed files with 82 additions and 5 deletions
2
changes/issue-add-missing-platforms
Normal file
2
changes/issue-add-missing-platforms
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
* Add missing software inventory and `disk_space_unix` for Debian hosts. Unify definition of linux hosts.
|
||||
|
||||
|
|
@ -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 ""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue