package main import ( "flag" "log" "strings" "time" "github.com/posteo/go-agentx" "govpp-snmp-example/ifmib" "govpp-snmp-example/vppstats" ) func main() { addr := flag.String("agentx-addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)") vppStatsAddr := flag.String("vpp-stats-addr", "/var/run/vpp/stats.sock", "VPP stats socket path") period := flag.Float64("period", 10.0, "Interval in seconds for querying VPP interface stats") ifIndexOffset := flag.Int("vpp-ifindex-offset", 1000, "Offset to add to VPP interface indices for SNMP") debug := flag.Bool("debug", false, "Enable debug logging") flag.Parse() var network, address string if strings.HasPrefix(*addr, "/") { network = "unix" address = *addr } else { network = "tcp" address = *addr } client, err := agentx.Dial(network, address) if err != nil { log.Fatalf("Failed to dial %s %s: %v", network, address, err) } client.Timeout = 1 * time.Minute client.ReconnectInterval = 1 * time.Second // Create the interface MIB interfaceMIB := ifmib.NewInterfaceMIB(*ifIndexOffset, *debug) // Register the interface MIB with the AgentX client if err := interfaceMIB.RegisterWithClient(client); err != nil { log.Fatalf("Failed to register interface MIB: %v", err) } // Start VPP stats routine with callback to update MIB vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond, interfaceMIB.UpdateStats, *debug) for { time.Sleep(100 * time.Millisecond) } }