Dart SNMP Library 4.0
SendTrap Method
Trap SnmpMessage to send.
Trap destination.
The local network interface to send the trap from. Can be NULL/Nothing.
Description
Encode a trap message and send it to a manager.
Syntax
Visual Basic
Public Sub SendTrap( _
   ByVal trapMessage As SnmpMessage, _
   ByVal targetEP As IPEndPoint, _
   ByVal localEP As IPEndPoint _
) 
Parameters
trapMessage
Trap SnmpMessage to send.
targetEP
Trap destination.
localEP
The local network interface to send the trap from. Can be NULL/Nothing.
Remarks

A socket is created and released each time this method is used. It is safe to use in apartment-model environments because it executes quickly and there is no wait for a reply.

If localEP is specified, the socket is bound to the specified address family, address and port for sending from. If NULL/Nothing, a socket is created that uses a compatible 'Any' local interface and an ephemeral port.

trapMessage.Type must include snmpTrap; otherwise an exception is thrown.

Use Manager.GetResponse to send inform requests.

Example
Demonstrates how to generate and send a trap to the specified destination Manager address.
Private Sub SendTrap(destination As String, community As String, sysObjectId As String, version As Integer, _
snmpUser As User)
    Dim msg As New SnmpMessage

    If version = 1 Then
        msg.Type = PduConstants.pduTrap1
        msg.community = community
        msg.GenericTrap = GenericTrapConstants.trapWarmStart
        msg.Enterprise = sysObjectId
        msg.SysUpTime = Agent1.SysUpTime
    Else
        msg.Variables.Add Agent1.Mib.Nodes("sysUpTime").CreateVariable(Agent1.SysUpTime)
        msg.Variables.Add Agent1.Mib.Nodes("snmpTrapOID").CreateVariable(Agent1.Mib.Nodes("warmStart").Oid)
        
        If version = 2 Then
            msg.Type = PduConstants.pduTrap2
            msg.community = community
        ElseIf version = 3 Then
            msg.Type = PduConstants.pduTrap3
            msg.Security.User = snmpUser
        End If
    End If

    Dim destinationEP As New IPEndPoint
    destinationEP.NameOrAddress = destination
    destinationEP.Port = 162

    Agent1.SendTrap msg, destinationEP, Nothing
End Sub
See Also

Agent Object  | Agent Members


PowerSNMP for ActiveX Documentation Version 4.0
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic