|
@@ -1,6 +1,6 @@
|
|
|
import requests
|
|
import requests
|
|
|
|
|
|
|
|
-ZABBIX_API_URL = "http://localhost:8081/api_jsonrpc.php"
|
|
|
|
|
|
|
+ZABBIX_API_URL = "http://192.168.130.170:8081/api_jsonrpc.php"
|
|
|
ZABBIX_USER = "Admin"
|
|
ZABBIX_USER = "Admin"
|
|
|
ZABBIX_PASSWORD = "zabbix"
|
|
ZABBIX_PASSWORD = "zabbix"
|
|
|
|
|
|
|
@@ -18,47 +18,85 @@ def authenticate():
|
|
|
print(f"Error connecting to Zabbix API: {e}")
|
|
print(f"Error connecting to Zabbix API: {e}")
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
-def create_dashboard(auth_token):
|
|
|
|
|
|
|
+def get_snmp_item_id(auth_token):
|
|
|
|
|
+ # Retrieve the SNMP fallback item which catches all traps
|
|
|
|
|
+ payload = {
|
|
|
|
|
+ "jsonrpc": "2.0",
|
|
|
|
|
+ "method": "item.get",
|
|
|
|
|
+ "params": {
|
|
|
|
|
+ "output": ["itemid", "name", "key_"],
|
|
|
|
|
+ "search": {
|
|
|
|
|
+ "key_": "snmptrap.fallback"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ "id": 2,
|
|
|
|
|
+ "auth": auth_token
|
|
|
|
|
+ }
|
|
|
|
|
+ response = requests.post(ZABBIX_API_URL, json=payload).json()
|
|
|
|
|
+ items = response.get('result', [])
|
|
|
|
|
+ if items:
|
|
|
|
|
+ print(f"Found SNMP Trap Item: {items[0]['itemid']}")
|
|
|
|
|
+ return items[0]['itemid']
|
|
|
|
|
+ else:
|
|
|
|
|
+ # Fallback to search any SNMP trap item
|
|
|
|
|
+ payload["params"]["search"] = {"key_": "snmptrap["}
|
|
|
|
|
+ response = requests.post(ZABBIX_API_URL, json=payload).json()
|
|
|
|
|
+ items = response.get('result', [])
|
|
|
|
|
+ if items:
|
|
|
|
|
+ print(f"Found specific SNMP Trap Item: {items[0]['itemid']}")
|
|
|
|
|
+ return items[0]['itemid']
|
|
|
|
|
+ print("Could not find any SNMP Trap item in Zabbix.")
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+def create_dashboard(auth_token, item_id):
|
|
|
print("Creating Food AI RAG Telemetry Dashboard...")
|
|
print("Creating Food AI RAG Telemetry Dashboard...")
|
|
|
|
|
+
|
|
|
|
|
+ # A Plaintext widget needs the itemid passed correctly in fields
|
|
|
|
|
+ widget_fields = []
|
|
|
|
|
+ if item_id:
|
|
|
|
|
+ widget_fields = [
|
|
|
|
|
+ {"type": 4, "name": "itemids", "value": item_id},
|
|
|
|
|
+ {"type": 0, "name": "show_lines", "value": 25}
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
payload = {
|
|
payload = {
|
|
|
"jsonrpc": "2.0",
|
|
"jsonrpc": "2.0",
|
|
|
"method": "dashboard.create",
|
|
"method": "dashboard.create",
|
|
|
"params": {
|
|
"params": {
|
|
|
- "name": "Food AI RAG Telemetry",
|
|
|
|
|
|
|
+ "name": "Food AI RAG Telemetry (Live)",
|
|
|
"userid": "1",
|
|
"userid": "1",
|
|
|
"pages": [
|
|
"pages": [
|
|
|
{
|
|
{
|
|
|
"name": "SNMP Trap Activity",
|
|
"name": "SNMP Trap Activity",
|
|
|
"widgets": [
|
|
"widgets": [
|
|
|
{
|
|
{
|
|
|
- "type": "svggraph",
|
|
|
|
|
- "name": "Ingestion Activity",
|
|
|
|
|
- "x": 0, "y": 0, "width": 12, "height": 5,
|
|
|
|
|
- "fields": [
|
|
|
|
|
- {"type": 1, "name": "ds.0.color", "value": "FF0000"}
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ "type": "plaintext",
|
|
|
|
|
+ "name": "Ingestion Row Count Log",
|
|
|
|
|
+ "x": 0, "y": 0, "width": 12, "height": 8,
|
|
|
|
|
+ "fields": widget_fields
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
"type": "systeminfo",
|
|
"type": "systeminfo",
|
|
|
"name": "Server Status",
|
|
"name": "Server Status",
|
|
|
- "x": 12, "y": 0, "width": 12, "height": 5
|
|
|
|
|
|
|
+ "x": 12, "y": 0, "width": 12, "height": 8
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
},
|
|
},
|
|
|
- "id": 2,
|
|
|
|
|
|
|
+ "id": 3,
|
|
|
"auth": auth_token
|
|
"auth": auth_token
|
|
|
}
|
|
}
|
|
|
response = requests.post(ZABBIX_API_URL, json=payload).json()
|
|
response = requests.post(ZABBIX_API_URL, json=payload).json()
|
|
|
if 'result' in response:
|
|
if 'result' in response:
|
|
|
- print(f"✅ Dashboard Created successfully! ID: {response['result']['dashboardids'][0]}")
|
|
|
|
|
|
|
+ print(f"Dashboard Created successfully! ID: {response['result']['dashboardids'][0]}")
|
|
|
else:
|
|
else:
|
|
|
- print(f"⚠️ Failed to create dashboard: {response}")
|
|
|
|
|
|
|
+ print(f"Failed to create dashboard: {response}")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
token = authenticate()
|
|
token = authenticate()
|
|
|
if token:
|
|
if token:
|
|
|
- create_dashboard(token)
|
|
|
|
|
|
|
+ item_id = get_snmp_item_id(token)
|
|
|
|
|
+ create_dashboard(token, item_id)
|
|
|
else:
|
|
else:
|
|
|
print("❌ Could not authenticate to Zabbix. Ensure the server is fully started on port 8081.")
|
|
print("❌ Could not authenticate to Zabbix. Ensure the server is fully started on port 8081.")
|