diff --git a/cmd/tendrils/main.go b/cmd/tendrils/main.go index 3561bef..5dc76a9 100644 --- a/cmd/tendrils/main.go +++ b/cmd/tendrils/main.go @@ -11,7 +11,7 @@ func main() { noARP := flag.Bool("no-arp", false, "disable ARP discovery") noLLDP := flag.Bool("no-lldp", false, "disable LLDP 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") debugLLDP := flag.Bool("debug-lldp", false, "debug LLDP discovery") debugSNMP := flag.Bool("debug-snmp", false, "debug SNMP discovery") @@ -22,7 +22,7 @@ func main() { t.DisableARP = *noARP t.DisableLLDP = *noLLDP t.DisableSNMP = *noSNMP - t.LogReasons = *logReasons + t.LogEvents = *logEvents t.DebugARP = *debugARP t.DebugLLDP = *debugLLDP t.DebugSNMP = *debugSNMP diff --git a/nodes.go b/nodes.go index 47ab940..78be15f 100644 --- a/nodes.go +++ b/nodes.go @@ -84,6 +84,7 @@ func (n *Nodes) Update(ips []net.IP, macs []net.HardwareAddr, source string) { } var targetID int + isNew := false if len(existingIDs) == 0 { targetID = 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{}, MACs: map[string]net.HardwareAddr{}, } + isNew = true } else if len(existingIDs) == 1 { for id := range existingIDs { 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()) n.mergeNodes(targetID, ids[i]) } - if n.t.LogReasons { - log.Printf("merged nodes %v into %s (via %s)", merging, n.nodes[targetID], source) + if n.t.LogEvents { + 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 } - if len(added) > 0 && n.t.LogReasons { - log.Printf("updated %s +%v (via %s)", node, added, source) + if len(added) > 0 && n.t.LogEvents { + if isNew { + log.Printf("[add] %s %v (via %s)", node, added, source) + } else { + log.Printf("[update] %s +%v (via %s)", node, added, source) + } } } diff --git a/tendrils.go b/tendrils.go index 6a67ec7..5a19c46 100644 --- a/tendrils.go +++ b/tendrils.go @@ -16,7 +16,7 @@ type Tendrils struct { DisableARP bool DisableLLDP bool DisableSNMP bool - LogReasons bool + LogEvents bool DebugARP bool DebugLLDP bool DebugSNMP bool