这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
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
6 changes: 6 additions & 0 deletions cmd/scollector/collectors/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func snmp_oid(host, community, oid string) (*big.Int, error) {
return v, err
}

func snmpOidString(host, community, oid string) (string, error) {
var v []byte
err := snmp.Get(host, community, oid, &v)
return string(v), err
}

func snmp_convertToFloat(v interface{}) (float64, error) {
switch val := v.(type) {
case int:
Expand Down
34 changes: 34 additions & 0 deletions cmd/scollector/collectors/snmp_cisco.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func SNMPCiscoASA(cfg conf.SNMP) {
Interval: time.Second * 30,
name: fmt.Sprintf("snmp-cisco-asa-%s", cfg.Host),
},
&IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_cisco_desc(cfg.Host, cfg.Community)
},
Interval: time.Minute * 5,
name: fmt.Sprintf("snmp-cisco-desc-%s", cfg.Host),
},
)
}

Expand All @@ -40,6 +47,13 @@ func SNMPCiscoIOS(cfg conf.SNMP) {
Interval: time.Second * 30,
name: fmt.Sprintf("snmp-cisco-ios-%s", cfg.Host),
},
&IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_cisco_desc(cfg.Host, cfg.Community)
},
Interval: time.Minute * 5,
name: fmt.Sprintf("snmp-cisco-desc-%s", cfg.Host),
},
)
}

Expand All @@ -54,6 +68,13 @@ func SNMPCiscoNXOS(cfg conf.SNMP) {
Interval: time.Second * 30,
name: fmt.Sprintf("snmp-cisco-nxos-%s", cfg.Host),
},
&IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_cisco_desc(cfg.Host, cfg.Community)
},
Interval: time.Minute * 5,
name: fmt.Sprintf("snmp-cisco-desc-%s", cfg.Host),
},
)
}

Expand Down Expand Up @@ -218,3 +239,16 @@ func c_cisco_nxos(host, community string, cpuIntegrator tsIntegrator) (opentsdb.
}
return md, nil
}

func c_cisco_desc(host, community string) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
desc, err := getSNMPDesc(host, community)
if err != nil {
return md, err
}
if desc == "" {
return md, fmt.Errorf("empty description string (used to get OS version) for cisco host %v", host)
}
metadata.AddMeta("", opentsdb.TagSet{"host": host}, "versionCaption", desc, false)
return md, nil
}
15 changes: 14 additions & 1 deletion cmd/scollector/collectors/snmp_sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"bosun.org/opentsdb"
)

const 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."
const (
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."
sysDescr = ".1.3.6.1.2.1.1.1.0"
)

// SNMPSys registers a SNMP system data collector for the given community and host.
func SNMPSys(cfg conf.SNMP) {
Expand All @@ -32,3 +35,13 @@ func c_snmp_sys(host, community string) (opentsdb.MultiDataPoint, error) {
Add(&md, osSystemUptime, uptime.Int64()/big.NewInt(100).Int64(), opentsdb.TagSet{"host": host}, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
return md, nil
}

// Description may mean different things so it isn't called in sys, for example
// with cisco it is the os version
func getSNMPDesc(host, community string) (description string, err error) {
description, err = snmpOidString(host, community, sysDescr)
if err != nil {
return description, fmt.Errorf("failed to fetch description for host %v: %v", host, err)
}
return
}