Add detailed logging to track the syslog parser's execution and state
Enhance syslog_parser.py with debug, info, and error logging statements, including checks for log file existence and robust error handling for database connections and parsing. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 1663254c-86fe-4c1e-966a-168eb8cd8f97 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/MkBJZ0L
This commit is contained in:
parent
2f0b79cc73
commit
46ab780e60
@ -185,8 +185,12 @@ class SyslogParser:
|
||||
|
||||
def main():
|
||||
"""Main entry point"""
|
||||
print("[DEBUG] Avvio syslog_parser...")
|
||||
|
||||
# Carica variabili d'ambiente da .env
|
||||
print("[DEBUG] Caricamento .env da /opt/ids/.env...")
|
||||
load_dotenv("/opt/ids/.env")
|
||||
print("[DEBUG] .env caricato")
|
||||
|
||||
# Configurazione database da environment
|
||||
# IMPORTANTE: Usa 127.0.0.1 invece di localhost per forzare IPv4
|
||||
@ -198,24 +202,55 @@ def main():
|
||||
'password': os.getenv('PGPASSWORD', 'ids_password_change_me')
|
||||
}
|
||||
|
||||
print(f"[DEBUG] Configurazione database:")
|
||||
print(f"[DEBUG] Host: {db_config['host']}")
|
||||
print(f"[DEBUG] Port: {db_config['port']}")
|
||||
print(f"[DEBUG] Database: {db_config['database']}")
|
||||
print(f"[DEBUG] User: {db_config['user']}")
|
||||
|
||||
# File log da processare
|
||||
log_file = '/var/log/mikrotik/raw.log'
|
||||
print(f"[DEBUG] File log: {log_file}")
|
||||
|
||||
# Verifica esistenza file
|
||||
if not os.path.exists(log_file):
|
||||
print(f"[ERROR] File log non trovato: {log_file}")
|
||||
print(f"[ERROR] Verifica che rsyslog sia configurato correttamente")
|
||||
return
|
||||
|
||||
print(f"[INFO] File log trovato: {log_file}")
|
||||
|
||||
# Crea parser
|
||||
print("[DEBUG] Creazione parser...")
|
||||
parser = SyslogParser(db_config)
|
||||
|
||||
try:
|
||||
# Connetti al database
|
||||
print("[DEBUG] Connessione database...")
|
||||
parser.connect_db()
|
||||
|
||||
# Processa file in modalità follow (come tail -f)
|
||||
print("[INFO] Avvio processamento log (modalità follow)...")
|
||||
parser.process_log_file(log_file, follow=True)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Errore critico: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
print("[DEBUG] Chiusura connessione database...")
|
||||
parser.disconnect_db()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== SYSLOG PARSER PER ROUTER MIKROTIK ===")
|
||||
print("Pressione Ctrl+C per interrompere\n")
|
||||
main()
|
||||
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n[INFO] Terminazione da utente (Ctrl+C)")
|
||||
except Exception as e:
|
||||
print(f"\n[ERROR] Errore fatale: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user