collector/systemd: use regexp to extract systemd version (#1647)

Signed-off-by: paulfantom <pawel@krupa.net.pl>
This commit is contained in:
Paweł Krupa 2020-03-27 21:35:56 +01:00 committed by GitHub
parent a57f246579
commit 1771fc87d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -469,7 +469,8 @@ func getSystemdVersion(logger log.Logger) int {
level.Warn(logger).Log("msg", "Unable to get systemd version property, defaulting to 0")
return 0
}
version = strings.Replace(version, "\"", "", 2)
re := regexp.MustCompile(`[0-9][0-9][0-9]`)
version = re.FindString(version)
v, err := strconv.Atoi(version)
if err != nil {
level.Warn(logger).Log("msg", "Got invalid systemd version", "version", version)