feat: add various infrastructure check and automation scripts
This commit is contained in:
45
scripts/update_trigger_15m.py
Normal file
45
scripts/update_trigger_15m.py
Normal file
@@ -0,0 +1,45 @@
|
||||
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")
|
||||
|
||||
# Update Active agent template triggers (10343)
|
||||
up1 = zabbix_api("trigger.update", {
|
||||
"triggerid": "22415",
|
||||
"expression": "min(/Linux by Zabbix agent active/system.cpu.util,15m)>{$CPU.UTIL.CRIT}"
|
||||
}, auth=auth)
|
||||
print("Update Active CPU trigger (15m):", up1)
|
||||
|
||||
up2 = zabbix_api("trigger.update", {
|
||||
"triggerid": "22421",
|
||||
"expression": "min(/Linux by Zabbix agent active/vm.memory.utilization,15m)>{$MEMORY.UTIL.MAX}"
|
||||
}, auth=auth)
|
||||
print("Update Active Memory trigger (15m):", up2)
|
||||
|
||||
# Update Passive agent template triggers (10001)
|
||||
up3 = zabbix_api("trigger.update", {
|
||||
"triggerid": "22370",
|
||||
"expression": "min(/Linux by Zabbix agent/system.cpu.util,15m)>{$CPU.UTIL.CRIT}"
|
||||
}, auth=auth)
|
||||
print("Update Passive CPU trigger (15m):", up3)
|
||||
|
||||
up4 = zabbix_api("trigger.update", {
|
||||
"triggerid": "22376",
|
||||
"expression": "min(/Linux by Zabbix agent/vm.memory.utilization,15m)>{$MEMORY.UTIL.MAX}"
|
||||
}, auth=auth)
|
||||
print("Update Passive Memory trigger (15m):", up4)
|
||||
|
||||
Reference in New Issue
Block a user