Contact Info

Crumbtrail

ActiveXperts.com » Network Component » Network Component Objects » SNMPTrap

ActiveXperts Network Component SnmpTrapManager Object

An SNMP trap is simply a notification message that is transmitted by an SNMP-managed device whenever it has something of interest to report. Traps can be thought of as event messages, similar to the events in the Windows event logs. Traps, like regular SNMP variables, are defined in MIB (Management Information Base) files. They are defined as a set of SNMP variables contained in (or referenced by) an OID (Object Identifier). If you look at the system directory on any Windows machine that has SNMP installed, you will find several MIB files. (They have the extension ".mib".) If you look through them you will see the variables that are supported on that machine. Network Component has interfaces for sending and receiving SNMP traps.

The SnmpTrapManager object provides properties and functions for sending and receiving SNMP traps. The SnmpTrap object provides enacapsulates all trap properties. It is used in onjunction with the SnmpTrapmanager object.

The Network Component SnmpTrapManager and SnmpTrap objects are compliant with SNMP v1 and SNMP v2c. Network Component automatically detects which SNMP version is running on the remote agent and adapts to it.

The Network Component trap objects supports different data types, including:

The Network Component trap objects feature the following:

Overview of all Network Component objects:

DnsServer & DnsRecord - Ftp & FtpFile - Http - Icmp - IPtoCountry - Msn - Ntp - Radius - Rsh - Scp - SFtp - Ssh - SnmpManager - SnmpTrapManager - SnmpMibBrowser - Tcp - Tftp - TraceRoute - Udp - Xen - Wake-on-LAN - Xen (Citrix)


SnmpTrapManager Sample code

Visual Basic .NET sample: Send SNMP traps

Imports AxNetwork

Module SendTrap
   Sub Main()

      Dim objManager As SnmpTrapManager
      Dim objTrap As SnmpTrap
      Dim objSnmpObject As SnmpObject
      Dim objConst As SocketConstants

      objManager    = New SnmpTrapManager
      objTrap       = New SnmpTrap
      objSnmpObject = New SnmpObject
      objConst      = New SocketConstants

      objManager.Initialize()

      objTrap.Host        = "server03"
      objTrap.Community   = "public"

      objSnmpObject.OID   = ".1.3.6.1.2.1.1.5.0"
      objSnmpObject.Type  = objConst.asSNMP_TYPE_IPADDRESS
      objSnmpObject.Value = "10.0.0.1"

      objTrap.AddObject(objSnmpObject)

      objManager.Send(objTrap)
      objManager.Shutdown()
    End Sub
End Module

Visual C# .NET: Receive SNMP traps

using System;
using AxNetwork;

namespace ReceiveTrap 
{
  class ReceiveTrap 
  {
    [STAThread]
    static void Main(string[] args) 
    {
      SnmpTrapManager  objManager = new SnmpTrapManager();
      SnmpTrap         objTrap;
      SnmpObject       objSnmpObject;

      objManager.Initialize();
      objManager.StartListening ( "public", 162 );
    
      while ( true ) 
      {
        objTrap = ( SnmpTrap ) objManager.GetFirstTrap();

        while( objManager.LastError == 0 ) 
        {
          objSnmpObject = ( SnmpObject ) objTrap.GetFirstObject ();
        
          while( objTrap.LastError == 0 ) 
          {
            Console.WriteLine( "OID   :" + objSnmpObject.OID );
            Console.WriteLine( "Value :" + objSnmpObject.Value );
            Console.WriteLine( "Type  :" + objSnmpObject.Type );
          
            objSnmpObject = ( SnmpObject ) objTrap.GetNextObject ();
          }
          
          objTrap = ( SnmpTrap ) objManager.GetNextTrap();
        }
        
        System.Threading.Thread.Sleep ( 1000 );
      }

      objManager.StopListening();       
      objManager.Shutdown();
    }
  }
}

You can download the full samples here.