[Nut-upsuser] timers and their usage

Steven Schoch schoch at spamcop.net
Wed Sep 14 17:09:10 UTC 2005


Mike Pepe wrote:
> That sounds similar to what I'd like to do. Perhaps I could take a peek 
> at your config for that scenario?

First, here's how NuT works:

- The UPS driver talks to the UPS and communicates with upsd.
- upsmon talks to upsd.
- When a UPS event happens, the UPS sends the event to the driver, which 
sends it to upsd, which sends it to upsmon.  (Actually, it may not send 
the events, but it may poll instead.  I'm not sure.) Upsmon looks at 
upsmon.conf to figure out what to do with the event notification.  Among 
other things, upsmon can shut the system down, syslog(3) the event, 
wall(1) it to all users, or exec a program.

Upsmon does not implement delays itself.  Instead it uses upssched, 
which has it's own config file.

Here's how I have it set on my machine:  upsmon.conf includes these lines:

NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC

In my case I don't care if it sends those brief power interrupted 
messages to all users, since few people actually log into the machine 
anyway (most use it as a Intranet, email, and file server).  However, I 
also want to get paged when the power goes out for an extended period of 
time (20 seconds).  To do that, I also have this line in upsmon.conf:

NOTIFYCMD /usr/local/ups/sbin/upssched

This tells upsmon to call upssched when any of those events (online, 
onbatt, lowbatt, commok, commbad) happen.

My upssched.conf file has these lines:

CMDSCRIPT /usr/local/ups/bin/upssched-cmd

AT ONBATT * START-TIMER onbatt 20
AT ONLINE * CANCEL-TIMER onbatt online

AT LOWBATT * START-TIMER lowbatt 1

AT COMMBAD * START-TIMER commbad 10
AT COMMOK * CANCEL-TIMER commbad commok


When upssched gets an ONBATT event from upsmon it will start the 
"onbatt" timer.  If it gets an ONLINE (power restore) event while the 
onbatt timer is still running, it will cancel that timer and do nothing 
else.  If, however, the onbatt timer is not running, then it must have 
already sent the "on battery" page, so it sends the "online" argument to 
  the script.  This makes sure I get the "power restored" page only if 
the power had been previously off for more than 20 seconds.

After the onbatt timer has run for 20 seconds, it will call the 
CMDSCRIPT with "onbatt" as an argument.  The upssched-cmd script 
contains this:

#! /bin/sh
case $1 in
         onbatt)
                 /usr/lib/sendmail -i -f off at power.example.com 
power-page << EOF
To: power-page
From: off at power.example.com

Power failed at `date '+%D %k:%M'`
EOF
;;
         online)
                 /usr/lib/sendmail -i -f on at power.example.com power-page 
<< EOF
To: power-page
From: on at power.example.com

Power was restored at `date '+%D %k:%M'`
EOF
;;


power-page is an alias for my cell phone's email address 
(<number>@vtext.com).  My phone can have different "ring tones" for 
different senders, so my plan was to have tones that would sound like 
the power turning off and on.

-- 
Steve




More information about the Nut-upsuser mailing list