-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrf.go
58 lines (50 loc) · 1.32 KB
/
rf.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
46
47
48
49
50
51
52
53
54
55
56
57
58
package godocsis
import (
"errors"
"fmt"
"github.com/gosnmp/gosnmp"
//"log"
"strconv"
)
// Return Cable modem struct with filled fields related to CM RF parameters
// This will work on any cable modem since those are generic DOCSIS MIBS
func RFLevel(session gosnmp.GoSNMP) (CM, error) {
//Session.Target = ip
var cm CM
cm.IPaddr = session.Target
//var rfdata RFParams
DSLevel, err := snmpwalk(session, DsOid)
if err != nil {
fmt.Println("Error in RFLevel:", err)
return cm, errors.New(err.Error())
}
cm.RF.DSLevel = string2int_a(DSLevel)
USLevel, err := snmpwalk(session, UsOid)
if err != nil {
return cm, fmt.Errorf("Problem with US level retrieval: %s", err)
}
cm.RF.USLevel = string2int_a(USLevel)
//CM.RF = rfparams
return cm, nil
}
func CmVersion(session gosnmp.GoSNMP) (version string, err error) {
rs, err := snmpwalk(session, oid_cmVersion)
if err != nil {
fmt.Println("Error in CmVersion:", err)
return version, errors.New(err.Error())
}
if len(rs) == 1 {
version = rs[0]
} else {
return version, errors.New("Wrong number of returned varbinds - expected one")
}
return version, nil
}
// convert string to slice of integer values
func string2int_a(arstring []string) []int {
rs := make([]int, len(arstring))
for i, value := range arstring {
rs[i], _ = strconv.Atoi(value)
}
return rs
}