move agentx into its own directory, simplify main.go

This commit is contained in:
Pim van Pelt
2025-06-10 13:28:30 +02:00
parent 458168e308
commit 467975b9d6
3 changed files with 64 additions and 33 deletions

33
main.go
View File

@ -3,18 +3,14 @@ package main
import (
"flag"
"log"
"strings"
"time"
"github.com/posteo/go-agentx"
"govpp-snmp-example/agentx"
"govpp-snmp-example/config"
"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)")
debug := flag.Bool("debug", false, "Enable debug logging")
vppcfg := flag.String("vppcfg", "", "VPP configuration YAML file to read interface descriptions from")
flag.Parse()
@ -22,22 +18,6 @@ func main() {
// Set global debug flag
config.Debug = *debug
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()
@ -48,15 +28,14 @@ func main() {
}
}
// 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 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)
for {
time.Sleep(100 * time.Millisecond)
}
// Keep the main routine running
select {}
}