// Copyright 2025, IPng Networks GmbH, Pim van Pelt package agentx import ( "flag" "strings" "time" "github.com/posteo/go-agentx" "govpp-snmp-agentx/ifmib" "govpp-snmp-agentx/logger" ) var ( // Flags for AgentX configuration AgentXAddr = flag.String("agentx.addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)") ) // StartAgentXRoutine initializes the AgentX client and registers the interface MIB func StartAgentXRoutine(interfaceMIB *ifmib.InterfaceMIB) error { var network, address string if strings.HasPrefix(*AgentXAddr, "/") { network = "unix" address = *AgentXAddr } else { network = "tcp" address = *AgentXAddr } logger.Debugf("Connecting to AgentX at %s://%s", network, address) client, err := agentx.Dial(network, address) if err != nil { return err } client.Timeout = 1 * time.Minute client.ReconnectInterval = 1 * time.Second // Register the interface MIB with the AgentX client if err := interfaceMIB.RegisterWithClient(client); err != nil { return err } logger.Printf("Successfully registered with AgentX at %s://%s", network, address) return nil }