Quicklinks
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)
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
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();
}
}
}
On ftp.activexperts-labs.com, you can find a lot of Network Component samples. These samples are also part of the Network Component installation.
Visit ftp.activexperts-labs.com »