41 lines
1.6 KiB
Python
41 lines
1.6 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 templates
|
|
templates = zabbix_api("template.get", {
|
|
"output": ["templateid", "name"],
|
|
"search": {"name": "Linux"},
|
|
"selectMacros": "extend"
|
|
}, auth=auth).get("result", [])
|
|
|
|
for t in templates:
|
|
print(f"\nTemplate: {t['name']} (ID: {t['templateid']})")
|
|
for m in t.get("macros", []):
|
|
if "CPU" in m['macro'] or "MEM" in m['macro'] or "LOAD" in m['macro']:
|
|
print(f" Macro: {m['macro']} = {m['value']}")
|
|
# Get triggers in this template
|
|
triggers = zabbix_api("trigger.get", {
|
|
"output": ["triggerid", "description", "expression", "priority"],
|
|
"templateids": [t['templateid']],
|
|
"search": {"description": "utilization"}
|
|
}, auth=auth).get("result", [])
|
|
for tr in triggers:
|
|
print(f" Trigger: {tr['description']} | Expr: {tr['expression']} | Priority: {tr['priority']}")
|
|
|