feat: add infrastructure automation and diagnostic scripts for Zabbix, Nginx, and Authentik
This commit is contained in:
19
scripts/check_alerts_status.py
Normal file
19
scripts/check_alerts_status.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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': 'alert.get', 'params': {'output': 'extend', 'limit': 20, 'sortfield': 'clock', 'sortorder': 'DESC'}, 'id': 2}
|
||||
req = urllib.request.Request(ZABBIX_URL, data=json.dumps(payload).encode(), headers={'Content-Type': 'application/json-rpc', 'Authorization': f'Bearer {token}'})
|
||||
alerts = json.loads(urllib.request.urlopen(req, context=ctx).read())['result']
|
||||
|
||||
for a in alerts:
|
||||
print(f"ID: {a['alertid']} | Status: {a['status']} | User: {a['userid']} | Error: '{a.get('error')}' | Subject: {a.get('subject')}")
|
||||
|
||||
Reference in New Issue
Block a user