diff --git a/states/zabbix/scripts/dkron.py b/states/zabbix/scripts/dkron.py index 7331257..cd621b7 100755 --- a/states/zabbix/scripts/dkron.py +++ b/states/zabbix/scripts/dkron.py @@ -3,14 +3,14 @@ import argparse import json from datetime import datetime, timezone +from urllib.request import urlopen import dateutil.parser -import requests def discovery(url="http://localhost:8898"): ret = {"data": []} - req = requests.request(method="GET", url=f"{url}/v1/jobs") + req = urlopen(url=f"{url}/v1/jobs") try: - for res_value in req.json(): + for res_value in json.loads(req.read()): if not res_value["disabled"]: ret["data"].append({"{#SERVICE}": res_value["name"]}) return json.dumps(ret) @@ -20,8 +20,8 @@ def discovery(url="http://localhost:8898"): def status(url="http://localhost:8898", task_name=""): ret = "" try: - req = requests.request(method="GET", url=f"{url}/v1/jobs/{task_name}") - ret = req.json()["status"] + req = urlopen(url=f"{url}/v1/jobs/{task_name}") + ret = json.loads(req.read())["status"] except Exception as err: return f"error: {err}" return ret @@ -30,9 +30,8 @@ def nextrun(url="http://localhost:8898", task_name=""): ret = "" nrun = "" try: - req = requests.request(method="GET", url=f"{url}/v1/jobs/{task_name}") - #disabled = req.json()["disabled"] - nraw = req.json()["next"] + req = urlopen(url=f"{url}/v1/jobs/{task_name}") + nraw = json.loads(req.read())["next"] nrun = dateutil.parser.parse(nraw) now = datetime.now(tz=timezone.utc) diff = nrun-now