From 5da14042f70711ea5cf66e034699730335462f66 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 14:08:03 +0200 Subject: Merging upstream version 1.45.3+dfsg. Signed-off-by: Daniel Baumann --- .../go.d.plugin/agent/hostinfo/hostinfo_linux.go | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/go/collectors/go.d.plugin/agent/hostinfo/hostinfo_linux.go (limited to 'src/go/collectors/go.d.plugin/agent/hostinfo/hostinfo_linux.go') diff --git a/src/go/collectors/go.d.plugin/agent/hostinfo/hostinfo_linux.go b/src/go/collectors/go.d.plugin/agent/hostinfo/hostinfo_linux.go new file mode 100644 index 000000000..db2005f00 --- /dev/null +++ b/src/go/collectors/go.d.plugin/agent/hostinfo/hostinfo_linux.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +//go:build linux + +package hostinfo + +import ( + "context" + "regexp" + "strconv" + + "github.com/coreos/go-systemd/v22/dbus" +) + +var SystemdVersion = getSystemdVersion() + +func getSystemdVersion() int { + var reVersion = regexp.MustCompile(`[0-9][0-9][0-9]`) + + conn, err := dbus.NewWithContext(context.Background()) + if err != nil { + return 0 + } + defer conn.Close() + + version, err := conn.GetManagerProperty("Version") + if err != nil { + return 0 + } + + major := reVersion.FindString(version) + if major == "" { + return 0 + } + + ver, err := strconv.Atoi(major) + if err != nil { + return 0 + } + + return ver +} -- cgit v1.2.3