Download ActiveSocket Network Communications Toolkit 4.1  (7643 KB - .exe file)
Download Manual  (556 KB - .htm file)
ColdFusion SNMP Trap Sender Source Code
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols.
By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets, WOL (Wake-On-LAN), and more.
ActiveSocket SNMP traps can be well integrated into ColdFusion environments.
This document describes how ActiveSocket SNMP traps can be integrated into ColdFusion projects.
ActiveSocket is compliant with SNMP v1 and SNMP v2c.
Several SNMP data types are supported, including:
- String types (also called "octet strings");
- Integer types (16bit, 32bit, 64bit and unsigned integers);
- IP Address types;
- Timetick types;
- Counter types (32bit and 64bit counters);
- OID types (also called "Object ID's");
- Other, less frequently used datatypes.
ActiveSocket SNMP traps features:
- SNMP v1 and SNMP v2c support
;
- Support for aplphanumeric OID's (object identifier) and numeric OID's;
- Multi-threading architecture: send SNMP traps simultaneously from one process using multiple threads;
- Support for ports other than the default 161 and 162 ports;
- Support for enterprise specific traps;
- Support for SNMP v1 generic traps;
- Send multiple variables in a single SNMP TRAP message.
Step 1: Download and install the ActiveSocket Toolkit
Download the ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 1: Download and install the ActiveSocket Toolkit
Download ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 2: Create a new ColdFusion document
Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.
Step 3: Implementation
To send an SNMP trap, we need to use three ActiveSocket objects.
- An object that is managing SNMP.
- An object to store some trapdata.
- The ASConstants object, witch has some information stored.
We also need to know:
- The SNMP Version
- The host
- The community
- A value for the trap
- The type of the trap
You can use a form that looks like this:

(Click on the picture to enlarge)
To add those objects in your script, add the following code:
<!--- Setting the objects --->
<cfobject class="ActiveXperts.SnmpTrapData" type="com" name="objTrapData" Action="Create">
<cfobject class="ActiveXperts.SnmpTrapManager" type="com" name="objTrapManager" Action="Create">
<cfobject class="ActiveXperts.ASConstants" type="com" name="objConstants" Action="Create">
<cfobject class="ActiveXperts.SnmpTrapVariable" type="com" name="objTrapVariable" Action="Create">
Just like the SNMP sample, we're going to configure the logfile first.
<--- Set the logfile --->
<cfset objTrapManager.Logfile = "C:\logfile.txt" >
To send the trap we need to configure some options first.
- Configure the settings
- Add a trap
- Send the trap
Configure the protocol version and then initialize the device. Use the following code:
<!--- Setting the protocolversion --->
<cfscript>
if(objTrapManager.LastError eq 0){
intVersion = 2;
if(IsDefined("URL.version")){
objTrapManager.ProtocolVersion = URL.version;
intVersion = URL.version;
}
}
</cfscript<
<!--- Initializing --->
<cfif objTrapManager.LastError eq 0>
<cfset objTrapManager.Initialize()>
</cfif>
Now we're going to create the trap. When creating a trap, you must fill in the datatype and the value:
<!--- Setting the datatype --->
<cfscript>
if(objTrapManager.LastError eq 0){
if(IsDefined("URL.datatype")){
strDatatype = "string";
switch(URL.datatype){
case "string":
objTrapVariable.Type = objConstants.asSNMP_TYPE_OCTETSTRING;
strDatatype = "string";
break;
case "number":
objTrapVariable.Type = objConstants.asSNMP_TYPE_INTEGER;
strDatatype = "number";
break;
}
}
}
</cfscript>
<!--- Setting the Value --->
<cfscript>
if(objTrapManager.LastError eq 0){
strValue = "Hello world!";
if(IsDefined("URL.value")){
objTrapVariable.Value = URL.value;
strValue = URL.value;
}
}
</cfscript>>
You can add as much variables to the trap as you wish. Once a trap is created, you need to add and send it:
<!--- Adding the value to the trap and sending it --->
<cfscript>
if(objTrapManager.LastError eq 0){
objTrapData.Host = URL.host;
objTrapData.Community = URL.community;
objTrapData.AddVariable ( objTrapVariable );
objTrapManager.Sleep(200);
objTrapManager.Send(objTrapData);
}
</cfscript>
And last but not least, display the results:
<!--- Echo the results --->
<cfscript>
intErrorNo = objTrapManager.LastError;
strErrorDescr = objTrapManager.GetErrorDescription(objTrapManager.LastError);
</cfscript>
There are many working samples included with the product.
You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.
The ActiveSocket tool is a Network Communications ActiveX software component (SDK).
This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform,
including Visual Basic .NET, Visual CSharp .NET,
ASP .NET (VB,CS),
ASP,
Visual Basic,
Visual Studio/Visual C++,
Delphi,
PHP,
ColdFusion,
HTML,
VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.
|