Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add foundry&brocade switches cpu&mem support #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cpustat.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func CpuUtilization(ip, community string, timeout, retry int) (int, error) {
case "Linux":
oid = "1.3.6.1.4.1.2021.11.11.0"
return getLinuxCpu(ip, community, oid, timeout, retry)
case "Foundry":
oid = "1.3.6.1.4.1.1991.1.1.2.1.52.0"
return getFoundryCpu(ip, community, oid, timeout, retry)
default:
err = errors.New(ip + " Switch Vendor is not defined")
return 0, err
Expand Down Expand Up @@ -184,6 +187,28 @@ func getDellCpu(ip, community, oid string, timeout, retry int) (value int, err e
return snmpPDUs[0].Value.(int), err
}

func getFoundryCpu(ip, community, oid string, timeout, retry int) (value int, err error) {

defer func() {
if r := recover(); r != nil {
log.Println(ip+" Recovered in CPUtilization", r)
}
}()
method := "getnext"

var snmpPDUs []gosnmp.SnmpPDU

for i := 0; i < retry; i++ {
snmpPDUs, err = RunSnmp(ip, community, oid, method, timeout)
if len(snmpPDUs) > 0 {
break
}
time.Sleep(100 * time.Millisecond)
}

return snmpPDUs[0].Value.(int), err
}

func getLinuxCpu(ip, community, oid string, timeout, retry int) (value int, err error) {

defer func() {
Expand Down
8 changes: 8 additions & 0 deletions descrstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func SysVendor(ip, community string, retry int, timeout int) (string, error) {
return "Dell", err
}

if strings.Contains(sysDescrLower, "brocade communications systems") {
return "Foundry", err
}

if strings.Contains(sysDescrLower, "foundry networks") {
return "Foundry", err
}

if strings.Contains(sysDescrLower, "linux") {
return "Linux", err
}
Expand Down
17 changes: 17 additions & 0 deletions memstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func MemUtilization(ip, community string, timeout, retry int) (int, error) {
return GetDellMem(ip, community, timeout, retry)
case "Linux":
return GetLinuxMem(ip, community, timeout, retry)
case "Foundry":
return GetFoundryMem(ip, community, timeout, retry)
default:
err = errors.New(ip + " Switch Vendor is not defined")
return 0, err
Expand Down Expand Up @@ -236,3 +238,18 @@ func GetLinuxMem(ip, community string, timeout, retry int) (int, error) {
}
return 0, err
}

func GetFoundryMem(ip, community string, timeout, retry int) (int, error) {
method := "getnext"
memTotalOid := "1.3.6.1.4.1.1991.1.1.2.1.54.0"
memTotal, err := RunSnmp(ip, community, memTotalOid, method, timeout)
memFreeOid := "1.3.6.1.4.1.1991.1.1.2.1.55.0"
memFree, err := RunSnmp(ip, community, memFreeOid, method, timeout)
if &memTotal[0] != nil && &memFree[0] != nil {
memfree := memFree[0].Value.(int)
memtotal := memTotal[0].Value.(int)
memUtili := float64(memtotal-memfree) / float64(memtotal)
return int(memUtili * 100), nil
}
return 0, err
}