Skip to content

Commit

Permalink
Fix SendTrap to allow v1 traps that have no varbinds (like coldStart) (
Browse files Browse the repository at this point in the history
…#426)

* Fix SendTrap to allow v1 traps that have no varbinds (like coldStart) (#426)

Signed-off-by: Damien Stuart <dstuart@dstuart.org>
  • Loading branch information
damienstuart committed Feb 2, 2023
1 parent 9d67d21 commit 7f6d705
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions trap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Sending Traps ie GoSNMP acting as an Agent
//

// SendTrap sends a SNMP Trap (v2c/v3 only)
// SendTrap sends a SNMP Trap
//
// pdus[0] can a pdu of Type TimeTicks (with the desired uint32 epoch
// time). Otherwise a TimeTicks pdu will be prepended, with time set to
Expand All @@ -33,22 +33,22 @@ import (
func (x *GoSNMP) SendTrap(trap SnmpTrap) (result *SnmpPacket, err error) {
var pdutype PDUType

if len(trap.Variables) == 0 {
return nil, fmt.Errorf("function SendTrap requires at least 1 PDU")
}

if trap.Variables[0].Type == TimeTicks {
// check is uint32
if _, ok := trap.Variables[0].Value.(uint32); !ok {
return nil, fmt.Errorf("function SendTrap TimeTick must be uint32")
}
}

switch x.Version {
case Version2c, Version3:
// Default to a v2 trap.
pdutype = SNMPv2Trap

if len(trap.Variables) == 0 {
return nil, fmt.Errorf("function SendTrap requires at least 1 PDU")
}

if trap.Variables[0].Type == TimeTicks {
// check is uint32
if _, ok := trap.Variables[0].Value.(uint32); !ok {
return nil, fmt.Errorf("function SendTrap TimeTick must be uint32")
}
}

switch x.MsgFlags {
// as per https://www.rfc-editor.org/rfc/rfc3412.html#section-6.4
// The reportableFlag MUST always be zero when the message contains
Expand Down

0 comments on commit 7f6d705

Please sign in to comment.