forked from gosnmp/gosnmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (35 loc) · 934 Bytes
/
main.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
// Copyright 2012 The GoSNMP Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
package main
import (
"log"
"os"
g "github.com/wecise/gosnmp"
)
func main() {
// Default is a pointer to a GoSNMP struct that contains sensible defaults
// eg port 161, community public, etc
g.Default.Target = "127.0.0.1"
g.Default.Port = 162
g.Default.Version = g.Version2c
g.Default.Community = "public"
g.Default.Logger = g.NewLogger(log.New(os.Stdout, "", 0))
err := g.Default.Connect()
if err != nil {
log.Fatalf("Connect() err: %v", err)
}
defer g.Default.Conn.Close()
pdu := g.SnmpPDU{
Name: ".1.3.6.1.6.3.1.1.4.1.0",
Type: g.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1",
}
trap := g.SnmpTrap{
Variables: []g.SnmpPDU{pdu},
}
_, err = g.Default.SendTrap(trap)
if err != nil {
log.Fatalf("SendTrap() err: %v", err)
}
}