Agent Object : SendTrap Method |
Visual Basic |
---|
Public Sub SendTrap( _ ByVal trapMessage As SnmpMessage, _ ByVal targetEP As IPEndPoint, _ ByVal localEP As IPEndPoint _ ) |
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.
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