updated zabbix scripts for dkron
This commit is contained in:
parent
b79efa21ee
commit
eba3841154
39
states/zabbix/scripts/dkron.py
Executable file
39
states/zabbix/scripts/dkron.py
Executable file
@ -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)
|
Loading…
Reference in New Issue
Block a user