refactor to per-node snmp polling and immediate arp dump

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-22 23:09:54 -08:00
parent d2a09250d0
commit c3ed8e30e3
4 changed files with 94 additions and 53 deletions

40
snmp.go
View File

@@ -1,7 +1,6 @@
package tendrils
import (
"context"
"fmt"
"log"
"net"
@@ -80,36 +79,25 @@ func (t *Tendrils) connectSNMP(ip net.IP) (*gosnmp.GoSNMP, error) {
return snmp, nil
}
func (t *Tendrils) pollSNMP(ctx context.Context) {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
t.querySwitches()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
t.querySwitches()
}
func (t *Tendrils) pollNode(node *Node) {
if t.DisableSNMP {
return
}
}
func (t *Tendrils) querySwitches() {
nodes := t.nodes.All()
for _, node := range nodes {
for _, iface := range node.Interfaces {
for _, ip := range iface.IPs {
if ip.To4() == nil {
continue
}
go t.querySNMPDevice(node, ip)
t.nodes.mu.RLock()
var ips []net.IP
for _, iface := range node.Interfaces {
for _, ip := range iface.IPs {
if ip.To4() != nil {
ips = append(ips, ip)
}
}
}
t.nodes.mu.RUnlock()
for _, ip := range ips {
t.querySNMPDevice(node, ip)
}
}
func (t *Tendrils) querySNMPDevice(node *Node, ip net.IP) {