Beispiel #1
0
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
}
Beispiel #2
0
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,
	}
}
Beispiel #3
0
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
}
Beispiel #4
0
Datei: snmp.go Projekt: ozym/dmc
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
}
Beispiel #5
0
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)),
	}
}