Files
SnarfCode/scripts/check_remaining_agent_problems.py

24 lines
1.1 KiB
Python

import json, ssl, urllib.request
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
ZABBIX_URL = 'http://140.44.4.60:8888/api_jsonrpc.php'
payload = {'jsonrpc': '2.0', 'method': 'user.login', 'params': {'username': 'Admin', 'password': 'zabbix'}, 'id': 1}
req = urllib.request.Request(ZABBIX_URL, data=json.dumps(payload).encode(), headers={'Content-Type': 'application/json-rpc'})
token = json.loads(urllib.request.urlopen(req, context=ctx).read())['result']
payload = {'jsonrpc': '2.0', 'method': 'problem.get', 'params': {'output': 'extend', 'selectAcknowledges': 'extend'}, 'id': 2}
req = urllib.request.Request(ZABBIX_URL, data=json.dumps(payload).encode(), headers={'Content-Type': 'application/json-rpc', 'Authorization': f'Bearer {token}'})
resp = json.loads(urllib.request.urlopen(req, context=ctx).read())
if 'error' in resp:
print("API Error:", resp['error'])
else:
problems = resp['result']
print(f"Total problems: {len(problems)}")
for p in problems:
if 'agent' in p['name'].lower():
print(f" - EventID: {p['eventid']} | Severity: {p['severity']} | Name: {p['name']}")