Make -debug a global config flag, clean up logger.Debugf() callsites
This commit is contained in:
@ -66,15 +66,13 @@ type InterfaceMIB struct {
|
||||
ifXTableSession *agentx.Session
|
||||
stats map[uint32]*api.InterfaceCounters // indexed by interface index
|
||||
indexOffset int
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewInterfaceMIB(indexOffset int, debug bool) *InterfaceMIB {
|
||||
func NewInterfaceMIB(indexOffset int) *InterfaceMIB {
|
||||
return &InterfaceMIB{
|
||||
handler: &agentx.ListHandler{},
|
||||
stats: make(map[uint32]*api.InterfaceCounters),
|
||||
indexOffset: indexOffset,
|
||||
debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +84,7 @@ func (m *InterfaceMIB) UpdateStats(interfaceStats *api.InterfaceStats) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
logger.Debugf(m.debug, "Updating IF-MIB with %d interfaces", len(interfaceStats.Interfaces))
|
||||
logger.Debugf("Updating IF-MIB with %d interfaces", len(interfaceStats.Interfaces))
|
||||
|
||||
// Clear existing entries
|
||||
m.handler = &agentx.ListHandler{}
|
||||
@ -94,7 +92,7 @@ func (m *InterfaceMIB) UpdateStats(interfaceStats *api.InterfaceStats) {
|
||||
|
||||
// Add new entries
|
||||
for _, iface := range interfaceStats.Interfaces {
|
||||
logger.Debugf(m.debug, "Processing interface %d (%s)", iface.InterfaceIndex, iface.InterfaceName)
|
||||
logger.Debugf("Processing interface %d (%s)", iface.InterfaceIndex, iface.InterfaceName)
|
||||
m.stats[iface.InterfaceIndex] = &iface
|
||||
m.addInterfaceToMIB(&iface)
|
||||
}
|
||||
@ -108,7 +106,7 @@ func (m *InterfaceMIB) UpdateStats(interfaceStats *api.InterfaceStats) {
|
||||
logger.Printf("Updated session handlers with new IF-MIB data")
|
||||
}
|
||||
|
||||
logger.Debugf(m.debug, "IF-MIB now contains %d interfaces", len(m.stats))
|
||||
logger.Debugf("IF-MIB now contains %d interfaces", len(m.stats))
|
||||
}
|
||||
|
||||
func (m *InterfaceMIB) addInterfaceToMIB(iface *api.InterfaceCounters) {
|
||||
@ -120,7 +118,7 @@ func (m *InterfaceMIB) addInterfaceToMIB(iface *api.InterfaceCounters) {
|
||||
// Add ifXTable (extended interface table) entries
|
||||
m.addIfXTable(iface, idx)
|
||||
|
||||
logger.Debugf(m.debug, "Added interface %d (%s) to IF-MIB with SNMP index %d", iface.InterfaceIndex, iface.InterfaceName, idx)
|
||||
logger.Debugf("Added interface %d (%s) to IF-MIB with SNMP index %d", iface.InterfaceIndex, iface.InterfaceName, idx)
|
||||
}
|
||||
|
||||
func (m *InterfaceMIB) addIfEntry(iface *api.InterfaceCounters, idx int) {
|
||||
@ -337,7 +335,7 @@ func (m *InterfaceMIB) RegisterWithClient(client *agentx.Client) error {
|
||||
return fmt.Errorf("failed to register ifXTable: %v", err)
|
||||
}
|
||||
|
||||
logger.Debugf(m.debug, "Registered IF-MIB ifEntry at OID %s", ifEntryOID)
|
||||
logger.Debugf(m.debug, "Registered IF-MIB ifXTable at OID %s", ifXTableOID)
|
||||
logger.Debugf("Registered IF-MIB ifEntry at OID %s", ifEntryOID)
|
||||
logger.Debugf("Registered IF-MIB ifXTable at OID %s", ifXTableOID)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user