github.com/netdata/go.d.plugin@v0.58.1/agent/hostinfo/hostinfo_linux.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 //go:build linux 4 5 package hostinfo 6 7 import ( 8 "context" 9 "regexp" 10 "strconv" 11 12 "github.com/coreos/go-systemd/v22/dbus" 13 ) 14 15 var SystemdVersion = getSystemdVersion() 16 17 func getSystemdVersion() int { 18 var reVersion = regexp.MustCompile(`[0-9][0-9][0-9]`) 19 20 conn, err := dbus.NewWithContext(context.Background()) 21 if err != nil { 22 return 0 23 } 24 defer conn.Close() 25 26 version, err := conn.GetManagerProperty("Version") 27 if err != nil { 28 return 0 29 } 30 31 major := reVersion.FindString(version) 32 if major == "" { 33 return 0 34 } 35 36 ver, err := strconv.Atoi(major) 37 if err != nil { 38 return 0 39 } 40 41 return ver 42 }