fix: units not displayed correctly on systemd >= 252

This commit is contained in:
2025-01-01 19:41:08 +01:00
parent 5b27bee900
commit de0ba6d093

View File

@@ -22,18 +22,21 @@ class SystemdStatus(nagiosplugin.Resource):
p = subprocess.Popen(['systemctl', '--failed', '--no-legend'], p = subprocess.Popen(['systemctl', '--failed', '--no-legend'],
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE) stdout=subprocess.PIPE,
pres, err = p.communicate() universal_newlines=True)
stdout, err = p.communicate()
except OSError as e: except OSError as e:
raise nagiosplugin.CheckError(e) raise nagiosplugin.CheckError(e)
if err: if err:
raise nagiosplugin.CheckError(err) raise nagiosplugin.CheckError(err)
if pres: if stdout:
lines = list(filter(lambda x: "service" in x, stdout.split("\n")))
result = "" result = ""
for line in io.StringIO(pres.decode('utf-8')): for line in lines:
result = "%s %s" % (result, line.split(' ')[0]) result += "{}".format(line.split(' ')[1])
return [nagiosplugin.Metric('systemd', (False, result), context='systemd')] return [nagiosplugin.Metric('systemd', (False, result), context='systemd')]