// Copyright 2025, IPng Networks GmbH, Pim van Pelt package main import ( "flag" "log" "os" "os/signal" "syscall" "govpp-snmp-agentx/agentx" "govpp-snmp-agentx/config" "govpp-snmp-agentx/ifmib" "govpp-snmp-agentx/logger" "govpp-snmp-agentx/vpp" ) const Version = "1.2.3-1" func main() { debug := flag.Bool("debug", false, "Enable debug logging") vppcfg := flag.String("vppcfg", "", "VPP configuration YAML file to read interface descriptions from") flag.Parse() // Set global debug flag config.Debug = *debug // Log startup message with version logger.Printf("Starting govpp-snmp-agentx version %s", Version) // Create the interface MIB interfaceMIB := ifmib.NewInterfaceMIB() // Load VPP config if specified if *vppcfg != "" { if err := interfaceMIB.LoadVPPConfig(*vppcfg); err != nil { logger.Printf("Warning: Failed to load VPP config from %s: %v", *vppcfg, err) logger.Printf("Continuing without VPP config file...") } } // Start AgentX routine if err := agentx.StartAgentXRoutine(interfaceMIB); err != nil { log.Fatalf("Failed to start AgentX: %v", err) } // Create VPP client and managers vppClient := &vpp.VPPClient{} interfaceManager := vpp.NewInterfaceManager(vppClient) statsManager := vpp.NewStatsManager(vppClient, interfaceManager) // Set up interface event callback to update interface details interfaceManager.SetEventCallback(interfaceMIB.UpdateInterfaceDetails) // Set up stats callback to update MIB statsManager.SetStatsCallback(interfaceMIB.UpdateStats) // Start VPP stats routine statsManager.StartStatsRoutine() // Start interface event monitoring (handles reconnections automatically) interfaceManager.StartEventMonitoring() // Set up signal handling for graceful shutdown sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // Wait for shutdown signal <-sigChan logger.Printf("Shutting down...") // Stop stats routine and interface monitoring, then disconnect statsManager.StopStatsRoutine() interfaceManager.StopEventMonitoring() vppClient.Disconnect() // Flush any buffered log entries logger.Sync() }