Move Go code to src/
This commit is contained in:
56
src/main.go
Normal file
56
src/main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2025, IPng Networks GmbH, Pim van Pelt <pim@ipng.ch>
|
||||
|
||||
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/vppstats"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Start VPP stats routine with callback to update MIB
|
||||
vppstats.StartStatsRoutine(interfaceMIB.UpdateStats)
|
||||
|
||||
// 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...")
|
||||
|
||||
// Flush any buffered log entries
|
||||
logger.Sync()
|
||||
}
|
||||
Reference in New Issue
Block a user