Quicklinks
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: 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.
SNMP can be well integrated into ColdFusion environments. This document describes how ActiveSocket's SNMP objects can be integrated into ColdFusion code.
ActiveSocket is compliant with SNMP v1 and SNMP v2c. Different SNMP data types are supported, including:
The following operations are supported:
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.
For the usage of SNMP in ColdFusion, we're going to work with objects. Sending an OID to a server is quit simple. It can be done in four simple steps.
Attention: Before using this sample, make sure you've configured SNMP properly.
Once the object is created the rest is easy. To make the ActiveSocket object in ColdFusion you need the following code snippet:
<cfobject class="ActiveXperts.SnmpManager" type="com" name="objSnmp" Action="Create">
Trough this tag you are able to communicate trough the ActiveSocket toolkit. The program has a certain amount of options witch are to be found in the products manual that is shipped with it. In our sample just a few of them are used. You can call to a function of the object using a “.”.
We're also going to need a form that collects the required information to send an OID. We've made a form that looks like this:
(Click on the picture to enlarge)
Once the form is ready the first thing we're configuring is the “logfile” option. You can fill in the path and filename for the logfile. Trough this file you’re able to check what goes on during the execution of the script you are writing. Use the following code to configure the logfile:
<cfset objSnmpManager.LogFile = “C:\temp\logfile.txt”>
First of all we're going to initialise SNMP. Using "Initialize()":
<cfset objSnmpManager.Initialize()>
Then we're moving on to setting the protocol version. We're doing this with the "version" property of the object we have created. Versions can differ between version one and two.
<cfset objSnmpManager.Version = URL.Version >
If all of this is succesfully configured, we're able to open a connection to a host. We're able to do that using the "Open()" command. We need to fill in the host, the community and the portnumber.
<cfset objSnmpManager.Open("localhost", "public", 161) >
You're able to get an OID using the property "Get("someOid")". This makes the entire sourcecode to send an OID look like this:
function snmpget(getnext, OID){
objSnmpManager.LogFile = strLogFile;
objSnmpManager.Initialize();
objSnmpManager.ProtocolVersion = strVersion;
if(objSnmpManager.LastError eq 0){
objSnmpManager.Open(strHost,strCommunity,strPort);
}
if(objSnmpManager.LastError eq 0){
objSnmpData = objSnmpManager.get(OID);
if (getnext eq "getnext") {
objSnmpData = objSnmpManager.getnext();
}
}
if(objSnmpManager.LastError eq 0){
strOid = objSnmpData.oid;
strValue = objSnmpData.value & "<br>";
}
strResult = objSnmpManager.LastError & " : " & objSnmpManager.GetErrorDescription(objSnmpManager.LastError);
objSnmpManager.Close();
objSnmpManager.Shutdown();
}
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/network-component.