-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreewave.go
117 lines (100 loc) · 2.35 KB
/
freewave.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dmc
import (
"net"
"regexp"
"strconv"
"strings"
"time"
"github.com/soniah/gosnmp"
)
type Freewave struct {
Community string
}
func (f *Freewave) Name() string {
return "Freewave"
}
func (f *Freewave) MatchString(s string) bool {
return regexp.MustCompile("^Freewave").MatchString(s)
}
func (f *Freewave) Groups() []ModelType {
return []ModelType{RadioModel}
}
func (f *Freewave) Group(g ModelType) bool {
switch g {
case RadioModel:
return true
default:
return false
}
}
func (f *Freewave) Identify(orig string, ip net.IP, timeout time.Duration, retries int) (*State, error) {
community := env(f.Community, "FREEWAVE_COMMUNITY", "public")
var snmp = &gosnmp.GoSNMP{
Target: ip.String(),
Port: 161,
Community: community,
Version: gosnmp.Version1,
Timeout: timeout,
Retries: retries,
}
if err := snmp.Connect(); err != nil {
return nil, nil
}
defer snmp.Conn.Close()
oid, err := sysObjectID(snmp)
if oid == nil || err != nil {
return nil, err
}
// not an freewave ...
if (*oid) != ".1.3.6.1.4.1.29956.2.1.1" {
return nil, nil
}
s := State{Values: make(map[string]interface{})}
// default model
s.Values["model"] = "Freewave Spread Spectrum Radio"
r, err := snmp.Get([]string{
".1.3.6.1.2.1.1.1.0",
".1.3.6.1.2.1.1.5.0",
".1.3.6.1.2.1.1.6.0",
".1.3.6.1.4.1.29956.3.1.1.1.1.12.1",
})
if r == nil || err != nil {
return nil, err
}
for _, v := range r.Variables {
switch v.Type {
case gosnmp.OctetString:
switch v.Name {
case ".1.3.6.1.2.1.1.1.0":
l := strings.Replace((string)(v.Value.([]byte)), "Freewave Technologies", "Freewave", -1)
l = strings.Replace(strings.Replace(strings.Replace(l, " (", ";", -1), " ;", ";", -1), ")", "", -1)
f := strings.Split(l, ";")
if len(f) > 0 {
s.Values["model"] = f[0]
for _, j := range f[1:] {
if k := strings.Fields(j); len(k) > 2 {
s.Values[k[0]] = k[2]
}
}
}
case ".1.3.6.1.2.1.1.5.0":
if a := (string)(v.Value.([]byte)); a != "" {
s.Values["name"] = a
}
case ".1.3.6.1.2.1.1.6.0":
if a := (string)(v.Value.([]byte)); a != "" {
s.Values["location"] = a
}
}
case gosnmp.Integer:
switch v.Name {
case ".1.3.6.1.4.1.29956.3.1.1.1.1.12.1":
if a := strconv.Itoa(v.Value.(int)); a != "" {
s.Values["serial"] = a
}
}
}
}
// done ...
return &s, nil
}