From cee0c05fb64e357b9048b6df51932f4e28d5710d Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 24 Jan 2021 19:01:26 +0100 Subject: [PATCH] updated zabbix state --- states/zabbix/scripts/systemd_discovery.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/states/zabbix/scripts/systemd_discovery.py b/states/zabbix/scripts/systemd_discovery.py index 8a9b0ee..39e4099 100755 --- a/states/zabbix/scripts/systemd_discovery.py +++ b/states/zabbix/scripts/systemd_discovery.py @@ -1,18 +1,26 @@ #!/usr/bin/python3 +# vim: ft=python import subprocess import json +import re def main(): ret = {"data": []} - output = subprocess.run(""" + output_list = subprocess.run(""" systemctl list-unit-files | grep -E '\.service\s+(generated|enabled)' | awk -F'.service ' '{print $1}' - """, - shell=True, - capture_output=True).stdout + """,shell=True,capture_output=True).stdout - for line in output.splitlines(): - ret["data"].append({"{#SERVICE}": line.decode("utf-8")}) + for line in output_list.splitlines(): + output_is_enabled = subprocess.run(f""" + systemctl is-enabled {line.decode("utf-8")} + """,shell=True,capture_output=True).stdout.decode('utf-8') + #output_is_active = subprocess.run(f""" + # systemctl is-active {line.decode("utf-8")} + # """,shell=True,capture_output=True).stdout.decode('utf-8') + + if re.match("^enabled", output_is_enabled) is not None: + ret["data"].append({"{#SERVICE}": line.decode("utf-8")}) return json.dumps(ret)