add debug flags for arp, lldp, and snmp discovery

This commit is contained in:
Ian Gulliver
2026-01-17 21:12:21 -08:00
parent 3c8afa9bdf
commit e92a09e119
5 changed files with 29 additions and 0 deletions

4
arp.go
View File

@@ -44,6 +44,10 @@ func (t *Tendrils) readARPTable() {
continue continue
} }
if t.DebugARP {
log.Printf("[arp] %s: ip=%s mac=%s", entry.iface, entry.ip, entry.mac)
}
t.nodes.Update([]net.IP{entry.ip}, []net.HardwareAddr{entry.mac}, entry.iface, "", "arp") t.nodes.Update([]net.IP{entry.ip}, []net.HardwareAddr{entry.mac}, entry.iface, "", "arp")
} }
} }

View File

@@ -13,6 +13,9 @@ func main() {
noSNMP := flag.Bool("no-snmp", false, "disable SNMP discovery") noSNMP := flag.Bool("no-snmp", false, "disable SNMP discovery")
logTree := flag.Bool("log-tree", false, "log full tree on changes") logTree := flag.Bool("log-tree", false, "log full tree on changes")
logReasons := flag.Bool("log-reasons", false, "log addition reasons") logReasons := flag.Bool("log-reasons", false, "log addition reasons")
debugARP := flag.Bool("debug-arp", false, "debug ARP discovery")
debugLLDP := flag.Bool("debug-lldp", false, "debug LLDP discovery")
debugSNMP := flag.Bool("debug-snmp", false, "debug SNMP discovery")
flag.Parse() flag.Parse()
t := tendrils.New() t := tendrils.New()
@@ -22,5 +25,8 @@ func main() {
t.DisableSNMP = *noSNMP t.DisableSNMP = *noSNMP
t.LogTree = *logTree t.LogTree = *logTree
t.LogReasons = *logReasons t.LogReasons = *logReasons
t.DebugARP = *debugARP
t.DebugLLDP = *debugLLDP
t.DebugSNMP = *debugSNMP
t.Run() t.Run()
} }

View File

@@ -64,6 +64,10 @@ func (t *Tendrils) handleLLDPPacket(ifaceName string, packet gopacket.Packet) {
} }
} }
if t.DebugLLDP {
log.Printf("[lldp] %s: mac=%s port=%s name=%s", ifaceName, mac, childPort, systemName)
}
t.nodes.Update(nil, []net.HardwareAddr{mac}, ifaceName, childPort, "lldp") t.nodes.Update(nil, []net.HardwareAddr{mac}, ifaceName, childPort, "lldp")
if systemName != "" { if systemName != "" {

12
snmp.go
View File

@@ -3,6 +3,7 @@ package tendrils
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"net" "net"
"regexp" "regexp"
"strings" "strings"
@@ -109,10 +110,17 @@ func (t *Tendrils) querySwitches() {
func (t *Tendrils) querySNMPDevice(ip net.IP) { func (t *Tendrils) querySNMPDevice(ip net.IP) {
snmp, err := t.connectSNMP(ip) snmp, err := t.connectSNMP(ip)
if err != nil { if err != nil {
if t.DebugSNMP {
log.Printf("[snmp] %s: connect failed: %v", ip, err)
}
return return
} }
defer snmp.Conn.Close() defer snmp.Conn.Close()
if t.DebugSNMP {
log.Printf("[snmp] %s: connected", ip)
}
t.querySysName(snmp, ip) t.querySysName(snmp, ip)
t.queryBridgeMIB(snmp, ip) t.queryBridgeMIB(snmp, ip)
} }
@@ -219,6 +227,10 @@ func (t *Tendrils) queryBridgeMIB(snmp *gosnmp.GoSNMP, deviceIP net.IP) {
} }
} }
if t.DebugSNMP {
log.Printf("[snmp] %s: mac=%s port=%s", deviceIP, mac, ifName)
}
if addToParent { if addToParent {
t.nodes.Update([]net.IP{deviceIP}, []net.HardwareAddr{mac}, "", "", "snmp") t.nodes.Update([]net.IP{deviceIP}, []net.HardwareAddr{mac}, "", "", "snmp")
} else { } else {

View File

@@ -18,6 +18,9 @@ type Tendrils struct {
DisableSNMP bool DisableSNMP bool
LogTree bool LogTree bool
LogReasons bool LogReasons bool
DebugARP bool
DebugLLDP bool
DebugSNMP bool
} }
func New() *Tendrils { func New() *Tendrils {