updated zabbix state
This commit is contained in:
parent
5bd15c71a9
commit
bd0c089761
@ -2,6 +2,8 @@
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
import dateutil.parser
|
||||
import requests
|
||||
|
||||
def discovery(url="http://localhost:8898"):
|
||||
@ -9,31 +11,54 @@ def discovery(url="http://localhost:8898"):
|
||||
req = requests.request(method="GET", url=f"{url}/v1/jobs")
|
||||
try:
|
||||
for res_value in req.json():
|
||||
if not res_value["disabled"]:
|
||||
ret["data"].append({"{#SERVICE}": res_value["name"]})
|
||||
return json.dumps(ret)
|
||||
except:
|
||||
return "error"
|
||||
except Exception as err:
|
||||
return f"error: {err}"
|
||||
|
||||
def task(url="http://localhost:8898", task_name=""):
|
||||
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"]
|
||||
except:
|
||||
return "error"
|
||||
except Exception as err:
|
||||
return f"error: {err}"
|
||||
return ret
|
||||
|
||||
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"]
|
||||
nrun = dateutil.parser.parse(nraw)
|
||||
now = datetime.now(tz=timezone.utc)
|
||||
diff = nrun-now
|
||||
ret = str(int(diff.total_seconds()))
|
||||
except Exception as err:
|
||||
return f"error: {err}"
|
||||
return ret
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(prog="dkron")
|
||||
subparser = parser.add_subparsers(help='sub-command help', dest='option')
|
||||
parser_discovery = subparser.add_parser("discovery")
|
||||
parser_service = subparser.add_parser("status")
|
||||
parser_service.add_argument("task")
|
||||
parser_status = subparser.add_parser("status")
|
||||
parser_status.add_argument("task")
|
||||
parser_nextrun = subparser.add_parser("nextrun")
|
||||
parser_nextrun.add_argument("task")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.option == "discovery":
|
||||
disc = discovery()
|
||||
print(disc)
|
||||
elif args.option == "status":
|
||||
t = task(task_name=args.task)
|
||||
print(t)
|
||||
sts = status(task_name=args.task)
|
||||
print(sts)
|
||||
elif args.option == "nextrun":
|
||||
nextr = nextrun(task_name=args.task)
|
||||
print(nextr)
|
||||
else:
|
||||
print("No option specified")
|
||||
|
@ -3,10 +3,19 @@
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
ret = {"data": []}
|
||||
output = subprocess.run("systemctl list-unit-files | grep -E '\.service\s+(generated|enabled)' | awk -F'.service ' '{print $1}'", shell=True, capture_output=True).stdout
|
||||
def main():
|
||||
ret = {"data": []}
|
||||
output = subprocess.run("""
|
||||
systemctl list-unit-files | grep -E '\.service\s+(generated|enabled)' | awk -F'.service ' '{print $1}'
|
||||
""",
|
||||
shell=True,
|
||||
capture_output=True).stdout
|
||||
|
||||
for line in output.splitlines():
|
||||
for line in output.splitlines():
|
||||
ret["data"].append({"{#SERVICE}": line.decode("utf-8")})
|
||||
|
||||
print(json.dumps(ret))
|
||||
return json.dumps(ret)
|
||||
|
||||
if __name__ == "__main__":
|
||||
res = main()
|
||||
print(res)
|
||||
|
Loading…
Reference in New Issue
Block a user