Fixing USP Nut 0.8.6 for Cacti 1.2.2

Eric A. Hall wrote a nice monitoring package for Cacti in PHP and XML.

Originally you copied one script and two xml files into place and then configured Cacti to enable the monitoring script and import the XML template for the Data graphs. But these were written for Cacti 0.8.6 or 0.8.7

The default install for Cacti for Raspberry Pi is version 1.2.2 and the monitoring package fails to work as described for the newer version of Cacti.

Here is how to get it working.

First connect the UPS to the raspberry pi using a USB cable

Second setup the NUT monitoring demon on the raspberry pi, as standalone and as the master monitoring daemon for the UPS.

This has been tested with my example:

CyberPower CP1500PFCLCD

get cacti-nut.0.5.tar.gz and unpack

edit  # vi nut_ups_status.xml
add the second line below to the file, use the first line below as a locator to find the right place to put the second line in the file


edit  # vi ss_nut_ups_status.php
remove the first line from the file
add the following lines to the top of the file

#!/bin/php -q


include_once(dirname(__FILE__) . '/../include/cli_check.php');

[You can test this script modification from the command line.]

# php ss_nut_ups_status.php localhost:: query ups.description

It should return:

php ss_nut_ups_status.php localhost:: query ups.description
cyberpower1:CyberPower CP1500PFCLCD
Third install the script and the two xml files to the <cacti_path> = /usr/share/cacti/site/

move the ss_nut_ups_status.php script into its home directory /usr/share/cacti/site/scripts
move the nut_ups_status.xml file into its home directory /usr/share/cacti/site/resource/script_server/
import the template nut_ups_status_data_query.xml from it current location using the cacti Template  Import wizard to navigate the file system and import the nut_ups_status.xml file

Everything else works as previously described by Eric Hall.

Basically it works by executing a PHP script to open a TCP socket connection to the upsd monitoring daemon. You can do this too by installing telnet and then using it to connect to the upsd daemon like this:

telnet localhost 3493
Trying ::1...
Connected to localhost.
Escape character is '^]'.

Network UPS Tools upsd 2.7.4 - http://www.networkupstools.org/
list ups
UPS cyberpower1 "CyberPower CP1500PFCLCD"

The "magic" of this monitoring package however is it quickly sets up a data source and graphing templates within cacti and instructs cacti how to interpret and graph the data in cacti terms with very little user input.

Previous error messages I received while figuring this out were:

# php ss_nut_ups_status.php

PHP Notice:  Undefined index: REQUEST_URI in /usr/share/cacti/site/include/global.php on line 425

This is a LOW LEVEL "notification" all it means is that the line (indicated '425') in the global.php file tested for an environment variable that was not set, it is "in fact" never set for any php script execucted from the command line and can be safely ignored.

The following line added to the top of the #ss_nut_ups_status.php script basically "turns" that distracting notification "off".. otherwise even when it was working properly the notification would continuously show up.


And when trying to add the Data query type to the [Device] for the local raspberry pi acting as the UPS monitoring server.. the query type was not "actived" (By DEFAULT no new data query just added or created is activated. Its a separate step to turn it on.) This has to be done on the Data Query page for the UPS Nut configuration page. The Rpi (Node) can't use the Query type until its "activated".

And when Importing the Template there is a (New) feature in Cacti 1.2.2 that (auto-enables) a feature called ('Preview') which "fakes" you out by making you think it has imported the Template.. but look very closely and in small, tiny print, it says.. "This is what it would have done if Preview was not enabled !!!" You have to slide or de-checkify (depends on the Console 'Theme' and Browser type which kind of de-checkify you have to do.. to turn-preview-off !!!)

If you don't already have the Data Query "activated" on it config page, when you try to Import the Template.. many things will "Fail".. activate the Data query "first" and then try Importing again.. 

It will Import 100 percent correct and nothing fails.

After adding the Data Query to the Device as an [Associated Data Queries] entry, it enables a realtime Debug tool called ['Actions'] over to the right for the Data Query line for [Nut - UPS Statistics]

They appear as a "refresh" green circular chasing arrows icon, and a "verbose" yellow circular chasing arrows icon. And a "remove query" red ex.

Clicking on the "yellow" will run run a query and popup the results above the [Associated Data Queries] (section) .. if it says something about "XML and Unsupported" that means the [mandatory] ss_script line in the XML file is missing:

edit  # vi nut_ups_status.xml
add the second line below the first line to the file, use the first line only as a guide to where ot place the second line in the file