Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP-V3 trap-send not work #469

Open
jingc1413 opened this issue May 14, 2024 · 0 comments
Open

SNMP-V3 trap-send not work #469

jingc1413 opened this issue May 14, 2024 · 0 comments

Comments

@jingc1413
Copy link

jingc1413 commented May 14, 2024

Hi, bro, i have some question, Please give some help or suggestions, thanks
gosnmp version: v1.37.0
go version: v1.19.6

1,Using the code in the example, start trap-serv and trap-cli to send and receive messages normally.
2,net-snmp snmptrapd can also receive messages normally
3,Use net-snmp snmptrapd as the server, and then use the gosnmp trap-send_v3 example to send data, but snmptrapd does not receive the data.

1)cat snmptrapd.conf

authCommunity log,execute,net public
createUser -e 123456789 user SHA pass AES pass
authuser log user

2), listen trap:

snmptrapd -f -d -m +ALL -Leo -On -C -c ./snmptrapd.conf udp:9888
output: 

image

3), send trap:

 snmptrap -v 3 -l authPriv -u user -a SHA -A "pass" -x AES -X "pass" -e 123456789 127.0.0.1:9888 "" 1.3.6.1.4.1.19046.11.1.158.5.1.24 s "hello world"

gosnmp trap-v3 send code:

package main

import (
    _ "crypto/md5"
    _ "crypto/sha1"
    "log"
    "os"
    "time"

    g "github.com/gosnmp/gosnmp"
)

func main() {
    params := &g.GoSNMP{
        Target:        "127.0.0.1",
        Port:          9888,
        Version:       g.Version3,
        Timeout:       time.Duration(30) * time.Second,
        SecurityModel: g.UserSecurityModel,
        MsgFlags:      g.AuthPriv,
        Logger:        g.NewLogger(log.New(os.Stdout, "", 0)),
        SecurityParameters: &g.UsmSecurityParameters{
            UserName: "user",
            AuthoritativeEngineID:    "123456789",
            AuthenticationProtocol:   g.SHA,
            AuthenticationPassphrase: "pass",
            PrivacyProtocol:          g.AES,
            PrivacyPassphrase:        "pass",
        },
    }
    err := params.Connect()
    if err != nil {
        log.Fatalf("Connect() err: %v", err)
    }
    defer params.Conn.Close()

    pdu := g.SnmpPDU{
        Name:  "1.3.6.1.4.1.19046.11.1.158.5.1.24",
        Type:  g.OctetString,
        Value: "hello world",
    }

    trap := g.SnmpTrap{
        Variables: []g.SnmpPDU{pdu},
    }

    _, err = params.SendTrap(trap)
    if err != nil {
        log.Fatalf("SendTrap() err: %v", err)
    }
}
@jingc1413 jingc1413 changed the title SNMP-V3-trap not work SNMP-V3 trap-send not work May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant