-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_info.go
45 lines (41 loc) · 1.24 KB
/
host_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package hpmib
import (
"github.com/soniah/gosnmp"
)
// OIDs defined by the HP MIB that describe the properties of the system.
const (
cpqSiSysSerialNum OID = "1.3.6.1.4.1.232.2.2.2.1"
cpqSiProductName OID = "1.3.6.1.4.1.232.2.2.4.2"
)
// SerialNumber returns the serial number of the server.
// Returns a non-nil error if the serial number could not be determined.
func (m *MIB) SerialNumber() (string, error) {
res, err := m.snmpClient.GetNext([]string{string(cpqSiSysSerialNum)})
if err != nil {
return "", err
}
if len(res.Variables) == 0 {
return "", ErrNoResultsReturned
}
if res.Variables[0].Type != gosnmp.OctetString {
return "", ErrExpectedOctetString
}
serialNo := string(res.Variables[0].Value.([]byte))
return prettifyString(serialNo), nil
}
// Model returns the model of the server.
// Returns a non-nil error if the model could not be determined.
func (m *MIB) Model() (string, error) {
res, err := m.snmpClient.GetNext([]string{string(cpqSiProductName)})
if err != nil {
return "", err
}
if len(res.Variables) == 0 {
return "", ErrNoResultsReturned
}
if res.Variables[0].Type != gosnmp.OctetString {
return "", ErrExpectedOctetString
}
model := string(res.Variables[0].Value.([]byte))
return prettifyString(model), nil
}