49 lines
2.1 KiB
Python
49 lines
2.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"
|
|
|
|
def zbx_req(method, params, token=None):
|
|
payload = {'jsonrpc': '2.0', 'method': method, 'params': params, 'id': 1}
|
|
headers = {'Content-Type': 'application/json-rpc'}
|
|
if token:
|
|
headers['Authorization'] = f'Bearer {token}'
|
|
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())['result']
|
|
|
|
token = zbx_req('user.login', {'username': 'Admin', 'password': 'zabbix'})
|
|
print("Zabbix Auth Token:", token)
|
|
|
|
# 1. Actions
|
|
actions = zbx_req('action.get', {'output': 'extend', 'selectOperations': 'extend', 'selectFilter': 'extend'}, token)
|
|
print("\n=== TRIGGER ACTIONS ===")
|
|
for a in actions:
|
|
print(f"ID: {a['actionid']}, Name: {a['name']}, Status (0=enabled, 1=disabled): {a['status']}, EventSource: {a['eventsource']}")
|
|
print(f" Operations: {a.get('operations')}")
|
|
print(f" Filter: {a.get('filter')}")
|
|
|
|
# 2. Media Types
|
|
media_types = zbx_req('mediatype.get', {'output': 'extend'}, token)
|
|
print("\n=== MEDIA TYPES ===")
|
|
for m in media_types:
|
|
print(f"ID: {m['mediatypeid']}, Name: {m['name']}, Type: {m['type']}, Status: {m['status']}")
|
|
|
|
# 3. User Media
|
|
users = zbx_req('user.get', {'output': ['userid', 'username'], 'selectMedias': 'extend'}, token)
|
|
print("\n=== USERS & MEDIA ===")
|
|
for u in users:
|
|
print(f"User: {u['username']} (ID: {u['userid']})")
|
|
for med in u.get('medias', []):
|
|
print(f" Media: mediatypeid={med['mediatypeid']}, sendto={med['sendto']}, active={med['active']}, severity={med['severity']}")
|
|
|
|
# 4. Recent Alerts
|
|
alerts = zbx_req('alert.get', {'output': 'extend', 'limit': 15, 'sortfield': 'clock', 'sortorder': 'DESC'}, token)
|
|
print("\n=== RECENT ALERTS ===")
|
|
for al in alerts:
|
|
print(f"Alert ID: {al['alertid']}, ActionID: {al['actionid']}, Clock: {al['clock']}, Error: {al.get('error')}, Status: {al.get('status')}, Subject: {al.get('subject')}")
|
|
|