-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtrapv3.go
56 lines (47 loc) · 1.49 KB
/
trapv3.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
package main
import (
"fmt"
"github.com/k-sone/snmpgo"
)
func main() {
// `snmpgo.SNMP.Open` function execute the EngineID Discovery when you use V3.
// Specify the Agent's EngineID to `snmpgo.SNMPArguments.SecurityEngineId` parameter,
// if you want to suppress this behavior.
snmp, err := snmpgo.NewSNMP(snmpgo.SNMPArguments{
Version: snmpgo.V3,
Address: "127.0.0.1:162",
Retries: 1,
UserName: "MyName",
SecurityLevel: snmpgo.AuthPriv,
AuthPassword: "aaaaaaaa",
AuthProtocol: snmpgo.Sha,
PrivPassword: "bbbbbbbb",
PrivProtocol: snmpgo.Aes,
SecurityEngineId: "8000000004736e6d70676f",
})
if err != nil {
// Failed to create snmpgo.SNMP object
fmt.Println(err)
return
}
// Build VarBind list
var varBinds snmpgo.VarBinds
varBinds = append(varBinds, snmpgo.NewVarBind(snmpgo.OidSysUpTime, snmpgo.NewTimeTicks(1000)))
oid, _ := snmpgo.NewOid("1.3.6.1.6.3.1.1.5.3")
varBinds = append(varBinds, snmpgo.NewVarBind(snmpgo.OidSnmpTrap, oid))
oid, _ = snmpgo.NewOid("1.3.6.1.2.1.2.2.1.1.2")
varBinds = append(varBinds, snmpgo.NewVarBind(oid, snmpgo.NewInteger(2)))
oid, _ = snmpgo.NewOid("1.3.6.1.2.1.31.1.1.1.1.2")
varBinds = append(varBinds, snmpgo.NewVarBind(oid, snmpgo.NewOctetString([]byte("eth0"))))
if err = snmp.Open(); err != nil {
// Failed to open connection
fmt.Println(err)
return
}
defer snmp.Close()
if err = snmp.V2Trap(varBinds); err != nil {
// Failed to request
fmt.Println(err)
return
}
}