- Introduced InterfaceInfo class to encapsulate interface details. - Modified CiscoMacTableParser to gather and store interface information. - Updated ZabbixLLDFormatter to include interface status and descriptions in the output. - Adjusted test_new_format.py to validate new interface information integration. - Enhanced run.sh for improved container management.
52 lines
1.7 KiB
Python
Executable File
52 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Test script para verificar el nuevo formato JSON
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from cisco_mac_monitor import MacEntry, InterfaceInfo, ZabbixLLDFormatter
|
|
import json
|
|
|
|
# Crear datos de prueba
|
|
test_mac_entries = [
|
|
MacEntry(vlan="600", mac_address="f0:8e:db:2e:4d:86", type="DYNAMIC", port="Gi1/0/1"),
|
|
MacEntry(vlan="601", mac_address="f0:8e:db:2e:4d:86", type="DYNAMIC", port="Gi1/0/1"),
|
|
MacEntry(vlan="151", mac_address="00:50:56:a6:91:69", type="DYNAMIC", port="Gi1/0/10"),
|
|
]
|
|
|
|
# Crear información de interfaces de prueba (incluye estado y descripción)
|
|
test_interface_info = {
|
|
"Gi1/0/1": InterfaceInfo(name="Gi1/0/1", status="up", description="User Port - Office"),
|
|
"Gi1/0/10": InterfaceInfo(name="Gi1/0/10", status="up", description="Server Link"),
|
|
"Gi1/0/11": InterfaceInfo(name="Gi1/0/11", status="down", description="Unused Port"),
|
|
}
|
|
|
|
# Crear formatter y formatear datos
|
|
formatter = ZabbixLLDFormatter("10.150.250.2")
|
|
result = formatter.format_for_zabbix(test_mac_entries, test_interface_info)
|
|
|
|
# Mostrar resultado
|
|
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
|
|
# Verificar estructura esperada
|
|
print("\n" + "="*50)
|
|
print("VERIFICACIÓN DE ESTRUCTURA:")
|
|
print("="*50)
|
|
|
|
data = result["data"]
|
|
print(f"✓ Total de puertos: {len(data)}")
|
|
|
|
for item in data:
|
|
port = item["port"]
|
|
port_data = item["data"]
|
|
print(f"✓ Puerto {port}:")
|
|
print(f" - Count: {port_data['count']}")
|
|
print(f" - VLANs: '{port_data['vlans']}'")
|
|
print(f" - Addresses: '{port_data['addresses']}'")
|
|
print(f" - Status: '{port_data['status']}'")
|
|
print(f" - Description: '{port_data['description']}'")
|
|
print(f" - Timestamp: {port_data['timestamp']}")
|
|
print() |