SendV2Trap() public method

Construct and send SNMP v2 Trap
public SendV2Trap ( IpAddress receiver, int receiverPort, string community, UInt32 senderUpTime, Oid trapObjectID, VbCollection varList ) : void
receiver IpAddress Trap receiver IP address
receiverPort int Trap receiver UDP port number
community string SNMP community name
senderUpTime System.UInt32 Sender sysUpTime
trapObjectID Oid Trap ObjectID
varList VbCollection Variable binding list
return void
        /// <summary>
        /// Send SNMP Trap notification
        /// </summary>
        /// <remarks>
        /// Helper function to allow for seamless sending of SNMP notifications for all protocol versions.
        ///
        /// packet parameter should be appropriately formatted SNMP notification in SnmpV1TrapPacket,
        /// SnmpV2Packet or SnmpV3Packet class cast as SnmpPacket class.
        ///
        /// Function will determine which version of the notification is to be used by checking the type
        /// of the packet parameter and call appropriate TrapAgent member function to send it.
        /// </remarks>
        /// <param name="packet">SNMP trap packet</param>
        /// <param name="peer">Manager (receiver) IP address</param>
        /// <param name="port">Manager (receiver) UDP port number</param>
        public static void SendTrap(SnmpPacket packet, IpAddress peer, int port)
        {
            TrapAgent agent = new TrapAgent();

            if (packet is SnmpV1TrapPacket)
            {
                agent.SendV1Trap((SnmpV1TrapPacket)packet, peer, port);
            }
            else if (packet is SnmpV2Packet)
            {
                agent.SendV2Trap((SnmpV2Packet)packet, peer, port);
            }
            else if (packet is SnmpV3Packet)
            {
                agent.SendV3Trap((SnmpV3Packet)packet, peer, port);
            }
            else
            {
                throw new SnmpException("Invalid SNMP packet type.");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Send SNMP Trap notification
 /// </summary>
 /// <remarks>
 /// Helper function to allow for seamless sending of SNMP notifications for all protocol versions.
 /// 
 /// packet parameter should be appropriately formatted SNMP notification in SnmpV1TrapPacket,
 /// SnmpV2Packet or SnmpV3Packet class cast as SnmpPacket class.
 /// 
 /// Function will determine which version of the notification is to be used by checking the type
 /// of the packet parameter and call appropriate TrapAgent member function to send it.
 /// </remarks>
 /// <param name="packet">SNMP trap packet</param>
 /// <param name="peer">Manager (receiver) IP address</param>
 /// <param name="port">Manager (receiver) UDP port number</param>
 public static void SendTrap(SnmpPacket packet, IpAddress peer, int port)
 {
     TrapAgent agent = new TrapAgent();
     if (packet is SnmpV1TrapPacket)
         agent.SendV1Trap((SnmpV1TrapPacket)packet, peer, port);
     else if (packet is SnmpV2Packet)
         agent.SendV2Trap((SnmpV2Packet)packet, peer, port);
     else if (packet is SnmpV3Packet)
         agent.SendV3Trap((SnmpV3Packet)packet, peer, port);
     else
         throw new SnmpException("Invalid SNMP packet type.");
 }