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:
ActiveSocket SNMP traps features:
Download the ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
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.
To send an SNMP trap, we need to use three ActiveSocket objects.
We also need to know:
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 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.