PowerSNMP for .NET
Trap2Message Class
Members  Example 




The Trap2Message class is used by agents to notify managers of an event. Uses SNMP version 2/3 encoding and is the functional equivalent of the Trap1Message used by SNMP version 1.
Object Model
Trap2Message ClassDecodingException ClassVariableCollection ClassVariable Class
Syntax
<SerializableAttribute()>
Public Class Trap2Message 
   Inherits StandardMessage
Dim instance As Trap2Message
[Serializable()]
public class Trap2Message : StandardMessage 
[Serializable()]
public __gc class Trap2Message : public StandardMessage 
[Serializable()]
public ref class Trap2Message : public StandardMessage 
Remarks

Three classes are included that specialize the Trap2Message class to standard NOTIFICATION-OBJECTs that are defined in RFC 1907:

1. Dart.Snmp.Trap2.coldStart

2. Dart.Snmp.Trap2.warmStart

3. Dart.Snmp.Trap2.authenticationFailure

This class replaces the NotificationMessage class in version 4.5 and prior.

Serializable using BinaryFormatter and XmlSerializer.

Example
The following example demonstrates how to send traps with the agent.
private void TrapSender_Load(object sender, EventArgs e)
{
    //Set sysObjectId to your enterprise number (for Trap1).
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid(), agent1.Mib.CreateVariable(NodeName.sysObjectID, "1.3.6.1.4.1.52222"));
}

private void buttonSendTrap1_Click(object sender, EventArgs e)
{
    //Send an SNMPv1 Trap
    agent1.Send(new Dart.Snmp.Trap1.warmStart(agent1.Variables[agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid()].Value.ToString(), agent1.SysUpTime), myManagerAddress);
}

private void buttonSendTrap2_Click(object sender, EventArgs e)
{
    //Send an SNMPv2 Trap (for SNMPv3, configure warmStart.Security.User)
    agent1.Send(new Dart.Snmp.Trap2.warmStart(agent1.SysUpTime), myManagerAddress);
}
Private Sub TrapSender_Load(ByVal sender As Object, ByVal e As EventArgs)
    'Set sysObjectId to your enterprise number (for Trap1).
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid(), agent1.Mib.CreateVariable(NodeName.sysObjectID, "1.3.6.1.4.1.52222"))
End Sub

Private Sub buttonSendTrap1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Send an SNMPv1 Trap
    agent1.Send(New Dart.Snmp.Trap1.warmStart(agent1.Variables(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid()).Value.ToString(), agent1.SysUpTime), myManagerAddress)
End Sub

Private Sub buttonSendTrap2_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Send an SNMPv2 Trap (for SNMPv3, configure warmStart.Security.User)
    agent1.Send(New Dart.Snmp.Trap2.warmStart(agent1.SysUpTime), myManagerAddress)
End Sub
Inheritance Hierarchy

System.Object
   Dart.Snmp.MessageBase
      Dart.Snmp.StandardMessage
         Dart.Snmp.Trap2Message
            Dart.Snmp.Trap2.authenticationFailure
            Dart.Snmp.Trap2.coldStart
            Dart.Snmp.Trap2.warmStart

See Also

Reference

Trap2Message Members
Dart.Snmp Namespace


PowerSNMP for .NET Documentation Version 5.0
© 2021 Dart Communications. All Rights Reserved.
Send comments on this topic