|By Matthew Fusfield, Ryan Emerle||
|October 13, 2004 12:00 AM EDT||
One of the best features of ColdFusion is its versatility. Very few other languages or environments offer the cross-platform, open framework for development that the ColdFusion platform provides.
As CF developers, we have implemented countless Web-based workflow and content management style applications. As an Internet service and hosting provider, however, we used a number of different technologies to monitor and manage our network. While a huge number of commercial and free software packages exist for managing various parts of a network, our employer lacked a single platform for managing corporate information and our network. Fortunately, we use ColdFusion so we're familiar with its extensibility and could take advantage of that to meet our need.
One of the key technologies used in monitoring our network was SNMP, the Simple Network Management Protocol. While the term "simple" may be relative, SNMP is an accepted standard for monitoring and managing network devices. Servers, routers, switches, UPSs, environment sensors, and nearly any other kind of network-connected device can often "speak" SNMP to communicate information about their operation and status.
SNMP works by sending messages, called protocol data units (PDUs), to different parts of a network. SNMP-compliant devices, called agents, store data about themselves in Management Information Bases (MIBs) and return this data to the SNMP requesters.
A popular application among network administrators is MRTG. MRTG is an open source application that generates useful graphs of LAN and WAN utilization. Simply put, MRTG reads information from a router via SNMP, processes it, and generates a graph of the information that the router reports about bandwidth utilization. This is just one example of what SNMP can be used for. Because of SNMP, MRTG can work with devices from multiple vendors and even graph information from two different types of routers side by side.
This summary of SNMP is fairly simple, but is enough to give you the basic idea of what it can do.
For ColdFusion developers without CFQUERY, ODBC (or JDBC more recently) would be much more difficult to implement. Unfortunately, ColdFusion does not have a similar tag for communicating via SNMP. This was corrected with the development of the CFX_SNMP, which is available for purchase and download at www.insapi.com/. CFX_SNMP allows ColdFusion applications to retrieve data from network devices through the use of SNMP, and is written in Java for cross-platform compatibility.
Use of the tag is as follows:
<cfx_snmp host="router.host.com" community="public" oid="188.8.131.52.184.108.40.206.1.2" r_qResults="results">The HOST attribute simply specifies the host name or IP address to connect to. This can be a router, a server, network switch, or any other piece of SNMP-enabled network equipment. The COMMUNITY attribute specifies the SNMP community string to use, which is similar to a password for accessing the SNMP device. Next, the OID (object id) attribute is a numeric identifier. The object ID selects the specific piece of information to be retrieved. SNMP organizes objects in a tree fashion, similar to a file system, which can be "walked". The example above indicates that we should first select object 1, then the third subobject, then the sixth subobject, and so on, until we retrieve the specific data needed. Finally, the R_QRESULTS attribute specifies the name of the query to return data. This query can be accessed as any other ColdFusion query, using Query-of-Query, CFOUTPUT, or CFLOOP.
The result set will have four columns: the OID, the data type, a hexadecimal representation of the data, and a string representation of the data.
There are a few other useful features of the tag. If you specify an OID that contains multiple values ("subobjects"), the resulting query will contain rows for each. Further, the OID attribute of the tag will accept a comma-separated list of OIDs, and will return the values of each in a separate row of the query.
Example Application - UPS Power Monitoring
One problem we've experienced in our data center is monitoring the status of the power equipment. Each rack has at least one APC UPS battery backup unit, as well as an APC MasterSwitch for remote control of power. While each has an easy-to-use Web and text Telnet interface, in an outage, opening multiple browser windows to track your power utilization is not very efficient. For this reason, we used the CFX_SNMP to create a power "dashboard" application that displays the status of each UPS and MasterSwitch. This allows a network operator to determine how much runtime is available during a power failure, the load placed on each UPS, and even the internal temperature of each UPS.
The ups.cfm script (see Listing 1) has a number of declarations used throughout. First, a variable called COMMUNITY is set to the community string used. While there is no requirement that all network devices share a community string, management is made easier if all devices share a common community string. A struct called UPS contains named keys for each OID that will be referenced later. The sample script assumes that there are multiple UPSs being monitored, named in DNS as ups1, ups2, and ups3. This can be changed by altering the list in the first CFLOOP tag.
For each UPS looped over, the CFX_SNMP tag executes with the seven OIDs passed and returns a query called STATS. This query has seven rows, one for each OID in the same order as passed to CFX_SNMP (row 1 has the first OID, row 2 has the second OID, and so on). Each row contains OID, Hex, Type, and Value columns. The value column is the most important, as it contains the values that we will need to process and output. OID is the object ID being returned, and Type is a string representing the datatype of the data in the value column. Finally, the hex column is the hexadecimal value returned by the network device. You can add a <CFDUMP VAR="#stats#"> tag to see the full output of the tag.
The script outputs a table for each UPS (see Figure 1), with column headers for runtime, status, temperature, battery status, power load, and input voltage. Part of the title for each table is the UPS name and model number. Since we specified the OID for model number six in our OID list for CFX_SNMP, the sixth row of the query will contain the string representation of the UPS model number. This value is accessible as #stats.value#.
The script then outputs each row of the query. The first OID in the list is the runtime remaining of the UPS. This is the maximum amount of time before the batteries will run out if utility power is cut. The UPS expresses this in "timeticks" (100th of 1 second), which we convert to minutes using the Evaluate() function. The next OID is the UPS system status, which indicates if the system is running on utility power, battery, or some other specific condition (such as a low-voltage boost). The UPS returns this represented as a number, so we use a CFSWITCH to select the appropriate, operator-friendly text to display. Third is the UPS operating temperature. This is returned in Celsius and has been converted to Fahrenheit scale in this script for display using the Evaluate() function. We have also added some conditional logic to select the color of the display; if the UPS temperature begins to reach the maximum operating temperature, the display turns yellow, and then red once it exceeds the recommended maximums. The next OID is a simple binary value of whether the UPS battery needs to be replaced. Again, some logic has been added to change the color so an operator can know at a glance if there's a problem. The fifth row in the query contains information about the percentage load on the UPS. As in the other rows, some conditional logic has been added for display purposes. Finally, we output row 7 of the query, which is the input line voltage to the UPS. This is often useful if a backup generator powers the UPS.
Putting It All Together
This is a very simple example of using SNMP from within ColdFusion. Since the CFX_SNMP tag returns a standard ColdFusion query object, anything that you can do with a query, you can do with SNMP data. SNMP devices could easily be SOAP-enabled by writing a few CFCs with the appropriate calls to CFX_SNMP. The tag could easily be used with a database for logging historical information. This data can then be summarized or graphed with CFCHART to produce network status or outage reports.
The most difficult part for most ColdFusion developers will be determining the OIDs with the data needed. The OIDs in this example are for APC UPSs, but what if you want to monitor router usage or server disk space? SNMP will allow you to do this, but figuring out the correct OIDs to query is often a challenge. For this reason, a number of utilities exist that allow you to traverse, or "walk" the SNMP tree to find the exact piece of data you need.
Getif (www.wtcs.org/snmp4tpc/getif.htm) is one such freeware utility for Windows. Using Getif and a large MIB library (also available on the same site) you can easily browse for a particular value on nearly any kind of network equipment. Once you have found the needed OID, simply copy it into your CFML code and use the live data however needed.
ColdFusion is a great environment for creating business applications; integrating it with common hosting and networking systems can give organizations a unified look into their operations. In addition to databases, LDAP directories, mail servers, and FTP servers, ColdFusion can now access the wide array of network information via SNMP.
- Where Are RIA Technologies Headed in 2008?
- The Next Programming Models, RIAs and Composite Applications
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Constructing an Application with Flash Forms from the Ground Up
- Building a Zip Code Proximity Search with ColdFusion
- Personal Branding Checklist
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Has the Technology Bounceback Begun?
- Adobe Flex 2: Advanced DataGrid
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- Web Services Using ColdFusion and Apache CXF
- Passing Parameters to Flex That Works