本文整理汇总了Golang中github.com/soniah/gosnmp.GoSNMP.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang GoSNMP.Get方法的具体用法?Golang GoSNMP.Get怎么用?Golang GoSNMP.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/soniah/gosnmp.GoSNMP
的用法示例。
在下文中一共展示了GoSNMP.Get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getTemperatures
func getTemperatures(snmp g.GoSNMP) map[int]float64 {
result, err := snmp.Get([]string{".1.3.6.1.4.1.6574.2.1.1.6.0", ".1.3.6.1.4.1.6574.2.1.1.6.1"})
if err != nil {
log.Fatalf("Get() err: %v", err)
}
temps := map[int]float64{}
for i, variable := range result.Variables {
temps[i] = float64(variable.Value.(int))
}
return temps
}
示例2: FetchData
func (p LoadPlugin) FetchData(snmp g.GoSNMP) map[string]float64 {
result, err := snmp.Get([]string{".1.3.6.1.4.1.2021.10.1.5.1", ".1.3.6.1.4.1.2021.10.1.5.2", ".1.3.6.1.4.1.2021.10.1.5.3"})
if err != nil {
log.Fatalf("Get() err: %v", err)
}
return map[string]float64{
"load.shortterm": float64(result.Variables[0].Value.(int)) / 100,
"load.midterm": float64(result.Variables[1].Value.(int)) / 100,
"load.longterm": float64(result.Variables[2].Value.(int)) / 100,
}
}
示例3: snmpStats
func snmpStats(snmp *gosnmp.GoSNMP, cfg *SnmpConfig) error {
now := time.Now()
if cfg == nil {
log.Fatal("cfg is nil")
}
if cfg.Influx == nil {
log.Fatal("influx cfg is nil")
}
bps := cfg.Influx.BP()
// we can only get 'maxOids' worth of snmp requests at a time
for i := 0; i < len(cfg.oids); i += maxOids {
end := i + maxOids
if end > len(cfg.oids) {
end = len(cfg.oids)
}
cfg.incRequests()
pkt, err := snmp.Get(cfg.oids[i:end])
if err != nil {
errLog("SNMP (%s) get error: %s\n", cfg.Host, err)
cfg.incErrors()
cfg.LastError = now
return err
}
cfg.incGets()
if verbose {
log.Println("SNMP GET CNT:", len(pkt.Variables))
}
//log.Println("PKT", pkt)
for _, pdu := range pkt.Variables {
val := getPoint(cfg, pdu)
if val == nil {
continue
}
if val.value == nil {
continue
}
//log.Println("VAL", val)
pt := makePoint(cfg.Host, val, now)
//log.Println("PT", pt)
bps.Points = append(bps.Points, pt)
}
}
cfg.Influx.Send(bps)
return nil
}
示例4: FetchData
func (p CPUPlugin) FetchData(snmp g.GoSNMP) map[string]float64 {
oids := []string{
".1.3.6.1.4.1.2021.11.50.0",
".1.3.6.1.4.1.2021.11.51.0",
".1.3.6.1.4.1.2021.11.52.0",
".1.3.6.1.4.1.2021.11.53.0",
".1.3.6.1.4.1.2021.11.54.0",
".1.3.6.1.4.1.2021.11.55.0",
".1.3.6.1.4.1.2021.11.56.0",
}
result, err := snmp.Get(oids)
if err != nil {
log.Fatalf("Get() err: %v", err)
}
return map[string]float64{
"cpu-0.cpu-user": float64(result.Variables[0].Value.(uint)),
"cpu-0.cpu-nice": float64(result.Variables[1].Value.(uint)),
"cpu-0.cpu-system": float64(result.Variables[2].Value.(uint)),
"cpu-0.cpu-idle": float64(result.Variables[3].Value.(uint)),
"cpu-0.cpu-wait": float64(result.Variables[4].Value.(uint)),
"cpu-0.cpu-kernel": float64(result.Variables[5].Value.(uint)),
"cpu-0.cpu-interrupt": float64(result.Variables[6].Value.(uint)),
}
}
示例5: sysObjectID
func sysObjectID(snmp *gosnmp.GoSNMP) (*string, error) {
r, err := snmp.Get([]string{
".1.3.6.1.2.1.1.2.0",
})
if r == nil || err != nil {
return nil, err
}
var oid *string
for _, v := range r.Variables {
switch v.Type {
case gosnmp.ObjectIdentifier:
switch v.Name {
case ".1.3.6.1.2.1.1.2.0":
if a := v.Value.(string); a != "" {
oid = &a
}
}
}
}
return oid, nil
}