This commit is contained in:
2025-12-24 11:40:18 +01:00
parent 14ba01f51b
commit 3a939bd601
6 changed files with 100 additions and 4 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
/Dev/mysql_n8n_db/data
/Dev/mysql_n8n_db/mysql-data
Backup/Sophos/APS_HH.scx
*.log
*.log

View File

@@ -6,6 +6,7 @@ services:
- "5678:5678"
volumes:
- ./n8n-data:/home/node/.n8n
- ./n8n-scripts:/home/node/scripts
environment:
- N8N_HOST=${N8N_HOST:-localhost}
- N8N_PORT=5678

View File

@@ -1,2 +0,0 @@
{"__type":"$$EventMessageAudit","id":"10636aec-f055-4a49-8093-4f7f253589e7","ts":"2025-12-24T10:28:22.058+00:00","eventName":"n8n.audit.workflow.created","message":"n8n.audit.workflow.created","payload":{"userId":"83518984-8079-471d-bb46-b38676ef4115","_email":"i.meszely@aps-hh.de","_firstName":"Istvan","_lastName":"Meszely","globalRole":"global:owner","workflowId":"BXlx8AYRPLgg2wuh","workflowName":"My workflow"}}
{"__type":"$$EventMessageConfirm","confirm":"10636aec-f055-4a49-8093-4f7f253589e7","ts":"2025-12-24T10:28:22.058+00:00","source":{"id":"0","name":"eventBus"}}

View File

@@ -1,2 +0,0 @@
{"__type":"$$EventMessageAudit","id":"fe8b31f4-b3b1-4435-af25-9aaff5b202b1","ts":"2025-12-24T10:31:02.003+00:00","eventName":"n8n.audit.workflow.updated","message":"n8n.audit.workflow.updated","payload":{"userId":"83518984-8079-471d-bb46-b38676ef4115","_email":"i.meszely@aps-hh.de","_firstName":"Istvan","_lastName":"Meszely","globalRole":"global:owner","workflowId":"BXlx8AYRPLgg2wuh","workflowName":"My workflow"}}
{"__type":"$$EventMessageConfirm","confirm":"fe8b31f4-b3b1-4435-af25-9aaff5b202b1","ts":"2025-12-24T10:31:02.004+00:00","source":{"id":"0","name":"eventBus"}}

View File

@@ -0,0 +1,97 @@
import re
import json
import sys
from netmiko import ConnectHandler
from netmiko.exceptions import NetmikoTimeoutException, NetmikoAuthenticationException
def get_aruba_clients(host, username, password):
"""
Connects to an Aruba switch via SSH, gets hostname and client info,
and returns a list of dictionaries, each representing a client.
"""
device = {
'device_type': 'aruba_aoscx',
'host': host,
'username': username,
'password': password,
}
all_clients_data = []
print(f"Csatlakozás a(z) {host} eszközhöz...", file=sys.stderr)
try:
with ConnectHandler(**device) as net_connect:
print("Sikeres csatlakozás. Adatok lekérdezése...", file=sys.stderr)
prompt = net_connect.find_prompt()
switch_hostname = prompt.strip('#> ')
output = net_connect.send_command('show client ip')
ip_pattern = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
if isinstance(output, str):
lines = output.splitlines()
for line in lines[2:]:
columns = line.split()
if len(columns) >= 4:
potential_ip = columns[-1]
if ip_pattern.match(potential_ip):
client_data = {
'switch_name': switch_hostname,
'mac_address': columns[0],
'interface': columns[1],
'vlan': columns[2],
'ip_address': potential_ip,
}
all_clients_data.append(client_data)
return all_clients_data
print("Hiba: A parancs kimenete nem volt a várt formátumban.", file=sys.stderr)
return None
except NetmikoTimeoutException:
print(f"Hiba: Időtúllépés a(z) {host} eszközhöz való csatlakozáskor.", file=sys.stderr)
return None
except NetmikoAuthenticationException:
print(f"Hiba: Sikertelen hitelesítés a(z) {host} eszközön. Ellenőrizd a jelszót.", file=sys.stderr)
return None
except Exception as e:
print(f"Váratlan hiba történt: {e}", file=sys.stderr)
return None
if __name__ == "__main__":
# Konfigurációs fájl beolvasása
try:
with open('config.json', 'r') as f:
config = json.load(f)
except FileNotFoundError:
print("Hiba: A 'config.json' fájl nem található.", file=sys.stderr)
exit(1)
except json.JSONDecodeError:
print("Hiba: A 'config.json' fájl formátuma érvénytelen.", file=sys.stderr)
exit(1)
SWITCH_IPS = config.get("switch_ips", [])
USERNAME = config.get("username")
PASSWORD = config.get("password")
if not all([SWITCH_IPS, USERNAME, PASSWORD]):
print("Hiba: A 'config.json' fájl hiányos. Tartalmaznia kell 'switch_ips', 'username', és 'password' kulcsokat.", file=sys.stderr)
exit(1)
all_switches_clients = []
for ip in SWITCH_IPS:
print(f"\n--- Feldolgozás: {ip} ---", file=sys.stderr)
clients_from_one_switch = get_aruba_clients(ip, USERNAME, PASSWORD)
if clients_from_one_switch:
all_switches_clients.extend(clients_from_one_switch)
print(f"Sikeresen lekérdezve {len(clients_from_one_switch)} kliens a(z) {ip} switch-ről.", file=sys.stderr)
else:
print(f"Nem sikerült adatot lekérdezni a(z) {ip} switch-ről.", file=sys.stderr)
# Ha nem sikerült adatot gyűjteni, jelezzük a stderr-en
if not all_switches_clients:
print("\nEgyetlen switch-ről sem sikerült adatot gyűjteni.", file=sys.stderr)
# --- Fő kimenet: JSON a stdout-ra ---
print(json.dumps(all_switches_clients, indent=2))