add --log-nodes flag for comprehensive node logging
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ func main() {
|
|||||||
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")
|
||||||
logEvents := flag.Bool("log-events", false, "log node events")
|
logEvents := flag.Bool("log-events", false, "log node events")
|
||||||
|
logNodes := flag.Bool("log-nodes", false, "log full node details on changes")
|
||||||
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")
|
||||||
@@ -23,6 +24,7 @@ func main() {
|
|||||||
t.DisableLLDP = *noLLDP
|
t.DisableLLDP = *noLLDP
|
||||||
t.DisableSNMP = *noSNMP
|
t.DisableSNMP = *noSNMP
|
||||||
t.LogEvents = *logEvents
|
t.LogEvents = *logEvents
|
||||||
|
t.LogNodes = *logNodes
|
||||||
t.DebugARP = *debugARP
|
t.DebugARP = *debugARP
|
||||||
t.DebugLLDP = *debugLLDP
|
t.DebugLLDP = *debugLLDP
|
||||||
t.DebugSNMP = *debugSNMP
|
t.DebugSNMP = *debugSNMP
|
||||||
|
|||||||
51
nodes.go
51
nodes.go
@@ -15,21 +15,26 @@ type Interface struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interface) String() string {
|
func (i *Interface) String() string {
|
||||||
name := i.Name
|
|
||||||
if name == "" {
|
|
||||||
name = "??"
|
|
||||||
}
|
|
||||||
|
|
||||||
var ips []string
|
var ips []string
|
||||||
for _, ip := range i.IPs {
|
for _, ip := range i.IPs {
|
||||||
ips = append(ips, ip.String())
|
ips = append(ips, ip.String())
|
||||||
}
|
}
|
||||||
sort.Strings(ips)
|
sort.Strings(ips)
|
||||||
|
|
||||||
if len(ips) == 0 {
|
var parts []string
|
||||||
return fmt.Sprintf("%s/%s", name, i.MAC)
|
parts = append(parts, i.MAC.String())
|
||||||
|
if i.Name != "" {
|
||||||
|
parts = append(parts, fmt.Sprintf("(%s)", i.Name))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/%s %v", name, i.MAC, ips)
|
if len(ips) > 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("%v", ips))
|
||||||
|
}
|
||||||
|
|
||||||
|
result := parts[0]
|
||||||
|
for _, p := range parts[1:] {
|
||||||
|
result += " " + p
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
@@ -131,13 +136,18 @@ func (n *Nodes) Update(mac net.HardwareAddr, ips []net.IP, ifaceName, nodeName,
|
|||||||
node.Name = nodeName
|
node.Name = nodeName
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(added) > 0 && n.t.LogEvents {
|
if len(added) > 0 {
|
||||||
|
if n.t.LogEvents {
|
||||||
if isNew {
|
if isNew {
|
||||||
log.Printf("[add] %s %v (via %s)", node, added, source)
|
log.Printf("[add] %s %v (via %s)", node, added, source)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[update] %s +%v (via %s)", node, added, source)
|
log.Printf("[update] %s +%v (via %s)", node, added, source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if n.t.LogNodes {
|
||||||
|
n.logNode(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Nodes) Merge(macs []net.HardwareAddr, source string) {
|
func (n *Nodes) Merge(macs []net.HardwareAddr, source string) {
|
||||||
@@ -172,6 +182,10 @@ func (n *Nodes) Merge(macs []net.HardwareAddr, source string) {
|
|||||||
}
|
}
|
||||||
n.mergeNodes(targetID, ids[i])
|
n.mergeNodes(targetID, ids[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if n.t.LogNodes {
|
||||||
|
n.logNode(n.nodes[targetID])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Nodes) mergeNodes(keepID, mergeID int) {
|
func (n *Nodes) mergeNodes(keepID, mergeID int) {
|
||||||
@@ -223,6 +237,25 @@ func (n *Nodes) GetByMAC(mac net.HardwareAddr) *Node {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Nodes) logNode(node *Node) {
|
||||||
|
name := node.Name
|
||||||
|
if name == "" {
|
||||||
|
name = "??"
|
||||||
|
}
|
||||||
|
log.Printf("[node] %s", name)
|
||||||
|
|
||||||
|
var macKeys []string
|
||||||
|
for macKey := range node.Interfaces {
|
||||||
|
macKeys = append(macKeys, macKey)
|
||||||
|
}
|
||||||
|
sort.Strings(macKeys)
|
||||||
|
|
||||||
|
for _, macKey := range macKeys {
|
||||||
|
iface := node.Interfaces[macKey]
|
||||||
|
log.Printf("[node] %s", iface)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (n *Nodes) All() []*Node {
|
func (n *Nodes) All() []*Node {
|
||||||
n.mu.RLock()
|
n.mu.RLock()
|
||||||
defer n.mu.RUnlock()
|
defer n.mu.RUnlock()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type Tendrils struct {
|
|||||||
DisableLLDP bool
|
DisableLLDP bool
|
||||||
DisableSNMP bool
|
DisableSNMP bool
|
||||||
LogEvents bool
|
LogEvents bool
|
||||||
|
LogNodes bool
|
||||||
DebugARP bool
|
DebugARP bool
|
||||||
DebugLLDP bool
|
DebugLLDP bool
|
||||||
DebugSNMP bool
|
DebugSNMP bool
|
||||||
|
|||||||
Reference in New Issue
Block a user