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") # 1. Get recent problems in Zabbix problems = zabbix_api("problem.get", { "output": "extend", "sortfield": ["eventid"], "sortorder": "DESC", "limit": 30 }, auth=auth).get("result", []) print(f"Total active/recent problems: {len(problems)}") for p in problems[:15]: print(f"Problem: {p['name']} | Severity: {p['severity']} | Clock: {p['clock']}") # 2. Get triggers with High or Warning for CPU or Memory triggers = zabbix_api("trigger.get", { "output": ["triggerid", "description", "expression", "priority", "templateid"], "filter": {"value": 1}, "search": {"description": "CPU"}, "limit": 20 }, auth=auth).get("result", []) print("\nActive CPU Triggers:") for t in triggers: print(f"ID {t['triggerid']}: {t['description']} -> {t['expression']}") triggers_mem = zabbix_api("trigger.get", { "output": ["triggerid", "description", "expression", "priority", "templateid"], "filter": {"value": 1}, "search": {"description": "Memory"}, "limit": 20 }, auth=auth).get("result", []) print("\nActive Memory Triggers:") for t in triggers_mem: print(f"ID {t['triggerid']}: {t['description']} -> {t['expression']}") # 3. Check global macros for CPU and Memory macros = zabbix_api("usermacro.get", { "output": "extend", "globalmacro": True }, auth=auth).get("result", []) print("\nGlobal Macros:") for m in macros: if "CPU" in m['macro'] or "MEM" in m['macro']: print(f" {m['macro']} = {m['value']}") # 4. Check host groups for Aerodrome, Shipyard, Spaceport groups = zabbix_api("hostgroup.get", { "output": ["groupid", "name"] }, auth=auth).get("result", []) print("\nHost Groups:") for g in groups: print(f" {g['groupid']}: {g['name']}")