Koozali.org: home of the SME Server

nut/UPS e-mail notifications

Offline judgej

  • *
  • 375
  • +0/-0
nut/UPS e-mail notifications
« on: July 08, 2006, 04:01:06 PM »
If anyone is interested in getting e-mail notifications on change of state of a UPS, then the steps I followed to get this working on my system are given below. There are other contribs that discuss how to set up nut (the UPS subsystem) and these instructions just concern the monitoring and reporting of nut.

1. Update the 'notify stub script'. This stub appears to be part-complete, so we will finish it off. Edit the file and copy the code content into it.

# vi /sbin/e-smith/nutUPS.notify

Code: [Select]
#! /bin/sh
# UPS notify script.

/bin/mail -s "UPS '$UPSNAME': $NOTIFYTYPE" admin <<END
$*
END


It should be noted that this script may get over-written in future SME versions. It is not templated, so I have no control over that. The fact that the current stub does not produce a message body, could be considered a bug. I have not raised anything in the bug tracker for this, and will leave it for others to decide.

2. Set up notification events. A custom template adds these into the upsmon.conf fie.

# mkdir -p /etc/e-smith/templates-custom/etc/ups/upsmon.conf
# vi /etc/e-smith/templates-custom/etc/ups/upsmon.conf/NOTIFYEVENTS

Code: [Select]
# Events to notify
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG LOWBATT SYSLOG+EXEC
NOTIFYFLAG COMMOK SYSLOG+EXEC
NOTIFYFLAG COMMBAD SYSLOG+EXEC
NOTIFYFLAG REPLBATT SYSLOG+EXEC
NOTIFYFLAG NOCOMM SYSLOG+EXEC


# expand-template /etc/ups/upsmon.conf

Each of these events will produce a system log line and an e-mail to the administrator. There are other events you may wish to catch - see the manual page for upsmon for the full list.

3. Restart the nut process:

# /sbin/e-smith/service nut restart

Now pull out the mains cable, disconnect the serial/USB cables, turn the UPS off (assuming that does not cut the power to your server) etc. and see what happens.

Hope that is of some help.

-- JJ
-- Jason

Offline MSmith

  • *
  • 675
  • +0/-0
nut/UPS e-mail notifications
« Reply #1 on: July 11, 2006, 07:15:54 AM »
Brilliant!  Thank you!
...

Offline judgej

  • *
  • 375
  • +0/-0
nut/UPS e-mail notifications
« Reply #2 on: July 11, 2006, 12:55:33 PM »
I've started a feature request for UPS monitoring. Feel free to add any further requirements:

http://bugs.contribs.org/show_bug.cgi?id=1722

If I manage to get any of the feature request stuff working locally, I'll post the updates there. It is good that 'nut' provides a consistent interface to such a wide variety of UPS makes and models. It should make a control panel pane easier to write - simple selections of the UPS model and monitoring port (serial, USB, network IP/port) should be enough to get most people going. Icing on the top would be regular dumping of the UPS stats, configuration of settings such as when and how to shut down, whether to automatically restart etc.

-- JJ
-- Jason