feat: add various infrastructure check and automation scripts
This commit is contained in:
40
scripts/check_linux_template.py
Normal file
40
scripts/check_linux_template.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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")
|
||||
|
||||
# Get templates
|
||||
templates = zabbix_api("template.get", {
|
||||
"output": ["templateid", "name"],
|
||||
"search": {"name": "Linux"},
|
||||
"selectMacros": "extend"
|
||||
}, auth=auth).get("result", [])
|
||||
|
||||
for t in templates:
|
||||
print(f"\nTemplate: {t['name']} (ID: {t['templateid']})")
|
||||
for m in t.get("macros", []):
|
||||
if "CPU" in m['macro'] or "MEM" in m['macro'] or "LOAD" in m['macro']:
|
||||
print(f" Macro: {m['macro']} = {m['value']}")
|
||||
# Get triggers in this template
|
||||
triggers = zabbix_api("trigger.get", {
|
||||
"output": ["triggerid", "description", "expression", "priority"],
|
||||
"templateids": [t['templateid']],
|
||||
"search": {"description": "utilization"}
|
||||
}, auth=auth).get("result", [])
|
||||
for tr in triggers:
|
||||
print(f" Trigger: {tr['description']} | Expr: {tr['expression']} | Priority: {tr['priority']}")
|
||||
|
||||
Reference in New Issue
Block a user