add switch-wide poe budget tracking via snmp
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
40
snmp.go
40
snmp.go
@@ -125,6 +125,7 @@ func (t *Tendrils) querySNMPDevice(node *Node, ip net.IP) {
|
||||
t.querySysName(snmp, node)
|
||||
t.queryInterfaceMACs(snmp, node)
|
||||
t.queryInterfaceStats(snmp, node)
|
||||
t.queryPoEBudget(snmp, node)
|
||||
t.queryBridgeMIB(snmp, node)
|
||||
}
|
||||
|
||||
@@ -242,6 +243,45 @@ func (t *Tendrils) queryInterfaceStats(snmp *gosnmp.GoSNMP, node *Node) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tendrils) queryPoEBudget(snmp *gosnmp.GoSNMP, node *Node) {
|
||||
maxPowerOID := "1.3.6.1.2.1.105.1.3.1.1.2.1"
|
||||
powerOID := "1.3.6.1.2.1.105.1.3.1.1.4.1"
|
||||
|
||||
result, err := snmp.Get([]string{maxPowerOID, powerOID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var power, maxPower float64
|
||||
for _, v := range result.Variables {
|
||||
var val int
|
||||
switch x := v.Value.(type) {
|
||||
case int:
|
||||
val = x
|
||||
case uint:
|
||||
val = int(x)
|
||||
case int64:
|
||||
val = int(x)
|
||||
case uint64:
|
||||
val = int(x)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
if v.Name == "."+powerOID {
|
||||
power = float64(val)
|
||||
} else if v.Name == "."+maxPowerOID {
|
||||
maxPower = float64(val)
|
||||
}
|
||||
}
|
||||
|
||||
if maxPower > 0 {
|
||||
t.nodes.mu.Lock()
|
||||
node.PoEBudget = &PoEBudget{Power: power, MaxPower: maxPower}
|
||||
t.nodes.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tendrils) getInterfaceTable(snmp *gosnmp.GoSNMP, oid string) map[int]int {
|
||||
results, err := snmp.BulkWalkAll(oid)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user