updated zabbix state

This commit is contained in:
Paul 2021-06-14 23:06:21 +02:00
parent 92c752b8bb
commit f78ea933ef

View File

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