bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/snmp_sys.go (about)

     1  package collectors
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  	"time"
     7  
     8  	"bosun.org/cmd/scollector/conf"
     9  	"bosun.org/metadata"
    10  	"bosun.org/opentsdb"
    11  )
    12  
    13  const (
    14  	sysUpTime = ".1.3.6.1.2.1.1.3.0" // "The time (in hundredths of a second) since the network management portion of the system was last re-initialized."
    15  	sysDescr  = ".1.3.6.1.2.1.1.1.0"
    16  )
    17  
    18  // SNMPSys registers a SNMP system data collector for the given community and host.
    19  func SNMPSys(cfg conf.SNMP) {
    20  	collectors = append(collectors, &IntervalCollector{
    21  		F: func() (opentsdb.MultiDataPoint, error) {
    22  			return c_snmp_sys(cfg.Host, cfg.Community)
    23  		},
    24  		Interval: time.Minute * 1,
    25  		name:     fmt.Sprintf("snmp-sys-%s", cfg.Host),
    26  	})
    27  }
    28  
    29  func c_snmp_sys(host, community string) (opentsdb.MultiDataPoint, error) {
    30  	var md opentsdb.MultiDataPoint
    31  	uptime, err := snmp_oid(host, community, sysUpTime)
    32  	if err != nil {
    33  		return md, err
    34  	}
    35  	Add(&md, osSystemUptime, uptime.Int64()/big.NewInt(100).Int64(), opentsdb.TagSet{"host": host}, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
    36  	return md, nil
    37  }
    38  
    39  // Description may mean different things so it isn't called in sys, for example
    40  // with cisco it is the os version
    41  func getSNMPDesc(host, community string) (description string, err error) {
    42  	description, err = snmpOidString(host, community, sysDescr)
    43  	if err != nil {
    44  		return description, fmt.Errorf("failed to fetch description for host %v: %v", host, err)
    45  	}
    46  	return
    47  }