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'],
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
pres, err = p.communicate()
stdout=subprocess.PIPE,
universal_newlines=True)
stdout, err = p.communicate()
except OSError as e:
raise nagiosplugin.CheckError(e)
if err:
raise nagiosplugin.CheckError(err)
if pres:
if stdout:
lines = list(filter(lambda x: "service" in x, stdout.split("\n")))
result = ""
for line in io.StringIO(pres.decode('utf-8')):
result = "%s %s" % (result, line.split(' ')[0])
for line in lines:
result += "{}".format(line.split(' ')[1])
return [nagiosplugin.Metric('systemd', (False, result), context='systemd')]