rename log-reasons to log-events with structured prefixes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-18 08:17:45 -08:00
parent 545a448bca
commit e3bed567ab
3 changed files with 13 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ func main() {
noARP := flag.Bool("no-arp", false, "disable ARP discovery") noARP := flag.Bool("no-arp", false, "disable ARP discovery")
noLLDP := flag.Bool("no-lldp", false, "disable LLDP discovery") noLLDP := flag.Bool("no-lldp", false, "disable LLDP discovery")
noSNMP := flag.Bool("no-snmp", false, "disable SNMP discovery") noSNMP := flag.Bool("no-snmp", false, "disable SNMP discovery")
logReasons := flag.Bool("log-reasons", false, "log addition reasons") logEvents := flag.Bool("log-events", false, "log node events")
debugARP := flag.Bool("debug-arp", false, "debug ARP discovery") debugARP := flag.Bool("debug-arp", false, "debug ARP discovery")
debugLLDP := flag.Bool("debug-lldp", false, "debug LLDP discovery") debugLLDP := flag.Bool("debug-lldp", false, "debug LLDP discovery")
debugSNMP := flag.Bool("debug-snmp", false, "debug SNMP discovery") debugSNMP := flag.Bool("debug-snmp", false, "debug SNMP discovery")
@@ -22,7 +22,7 @@ func main() {
t.DisableARP = *noARP t.DisableARP = *noARP
t.DisableLLDP = *noLLDP t.DisableLLDP = *noLLDP
t.DisableSNMP = *noSNMP t.DisableSNMP = *noSNMP
t.LogReasons = *logReasons t.LogEvents = *logEvents
t.DebugARP = *debugARP t.DebugARP = *debugARP
t.DebugLLDP = *debugLLDP t.DebugLLDP = *debugLLDP
t.DebugSNMP = *debugSNMP t.DebugSNMP = *debugSNMP

View File

@@ -84,6 +84,7 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, source string) {
} }
var targetID int var targetID int
isNew := false
if len(existingIDs) == 0 { if len(existingIDs) == 0 {
targetID = n.nextID targetID = n.nextID
n.nextID++ n.nextID++
@@ -91,6 +92,7 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, source string) {
IPs: map[string]net.IP{}, IPs: map[string]net.IP{},
MACs: map[string]net.HardwareAddr{}, MACs: map[string]net.HardwareAddr{},
} }
isNew = true
} else if len(existingIDs) == 1 { } else if len(existingIDs) == 1 {
for id := range existingIDs { for id := range existingIDs {
targetID = id targetID = id
@@ -106,8 +108,8 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, source string) {
merging = append(merging, n.nodes[ids[i]].String()) merging = append(merging, n.nodes[ids[i]].String())
n.mergeNodes(targetID, ids[i]) n.mergeNodes(targetID, ids[i])
} }
if n.t.LogReasons { if n.t.LogEvents {
log.Printf("merged nodes %v into %s (via %s)", merging, n.nodes[targetID], source) log.Printf("[merge] %v into %s (via %s)", merging, n.nodes[targetID], source)
} }
} }
@@ -132,8 +134,12 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, source string) {
n.macIndex[macKey] = targetID n.macIndex[macKey] = targetID
} }
if len(added) > 0 && n.t.LogReasons { if len(added) > 0 && n.t.LogEvents {
log.Printf("updated %s +%v (via %s)", node, added, source) if isNew {
log.Printf("[add] %s %v (via %s)", node, added, source)
} else {
log.Printf("[update] %s +%v (via %s)", node, added, source)
}
} }
} }

View File

@@ -16,7 +16,7 @@ type Tendrils struct {
DisableARP bool DisableARP bool
DisableLLDP bool DisableLLDP bool
DisableSNMP bool DisableSNMP bool
LogReasons bool LogEvents bool
DebugARP bool DebugARP bool
DebugLLDP bool DebugLLDP bool
DebugSNMP bool DebugSNMP bool