41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
import json
|
|
import ssl
|
|
import urllib.request
|
|
|
|
ZABBIX_URL = "https://zabbix.snarfnet.net/api_jsonrpc.php"
|
|
ZABBIX_USER = "Admin"
|
|
ZABBIX_PASS = "zabbix"
|
|
|
|
ctx = ssl.create_default_context()
|
|
ctx.check_hostname = False
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
def zbx_req(method: str, params: dict, auth: str = None):
|
|
payload = {"jsonrpc": "2.0", "method": method, "params": params, "id": 1}
|
|
headers = {"Content-Type": "application/json-rpc"}
|
|
if auth: headers["Authorization"] = f"Bearer {auth}"
|
|
req = urllib.request.Request(ZABBIX_URL, data=json.dumps(payload).encode("utf-8"), headers=headers, method="POST")
|
|
with urllib.request.urlopen(req, timeout=10, context=ctx) as r:
|
|
return json.loads(r.read().decode("utf-8"))["result"]
|
|
|
|
token = zbx_req("user.login", {"username": ZABBIX_USER, "password": ZABBIX_PASS})
|
|
|
|
items = zbx_req("item.get", {
|
|
"templateids": "10343",
|
|
"output": ["itemid", "name", "key_"],
|
|
}, auth=token)
|
|
print(f"Total items in 10343: {len(items)}")
|
|
for i in items:
|
|
if "time" in i["name"].lower() or "time" in i["key_"].lower():
|
|
print(f" {i['itemid']}: {i['name']} ({i['key_']})")
|
|
|
|
trigs = zbx_req("trigger.get", {
|
|
"templateids": "10343",
|
|
"output": ["triggerid", "description", "priority", "expression"],
|
|
}, auth=token)
|
|
print(f"Total triggers in 10343: {len(trigs)}")
|
|
for t in trigs:
|
|
if "time" in t["description"].lower():
|
|
print(f" {t['triggerid']}: {t['description']} [prio={t['priority']}] -> {t['expression']}")
|
|
|