First stab, an empty main.go which comes from the go-agentx upstream module

This commit is contained in:
Pim van Pelt
2025-06-09 16:54:28 +02:00
commit 363215eaab
3 changed files with 100 additions and 0 deletions

7
go.mod Normal file
View File

@ -0,0 +1,7 @@
module govpp-snmp-example
go 1.23.5
require github.com/posteo/go-agentx v0.2.1
replace github.com/posteo/go-agentx => ./go-agentx

12
go.sum Normal file
View File

@ -0,0 +1,12 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posteo/go-agentx v0.2.1 h1:HO0zO/+GosL0RYEodu7KNH9OF/rL5bJbhXNP1z3hkT8=
github.com/posteo/go-agentx v0.2.1/go.mod h1:EUR75CfAEDstQn3WqCs26Ti64EsggaSXDk2dgxPQ5TI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

81
main.go Normal file
View File

@ -0,0 +1,81 @@
package main
import (
"log"
"net"
"time"
"github.com/posteo/go-agentx"
"github.com/posteo/go-agentx/pdu"
"github.com/posteo/go-agentx/value"
)
func main() {
client, err := agentx.Dial("tcp", "localhost:705")
if err != nil {
log.Fatalf("Failed to dial: %v", err)
}
client.Timeout = 1 * time.Minute
client.ReconnectInterval = 1 * time.Second
session, err := client.Session()
if err != nil {
log.Fatalf("Failed to create session: %v", err)
}
listHandler := &agentx.ListHandler{}
item := listHandler.Add("1.3.6.1.4.1.45995.3.0")
item.Type = pdu.VariableTypeInteger
item.Value = int32(-123)
item = listHandler.Add("1.3.6.1.4.1.45995.3.1")
item.Type = pdu.VariableTypeOctetString
item.Value = "echo test"
item = listHandler.Add("1.3.6.1.4.1.45995.3.2")
item.Type = pdu.VariableTypeOctetString
item.Value = "1.3.6.1.4.1.45995.3.0.5"
item = listHandler.Add("1.3.6.1.4.1.45995.3.3")
item.Type = pdu.VariableTypeIPAddress
item.Value = net.IP{10, 10, 10, 10}
item = listHandler.Add("1.3.6.1.4.1.45995.3.4")
item.Type = pdu.VariableTypeCounter32
item.Value = uint32(123)
item = listHandler.Add("1.3.6.1.4.1.45995.3.5")
item.Type = pdu.VariableTypeGauge32
item.Value = uint32(123)
item = listHandler.Add("1.3.6.1.4.1.45995.3.6")
item.Type = pdu.VariableTypeTimeTicks
item.Value = 123 * time.Second
item = listHandler.Add("1.3.6.1.4.1.45995.3.7")
item.Type = pdu.VariableTypeOpaque
item.Value = []byte{1, 2, 3}
item = listHandler.Add("1.3.6.1.4.1.45995.3.8")
item.Type = pdu.VariableTypeCounter64
item.Value = uint64(1234567890123456)
item = listHandler.Add("1.3.6.1.4.1.45995.3.9")
item.Type = pdu.VariableTypeCounter64
item.Value = uint64(12345)
item = listHandler.Add("1.3.6.1.4.1.45995.3.10")
item.Type = pdu.VariableTypeOctetString
item.Value = "hoi pim"
session.Handler = listHandler
if err := session.Register(127, value.MustParseOID("1.3.6.1.4.1.45995.3")); err != nil {
log.Fatalf("Failed to register: %v", err)
}
for {
time.Sleep(100 * time.Millisecond)
}
}