fix
This commit is contained in:
47
scripts/send_trap.go
Normal file
47
scripts/send_trap.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gosnmp/gosnmp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
host := "127.0.0.1"
|
||||
port := uint16(9162)
|
||||
msg := "E2E-TRAP-GO"
|
||||
if len(os.Args) > 1 && os.Args[1] != "" {
|
||||
host = os.Args[1]
|
||||
}
|
||||
if len(os.Args) > 2 && os.Args[2] != "" {
|
||||
msg = os.Args[2]
|
||||
}
|
||||
g := &gosnmp.GoSNMP{
|
||||
Target: host,
|
||||
Port: port,
|
||||
Version: gosnmp.Version2c,
|
||||
Community: "public",
|
||||
Timeout: 2 * time.Second,
|
||||
Retries: 1,
|
||||
}
|
||||
if err := g.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer g.Conn.Close()
|
||||
|
||||
trap := gosnmp.SnmpTrap{
|
||||
Variables: []gosnmp.SnmpPDU{
|
||||
{
|
||||
Name: "1.3.6.1.2.1.1.1.0",
|
||||
Type: gosnmp.OctetString,
|
||||
Value: msg,
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := g.SendTrap(trap); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("trap_sent")
|
||||
}
|
||||
Reference in New Issue
Block a user