Skip to content

Commit d9587c4

Browse files
belimawrmauri870
andauthored
Add os_family, os_platform and os_version to host provider (#5941)
This commit adds `os_family`, `os_platform` and `os_version` to the host provider, enabling differentiating Linux distributions. This is required to support Debian 12 and other distributions that are moving away from traditional log files in favour of Journald. --------- Co-authored-by: Mauri de Souza Meneguzzo <[email protected]>
1 parent 9396e19 commit d9587c4

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Add os_family, os_platform and os_version to host provider
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/5941
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: https://github.com/elastic/integrations/issues/10797

internal/pkg/composable/providers/host/host.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ func getHostInfo(log *logger.Logger) func() (map[string]interface{}, error) {
147147
"architecture": info.Architecture,
148148
"ip": info.IPs,
149149
"mac": info.MACs,
150+
"os_family": info.OS.Family,
151+
"os_platform": info.OS.Platform,
152+
"os_version": info.OS.Version,
150153
}, nil
151154
}
152155
}

internal/pkg/composable/providers/host/host_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
ctesting "github.com/elastic/elastic-agent/internal/pkg/composable/testing"
1717
"github.com/elastic/elastic-agent/internal/pkg/config"
1818
"github.com/elastic/elastic-agent/pkg/core/logger"
19+
testlogger "github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
1920
"github.com/elastic/elastic-agent/pkg/features"
2021
)
2122

@@ -167,3 +168,21 @@ func returnHostMapping(log *logger.Logger) infoFetcher {
167168
return host, nil
168169
}
169170
}
171+
172+
func TestGetHostInfoReturnsSomeKeys(t *testing.T) {
173+
l, _ := testlogger.New(t.Name())
174+
// this is a simple test to ensure the host provider returns the new keys
175+
// needed to add support to Debian 12.
176+
osInfo, err := getHostInfo(l)()
177+
if err != nil {
178+
t.Fatalf("could not get host provider variables: %s", err)
179+
}
180+
181+
expectedKeys := []string{"os_family", "os_platform", "os_version"}
182+
183+
for _, key := range expectedKeys {
184+
if _, exist := osInfo[key]; !exist {
185+
t.Errorf("expecting key '%s' from host provider.", key)
186+
}
187+
}
188+
}

0 commit comments

Comments
 (0)