Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gaochao1/sw
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomkk-qfeng committed May 27, 2022
2 parents e2a9208 + cc5434b commit 133be72
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
2 changes: 1 addition & 1 deletion fastping.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package sw

import (
"github.com/freedomkk-qfeng/go-fastping"
"net"
"time"
"github.com/tatsushid/go-fastping"
)

func fastPingRtt(ip string, timeout int) (float64, error) {
Expand Down
76 changes: 49 additions & 27 deletions ifstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,95 +280,117 @@ func ListIfStats(ip, community string, timeout int, ignoreIface []string, retry

for ti, ifHCInOctetsPDU := range ifInList {
if strings.Replace(ifHCInOctetsPDU.Name, ifHCInOidPrefix, "", 1) == ifIndexStr {
ifStats.IfHCInOctets = ifInList[ti].Value.(uint64)
ifStats.IfHCOutOctets = ifOutList[ti].Value.(uint64)
break
if ifInList[ti].Value != nil && ifOutList[ti].Value != nil {
ifStats.IfHCInOctets = ifInList[ti].Value.(uint64)
ifStats.IfHCOutOctets = ifOutList[ti].Value.(uint64)
break
}
}
}
if ignorePkt == false {
for ti, ifHCInPktsPDU := range ifInPktList {
if strings.Replace(ifHCInPktsPDU.Name, ifHCInPktsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfHCInUcastPkts = ifInPktList[ti].Value.(uint64)
ifStats.IfHCOutUcastPkts = ifOutPktList[ti].Value.(uint64)
break
if ifInPktList[ti].Value != nil && ifOutPktList[ti].Value != nil {
ifStats.IfHCInUcastPkts = ifInPktList[ti].Value.(uint64)
ifStats.IfHCOutUcastPkts = ifOutPktList[ti].Value.(uint64)
break
}
}
}
}
if ignoreBroadcastPkt == false {
for ti, ifHCInBroadcastPktPDU := range ifInBroadcastPktList {
if strings.Replace(ifHCInBroadcastPktPDU.Name, ifHCInBroadcastPktsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfHCInBroadcastPkts = ifInBroadcastPktList[ti].Value.(uint64)
ifStats.IfHCOutBroadcastPkts = ifOutBroadcastPktList[ti].Value.(uint64)
break
if ifInBroadcastPktList[ti].Value != nil && ifOutBroadcastPktList[ti].Value != nil {
ifStats.IfHCInBroadcastPkts = ifInBroadcastPktList[ti].Value.(uint64)
ifStats.IfHCOutBroadcastPkts = ifOutBroadcastPktList[ti].Value.(uint64)
break
}
}
}
}
if ignoreMulticastPkt == false {
for ti, ifHCInMulticastPktPDU := range ifInMulticastPktList {
if strings.Replace(ifHCInMulticastPktPDU.Name, ifHCInMulticastPktsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfHCInMulticastPkts = ifInMulticastPktList[ti].Value.(uint64)
ifStats.IfHCOutMulticastPkts = ifOutMulticastPktList[ti].Value.(uint64)
break
if ifInMulticastPktList[ti].Value != nil && ifOutMulticastPktList[ti].Value != nil {
ifStats.IfHCInMulticastPkts = ifInMulticastPktList[ti].Value.(uint64)
ifStats.IfHCOutMulticastPkts = ifOutMulticastPktList[ti].Value.(uint64)
break
}
}
}
}

if ignoreDiscards == false {
for ti, ifInDiscardsPDU := range ifInDiscardsList {
if strings.Replace(ifInDiscardsPDU.Name, ifInDiscardsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfInDiscards = ifInDiscardsList[ti].Value.(int)
ifStats.IfOutDiscards = ifOutDiscardsList[ti].Value.(int)
break
if ifInDiscardsList[ti].Value != nil && ifOutDiscardsList[ti].Value != nil {
ifStats.IfInDiscards = ifInDiscardsList[ti].Value.(int)
ifStats.IfOutDiscards = ifOutDiscardsList[ti].Value.(int)
break
}
}
}
}

if ignoreErrors == false {
for ti, ifInErrorsPDU := range ifInErrorsList {
if strings.Replace(ifInErrorsPDU.Name, ifInErrorsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfInErrors = ifInErrorsList[ti].Value.(int)
break
if ifInErrorsList[ti].Value != nil {
ifStats.IfInErrors = ifInErrorsList[ti].Value.(int)
break
}
}
}
for ti, ifOutErrorsPDU := range ifOutErrorsList {
if strings.Replace(ifOutErrorsPDU.Name, ifOutErrorsOidPrefix, "", 1) == ifIndexStr {
ifStats.IfOutErrors = ifOutErrorsList[ti].Value.(int)
break
if ifOutErrorsList[ti].Value != nil {
ifStats.IfOutErrors = ifOutErrorsList[ti].Value.(int)
break
}
}
}
}

if ignoreOperStatus == false {
for ti, ifOperStatusPDU := range ifStatusList {
if strings.Replace(ifOperStatusPDU.Name, ifOperStatusOidPrefix, "", 1) == ifIndexStr {
ifStats.IfOperStatus = ifStatusList[ti].Value.(int)
break
if ifStatusList[ti].Value != nil {
ifStats.IfOperStatus = ifStatusList[ti].Value.(int)
break
}
}
}
}

if ignoreUnknownProtos == false {
for ti, ifInUnknownProtosPDU := range ifInUnknownProtosList {
if strings.Replace(ifInUnknownProtosPDU.Name, ifInUnknownProtosPrefix, "", 1) == ifIndexStr {
ifStats.IfInUnknownProtos = ifInUnknownProtosList[ti].Value.(int)
break
if ifInUnknownProtosList[ti].Value != nil {
ifStats.IfInUnknownProtos = ifInUnknownProtosList[ti].Value.(int)
break
}
}
}
}

if ignoreOutQLen == false {
for ti, ifOutQLenPDU := range ifOutQLenList {
if strings.Replace(ifOutQLenPDU.Name, ifOutQLenPrefix, "", 1) == ifIndexStr {
ifStats.IfOutQLen = ifOutQLenList[ti].Value.(int)
break
if ifOutQLenList[ti].Value != nil {
ifStats.IfOutQLen = ifOutQLenList[ti].Value.(int)
break
}
}
}
}

for ti, ifSpeedPDU := range ifSpeedList {
if strings.Replace(ifSpeedPDU.Name, ifSpeedOidPrefix, "", 1) == ifIndexStr {
ifStats.IfSpeed = 1000 * 1000 * ifSpeedList[ti].Value.(int)
break
if ifSpeedList[ti].Value != nil {
ifStats.IfSpeed = 1000 * 1000 * ifSpeedList[ti].Value.(int)
break
}
}
}

Expand Down

0 comments on commit 133be72

Please sign in to comment.