35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import urllib.request
|
|
import json
|
|
import ssl
|
|
|
|
ctx = ssl.create_default_context()
|
|
ctx.check_hostname = False
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
def zabbix_api(method, params, auth=None):
|
|
payload = {"jsonrpc": "2.0", "method": method, "params": params, "id": 1}
|
|
if auth: payload["auth"] = auth
|
|
req = urllib.request.Request("https://zabbix.snarfnet.net/api_jsonrpc.php",
|
|
data=json.dumps(payload).encode('utf-8'),
|
|
headers={"Content-Type": "application/json-rpc"})
|
|
resp = urllib.request.urlopen(req, context=ctx, timeout=10)
|
|
return json.loads(resp.read().decode('utf-8'))
|
|
|
|
auth = zabbix_api("user.login", {"username": "Admin", "password": "zabbix"}).get("result")
|
|
|
|
# Get full trigger detail for template 10343 and 10001
|
|
triggers = zabbix_api("trigger.get", {
|
|
"output": "extend",
|
|
"templateids": ["10343", "10001"],
|
|
"search": {"description": "utilization"},
|
|
"selectFunctions": "extend"
|
|
}, auth=auth).get("result", [])
|
|
|
|
for t in triggers:
|
|
print(f"\nTrigger: {t['description']} (ID: {t['triggerid']}, Template: {t['templateid']})")
|
|
print(f" Expr: {t['expression']}")
|
|
print(f" Priority: {t['priority']}")
|
|
print(f" Comments: {t['comments']}")
|
|
print(f" Functions: {t.get('functions')}")
|
|
|