From ea43b5cb6c1bb63c1e59d88a9dedadc79574b50c Mon Sep 17 00:00:00 2001 From: wpanda Date: Mon, 9 Mar 2026 16:21:48 +0100 Subject: [PATCH] grafana docker --- Docker/librenms_aps/docker-compose.yml | 13 +++ Scripts/powershell/Get-GPO.ps1 | 7 ++ .../powershell/SNMP An auf Windows Server.ps1 | 2 +- Scripts/python/smb_folder_monitor.py | 97 +++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Scripts/powershell/Get-GPO.ps1 create mode 100644 Scripts/python/smb_folder_monitor.py diff --git a/Docker/librenms_aps/docker-compose.yml b/Docker/librenms_aps/docker-compose.yml index 3c5a0da..7b264ec 100644 --- a/Docker/librenms_aps/docker-compose.yml +++ b/Docker/librenms_aps/docker-compose.yml @@ -90,3 +90,16 @@ services: - DISPATCHER_NODE_ID=dispatcher1 - SIDECAR_DISPATCHER=1 restart: always + + grafana: + image: grafana/grafana-oss:latest + container_name: grafana + ports: + - "3000:3000" + volumes: + - ./grafana_data:/var/lib/grafana + environment: + - TZ=${TZ} + - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_USERS_ALLOW_SIGN_UP=false + restart: always diff --git a/Scripts/powershell/Get-GPO.ps1 b/Scripts/powershell/Get-GPO.ps1 new file mode 100644 index 0000000..5231c7a --- /dev/null +++ b/Scripts/powershell/Get-GPO.ps1 @@ -0,0 +1,7 @@ +# Az összes GPO végigfésülése az "SMTP" kulcsszóra +Get-GPO -All | ForEach-Object { + $report = Get-GPOReport -Guid $_.Id -ReportType Xml + if ($report -like "*SMTP*") { + Write-Host "Találat: $($_.DisplayName)" -ForegroundColor Green + } +} \ No newline at end of file diff --git a/Scripts/powershell/SNMP An auf Windows Server.ps1 b/Scripts/powershell/SNMP An auf Windows Server.ps1 index b601fb3..4e8b9d8 100644 --- a/Scripts/powershell/SNMP An auf Windows Server.ps1 +++ b/Scripts/powershell/SNMP An auf Windows Server.ps1 @@ -1,4 +1,4 @@ # SNMP An auf Windows Server Install-WindowsFeature -Name "SNMP-Service" -IncludeAllSubFeature -IncludeManagementTools # Firewall für SNMP Dienst öffnen -New-NetFirewallRule -Name "SNMP" -DisplayName "Allow SNMP" -Protocol UDP -LocalPort 161 -Action Allow -Direction Inbound -RemoteAddress 10.102.1.59 -Profile Domain +New-NetFirewallRule -Name "SNMP" -DisplayName "Allow SNMP" -Protocol UDP -LocalPort 161 -Action Allow -Direction Inbound -RemoteAddress 10.102.1.201 -Profile Domain diff --git a/Scripts/python/smb_folder_monitor.py b/Scripts/python/smb_folder_monitor.py new file mode 100644 index 0000000..212a733 --- /dev/null +++ b/Scripts/python/smb_folder_monitor.py @@ -0,0 +1,97 @@ +import smbclient +import smbclient.path +from datetime import datetime, timezone, timedelta +import requests +import sys + +# --- KONFIGURÁCIÓ --- +# Töltsd ki a saját adataiddal! +SERVER = "10.102.1.56" # Windows szerver IP +SHARE = "D$" # Megosztás neve (C$, D$, stb.) +FOLDER_PATH = "Schnittstellen/Bremen" # Útvonal a megosztáson belül (NE tegyél elé perjelet!) +USERNAME = "user" # Windows felhasználónév +PASSWORD = "password" # Windows jelszó + +# Küszöbértékek +MAX_FILES = 2 +MAX_AGE_MINUTES = 45 + +# n8n integráció +N8N_WEBHOOK_URL = "https://n8n.domain.hu/webhook/folder-alert" +TEST_MODE = True # True: csak kiírja az eredményt, nem küld n8n üzenetet + +def check_folder(): + print(f"--- Ellenőrzés indítása: {datetime.now()} ---") + print(f"Szerver: {SERVER}, Mappa: {SHARE}\\{FOLDER_PATH}") + + try: + # Kapcsolat felépítése + smbclient.register_session(SERVER, username=USERNAME, password=PASSWORD) + + # Windows-stílusú elérési út összeállítása + full_path = f"\\\\{SERVER}\\{SHARE}\\{FOLDER_PATH.replace('/', '\\')}" + + if not smbclient.path.exists(full_path): + print(f"HIBA: A megadott elérési út nem létezik: {full_path}") + return + + now = datetime.now(timezone.utc) + old_files = [] + + # Fájlok listázása és ellenőrzése + print("Fájlok vizsgálata...") + for file_entry in smbclient.scandir(full_path): + if file_entry.is_file(): + # Utolsó módosítás lekérése (st_mtime) + mtime = datetime.fromtimestamp(file_entry.stat().st_mtime, timezone.utc) + age = now - mtime + age_minutes = int(age.total_seconds() / 60) + + print(f" - {file_entry.name}: {age_minutes} perce módosítva") + + if age > timedelta(minutes=MAX_AGE_MINUTES): + old_files.append({ + "name": file_entry.name, + "age_minutes": age_minutes + }) + + # Logika: Ha több mint MAX_FILES régi fájl van + if len(old_files) > MAX_FILES: + print(f"\n[!] FIGYELEM: {len(old_files)} db régi fájl található!") + if not TEST_MODE: + send_n8n_alert(len(old_files), old_files) + else: + print("[Teszt mód] n8n hívás kihagyva.") + else: + print(f"\n[OK] Minden rendben. ({len(old_files)} régi fájl)") + + except Exception as e: + print(f"\n[!] Váratlan hiba történt: {e}") + finally: + # Kapcsolat lezárása + try: + smbclient.reset_connection(SERVER) + except: + pass + print("--- Ellenőrzés vége ---\n") + +def send_n8n_alert(count, files): + payload = { + "status": "warning", + "server": SERVER, + "folder": FOLDER_PATH, + "old_files_count": count, + "files": files, + "timestamp": datetime.now().isoformat() + } + try: + response = requests.post(N8N_WEBHOOK_URL, json=payload, timeout=10) + if response.status_code == 200: + print("n8n értesítés sikeresen elküldve.") + else: + print(f"n8n hiba: HTTP {response.status_code}") + except Exception as e: + print(f"Nem sikerült elérni az n8n-t: {e}") + +if __name__ == "__main__": + check_folder()