From 1771fc87d976d953512772c53a1d6605f5f25530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Krupa?= Date: Fri, 27 Mar 2020 21:35:56 +0100 Subject: [PATCH] collector/systemd: use regexp to extract systemd version (#1647) Signed-off-by: paulfantom --- collector/systemd_linux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index db659bfe..08270694 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -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)