|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS Hot Stories Using ColdFusion For Network Monitoring
Find the exact piece of data you need
Oct. 13, 2004 12:00 AM
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. CFX_SNMP Use of the tag is as follows: <cfx_snmp host="router.host.com" community="public" oid="1.3.6.1.2.1.2.2.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 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[6]#. 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 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. CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||