Liebert UPS Testing Revision 1

Technical chat for the techies and development testers
Post Reply
Posts: 1
Joined: Mon Jun 04, 2012 1:30 pm

Liebert UPS Testing Revision 1

Post by steveballantyne » Sun Jun 10, 2012 8:52 pm

Hello all,

I have been through several network monitoring packages and most of them are pretty terrible. I was happy to have discovered FreeNATS which was not overly complicated, and yet still provided the simple monitoring features that everybody needs (as in is it up or not?).

A few years ago I started buying up Emerson Liebert UPS systems to replace our mix of APC and Tripp Lite models. Liebert sells a web card option which provides you with SNMP monitoring and limited management. I am just now getting around to monitoring these units and I needed something very simple to do it with. And that is where this test comes from.

This is a "first effort" from a non-programmer. So if you spot some sloppy code and have some ideas on how to improve this script, please share your thoughts! Hopefully there is someone else out there monitoring Liebert UPS's and using FreeNATS who can make use of this.

This test provides you with a battery status (good, or needs replaced), time left on battery (you hope it's zero, otherwise you are running on battery), and temperature (how hot in Fahrenheit degrees). The temperature has been the most useful reading to me, because it tells me which of my wiring closets are running too hot and will kill my batteries prematurely.

Thanks to Dave (the admin and creator of FreeNATS) I was about to get hints on how I could also display the model number and serial number on the testing screen. This should be useful if you need to call into support for battery replacement, etc.

And now, the code:

Code: Select all

<?php // -- Liebert UPS Module 

// This is to pull info from a Liebert UPS with a web card
// installed to it.  As you can tell, it's a customization
// made upon the included with FreeNATS.
// -Steve Ballantyne 6/3/2012

/* -------------------------------------------------------------
This file is part of FreeNATS

FreeNATS is (C) Copyright 2008 PurplePixie Systems

FreeNATS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FreeNATS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FreeNATS.  If not, see

For more information see
-------------------------------------------------------------- */

if (isset($NATS))
class FreeNATS_LiebertUPS_Test extends FreeNATS_Local_Test
	function DoTest($testname,$param,$hostname,$timeout,$params)
		global $NATS;
		if ($timeout<=0) $timeout=$NATS->Cfg->Get("test.liebertups.timeout",0); // if no test-specific param use sys default
		if ($timeout<=0) $timeout=60; // if sys default is <=0 then default to 60 seconds
		if ($ip=="0") return -2; // lookup failed
		$ups_snmp = @snmpget($ip, $params[1], $params[0]);
		$snmp_value = preg_split('/[\s:]+/', $ups_snmp, -1, PREG_SPLIT_NO_EMPTY);
// Check to see if this data needs converted into an Integer or not.
		if (is_numeric($snmp_value[1])) {
			// This is an integer
			$snmp_value_int = (int)$snmp_value[1];
			return $snmp_value_int;
		else {
			// This is NOT an integer
			return $snmp_value[1]; 
	function Evaluate($result) 
		if ($result<0) return 2; // failure
		return 0; // else success
	function DisplayForm(&$row)
		global $NATS;
// Try to offer up goodies like the serial number and model number of this unit.
		echo "<strong>INFO COLLECTED FROM THIS UNIT</strong><br>";
		echo "<i>These values may be unknwon until you fill in your community password, save this test, and return to this screen.</i><br>";
		echo "<strong>Hostname : </strong>".$data['hostname']."<br>";
		echo "<strong>IP is : </strong>$ip<br>";
// We will not try to run SNMP queries if there is no community password set
		if ($row['testparam1']!="" || $row['testparam1']!=NULL) {
			$upsmodel_snmp = @snmpget($ip, $row['testparam1'], "");
                	$upsmodel_value = preg_split('/[\s:]+/', $upsmodel_snmp, -1, PREG_SPLIT_NO_EMPTY);
			$upsserial_snmp = @snmpget($ip, $row['testparam1'], "");
                	$upsserial_value = preg_split('/[\s:]+/', $upsserial_snmp, -1, PREG_SPLIT_NO_EMPTY);
		else {
		echo "<strong>Model Number</strong>: $upsmodel_value[1]<br>\n";
		echo "<strong>Serial Number</strong>: $upsserial_value[1]<br><hr>\n";
		echo "<table border=0>";
		echo "<tr><td align=left>";
		echo "<strong>Choose an SNMP OID :</strong>";
                echo "<tr><td align=left>";
// Determine what to set the dropdown box default to ... is this a saved test we are revising or viewing? - 
		if ($option=="") 
		elseif ($option=="")
		elseif ($option=="")
		echo "<center><select name=testparam style=\"background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: none; font-size: 12; width: 375px;\">";
		if ($selected==1) 
                	echo "<option value=\"\" selected=\"selected\">Temperature in Fahrenheit (</option>";
			echo "<option value=\"\">Temperature in Fahrenheit (</option>";
		if ($selected==2)
			echo "<option value=\"\" selected=\"selected\">Battery Status (2=okay 3=low 4=depleted) (</option>"; 
               		echo "<option value=\"\">Battery Status (2=okay 3=low 4=depleted) (</option>";
		if ($selected==3)
			echo "<option value=\"\" selected=\"selected\">Seconds on Battery (0=not on battery) (</option>";
			echo "<option value=\"\">Seconds on Battery (0=not on battery) (</option>";	
// Some older units do NOT report seconds left, but DO report a time remaining value
		echo "<option value=\"\">BatteryTimeRemaining (</option>";
                echo "</select><br /><br />";
		echo "<tr><td align=left>";	
		echo "<strong>Community Password :</strong>";
		echo "<br><i>Usually this is the word public</i>";
                echo "</td></tr>";
		echo "</td><td align=left>";
                echo "<tr><td align=left>";
                echo "<input type=text name=testparam1 size=30 maxlength=255 value=\"".$row['testparam1']."\">";
		echo "</td></tr>";
		echo "</table>";
$NATS->Tests->Register("liebertups","FreeNATS_LiebertUPS_Test",$params,"Liebert UPS Testing",1,"Liebert UPS SNMP Testing");

To use the above code, just copy and paste it into a new file called "" and save it into your server/base/tests directory in your FreeNATS directory structure.


Post Reply