You are here:
ActiveXperts.com > ActiveSocket > How to Use ActiveSocket > SNMP Trap Sender > ASP 2.x
Quicklinks
ActiveSocket provides an easy-to-use development interface (SDK) to a variety of IP protocols. By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.
ActiveSocket is compliant with SNMP versions v1 and v2c. Several SNMP data types are supported, including:
ActiveSocket supports the following SNMP trap features:
ActiveSocket can be well integrated into ASP environments. This document describes how ActiveSocket can be integrated into ASP projects.
IMPORTANT: Make sure that the SNMP Service is installed and running on the machine where ActiveSocket is installed. For more details, please read FAQ items Q1200010 and Q1200015.
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on. From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':
(Click on the picture to enlarge)
The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:
You're now able to write an ASP script to use IP protocols with ActiveSocket.
To receive SNMP traps using ASP, you need to declare and create the following ActiveSocket objects:
Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. On top of the ASP code, insert the following lines to declare and create the ActiveSocket objects:
<object runat=server progid="ActiveXperts.SnmpTrapManager" id=objSnmpTrapManager></object> <object runat=server progid="ActiveXperts.SnmpTrap" id=objSnmpTrap ></object> <object runat=server progid="ActiveXperts.SnmpObject" id=objSnmpObject ></object>
Now that we have created the objects objTrapManager, objSnmpTrap and objSnmpObject we're able to send a trap. We need to collect the following information from the user:
Please find the ASP code for sending a SNMP trap below:
<%
' Create the objects
Set objSnmpTrap = Server.CreateObject( "ActiveXperts.SnmpTrap" )
Set objSnmpObject = Server.CreateObject( "ActiveXperts.SnmpObject" )
Set objConstants = Server.CreateObject( "ActiveXperts.ASConstants" )
Set objSnmpTrapManager = Server.CreateObject( "ActiveXperts.SnmpTrapManager" )
objSnmpTrap.Clear
objSnmpObject.Clear
' Set the logfile
objSnmpTrapManager.Logfile = request("logfile")
' Initialize the SNMP Trap manager
objSnmpTrapManager.Initialize
'Set the protocol version
objSnmpTrapManager.ProtocolVersion = request("version")
' Set the SNMP data to send with the trap (variable bindings)
objSnmpObject.OID = request("oid")
objSnmpObject.Value = request("value")
select case request("oidDataType")
case "number"
objSnmpObject.Type = objConstants.asSNMP_TYPE_INTEGER32
case "text"
objSnmpObject.Type = objConstants.asSNMP_TYPE_OCTETSTRING
end select
' Set the SNMP Trap destination and community, and add the data
objSnmpTrap.Host = request ( "host" )
objSnmpTrap.Community = request ( "community" )
objSnmpTrap.AddObject objSnmpObject
'Send the trap
objSnmpTrapManager.Send objSnmpTrap
' Display the result
strResult = objSnmpTrapManager.LastError & " : " & objSnmpTrapManager.GetErrorDescription(objSnmpTrapManager.LastError)
objSnmpTrapManager.Shutdown
%>
You can download the complete sample from our ftp site ftp.activexperts-labs.com/samples/network-component. There are many other working ActiveSocket scripts on our site and shipped with the product.