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

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)
}
}