feat: add infrastructure automation and diagnostic scripts for Zabbix, Nginx, and Authentik
This commit is contained in:
24
scripts/check_one_problem.py
Normal file
24
scripts/check_one_problem.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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'}, 'id': 2}
|
||||
req = urllib.request.Request(ZABBIX_URL, data=json.dumps(payload).encode(), headers={'Content-Type': 'application/json-rpc', 'Authorization': f'Bearer {token}'})
|
||||
problems = json.loads(urllib.request.urlopen(req, context=ctx).read())['result']
|
||||
|
||||
for p in problems:
|
||||
if 'active checks' in p['name'].lower():
|
||||
# Get event
|
||||
ep = {'jsonrpc': '2.0', 'method': 'event.get', 'params': {'eventids': [p['eventid']], 'selectHosts': ['host', 'name']}, 'id': 3}
|
||||
er = urllib.request.Request(ZABBIX_URL, data=json.dumps(ep).encode(), headers={'Content-Type': 'application/json-rpc', 'Authorization': f'Bearer {token}'})
|
||||
events = json.loads(urllib.request.urlopen(er, context=ctx).read())['result']
|
||||
print(f"Problem: {p['name']} | Event: {events}")
|
||||
|
||||
Reference in New Issue
Block a user