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. ActiveSocket 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 ActiveSocket SnmpTrapManager and SnmpTrap objects are compliant with SNMP v1 and SNMP v2c. ActiveSocket automatically detects which SNMP version is running on the remote agent and adapts to it.
The ActiveSocket trap objects supports different data types, including:
The ActiveSocket trap objects feature the following:
Overview of all ActiveSocket objects:
Imports ASOCKETLib
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 ASOCKETLib;
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 ActiveSocket samples. These samples are also part of the ActiveSocket installation.
Visit ftp.activexperts-labs.com »