Last active
September 13, 2019 11:12
-
-
Save kevsersrca/be08e046fdc87031191d1ba84ed78bfd to your computer and use it in GitHub Desktop.
Golang Snmp Trials 🐰
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
"time" | |
"gopkg.in/errgo.v1" | |
"github.com/posteo/go-agentx" | |
"github.com/posteo/go-agentx/pdu" | |
"github.com/posteo/go-agentx/value" | |
) | |
func main() { | |
client := &agentx.Client{ | |
Net: "tcp", | |
Address: "localhost:161", | |
Timeout: 1 * time.Minute, | |
ReconnectInterval: 1 * time.Second, | |
} | |
if err := client.Open(); err != nil { | |
log.Fatalf(errgo.Details(err)) | |
} | |
session, err := client.Session() | |
if err != nil { | |
log.Fatalf(errgo.Details(err)) | |
} | |
listHandler := &agentx.ListHandler{} | |
item := listHandler.Add("1.3.6.1.4.1.45995.3.1") | |
item.Type = pdu.VariableTypeInteger | |
item.Value = int32(-123) | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.2") | |
item.Type = pdu.VariableTypeOctetString | |
item.Value = "echo test" | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.3") | |
item.Type = pdu.VariableTypeNull | |
item.Value = nil | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.4") | |
item.Type = pdu.VariableTypeObjectIdentifier | |
item.Value = "1.3.6.1.4.1.45995.1.5" | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.5") | |
item.Type = pdu.VariableTypeIPAddress | |
item.Value = net.IP{10, 10, 10, 10} | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.6") | |
item.Type = pdu.VariableTypeCounter32 | |
item.Value = uint32(123) | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.7") | |
item.Type = pdu.VariableTypeGauge32 | |
item.Value = uint32(123) | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.8") | |
item.Type = pdu.VariableTypeTimeTicks | |
item.Value = 123 * time.Second | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.9") | |
item.Type = pdu.VariableTypeOpaque | |
item.Value = []byte{1, 2, 3} | |
item = listHandler.Add("1.3.6.1.4.1.45995.3.10") | |
item.Type = pdu.VariableTypeCounter64 | |
item.Value = uint64(12345678901234567890) | |
session.Handler = listHandler | |
if err := session.Register(127, value.MustParseOID("1.3.6.1.4.1.45995.3")); err != nil { | |
log.Fatalf(errgo.Details(err)) | |
} | |
for { | |
time.Sleep(100 * time.Millisecond) | |
} | |
} |
Author
kevsersrca
commented
Mar 1, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment