feat: add various infrastructure check and automation scripts
This commit is contained in:
31
scripts/check_zabbix_spacedock_items.py
Normal file
31
scripts/check_zabbix_spacedock_items.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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")
|
||||
|
||||
hostids = ["10715", "10716", "10717", "10718", "10719", "10720", "10721", "10722"]
|
||||
hosts = zabbix_api("host.get", {
|
||||
"output": ["hostid", "host", "name", "status"],
|
||||
"hostids": hostids,
|
||||
"selectItems": ["itemid", "name", "lastvalue", "prevvalue", "status"]
|
||||
}, auth=auth).get("result", [])
|
||||
|
||||
for h in hosts:
|
||||
items = h.get("items", [])
|
||||
ping_items = [f"{i['name']}={i.get('lastvalue')}" for i in items]
|
||||
print(f"Host {h['host']} ({h['name']}): Items count: {len(items)}, Values: {ping_items}")
|
||||
|
||||
Reference in New Issue
Block a user