diff --git a/states/zabbix/scripts/dkron.py b/states/zabbix/scripts/dkron.py new file mode 100755 index 0000000..f784394 --- /dev/null +++ b/states/zabbix/scripts/dkron.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +import argparse +import json +import requests + +def discovery(url="http://localhost:8898"): + ret = {"data": []} + req = requests.request(method="GET", url=f"{url}/v1/jobs") + try: + for res_value in req.json(): + ret["data"].append({"{#SERVICE}": res_value["name"]}) + return json.dumps(ret) + except: + return "error" + +def task(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" + 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") + args = parser.parse_args() + + if args.option == "discovery": + disc = discovery() + print(disc) + elif args.option == "status": + t = task(task_name=args.task) + print(t)