From e92a09e1196194cb89ec5132ade635316b00de4e Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 17 Jan 2026 21:12:21 -0800 Subject: [PATCH] add debug flags for arp, lldp, and snmp discovery --- arp.go | 4 ++++ cmd/tendrils/main.go | 6 ++++++ lldp.go | 4 ++++ snmp.go | 12 ++++++++++++ tendrils.go | 3 +++ 5 files changed, 29 insertions(+) diff --git a/arp.go b/arp.go index 983fec9..4a3b64b 100644 --- a/arp.go +++ b/arp.go @@ -44,6 +44,10 @@ func (t *Tendrils) readARPTable() { 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") } } diff --git a/cmd/tendrils/main.go b/cmd/tendrils/main.go index e978450..802c3e6 100644 --- a/cmd/tendrils/main.go +++ b/cmd/tendrils/main.go @@ -13,6 +13,9 @@ func main() { noSNMP := flag.Bool("no-snmp", false, "disable SNMP discovery") logTree := flag.Bool("log-tree", false, "log full tree on changes") 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() t := tendrils.New() @@ -22,5 +25,8 @@ func main() { t.DisableSNMP = *noSNMP t.LogTree = *logTree t.LogReasons = *logReasons + t.DebugARP = *debugARP + t.DebugLLDP = *debugLLDP + t.DebugSNMP = *debugSNMP t.Run() } diff --git a/lldp.go b/lldp.go index 09e5045..b4ab22f 100644 --- a/lldp.go +++ b/lldp.go @@ -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") if systemName != "" { diff --git a/snmp.go b/snmp.go index 08849df..e18d917 100644 --- a/snmp.go +++ b/snmp.go @@ -3,6 +3,7 @@ package tendrils import ( "context" "fmt" + "log" "net" "regexp" "strings" @@ -109,10 +110,17 @@ func (t *Tendrils) querySwitches() { func (t *Tendrils) querySNMPDevice(ip net.IP) { snmp, err := t.connectSNMP(ip) if err != nil { + if t.DebugSNMP { + log.Printf("[snmp] %s: connect failed: %v", ip, err) + } return } defer snmp.Conn.Close() + if t.DebugSNMP { + log.Printf("[snmp] %s: connected", ip) + } + t.querySysName(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 { t.nodes.Update([]net.IP{deviceIP}, []net.HardwareAddr{mac}, "", "", "snmp") } else { diff --git a/tendrils.go b/tendrils.go index 95b127d..2a75254 100644 --- a/tendrils.go +++ b/tendrils.go @@ -18,6 +18,9 @@ type Tendrils struct { DisableSNMP bool LogTree bool LogReasons bool + DebugARP bool + DebugLLDP bool + DebugSNMP bool } func New() *Tendrils {