-
Notifications
You must be signed in to change notification settings - Fork 48
/
multiget.go
69 lines (59 loc) · 1.2 KB
/
multiget.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
package main
import (
"fmt"
"sync"
"github.com/k-sone/snmpgo"
)
func get(agent string, oids snmpgo.Oids) {
// create a SNMP Object for each the agent
snmp, err := snmpgo.NewSNMP(snmpgo.SNMPArguments{
Version: snmpgo.V2c,
Address: agent,
Retries: 1,
Community: "public",
})
if err != nil {
fmt.Printf("[%s] : construct error - %s\n", agent, err)
return
}
if err = snmp.Open(); err != nil {
fmt.Printf("[%s] : open error - %s\n", agent, err)
return
}
defer snmp.Close()
pdu, err := snmp.GetRequest(oids)
if err != nil {
fmt.Printf("[%s] : get error - %s\n", agent, err)
return
}
if pdu.ErrorStatus() != snmpgo.NoError {
fmt.Printf("[%s] : error status - %s at %d\n",
agent, pdu.ErrorStatus(), pdu.ErrorIndex())
}
fmt.Printf("[%s] : %s\n", agent, pdu.VarBinds())
}
func main() {
oids, err := snmpgo.NewOids([]string{
"1.3.6.1.2.1.1.1.0",
"1.3.6.1.2.1.1.2.0",
"1.3.6.1.2.1.1.3.0",
})
if err != nil {
fmt.Println(err)
return
}
agents := []string{
"192.168.1.1:161",
"192.168.1.2:161",
"192.168.1.3:161",
}
var wg sync.WaitGroup
for _, agent := range agents {
wg.Add(1)
go func(a string) {
defer wg.Done()
get(a, oids)
}(agent)
}
wg.Wait()
}