02.12.2015 Views

Network UPS Tools User Manual

Network UPS Tools User Manual

Network UPS Tools User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Network</strong> <strong>UPS</strong> <strong>Tools</strong> <strong>User</strong> <strong>Manual</strong> 34 / 84<br />

Establishing timers<br />

Let’s say that you want to receive a page when any <strong>UPS</strong> has been running on battery for 30 seconds. Create a handler that starts<br />

a 30 second timer for an ONBATT condition.<br />

AT ONBATT * START-TIMER onbattwarn 30<br />

This means "when any <strong>UPS</strong> (the *) goes on battery, start a timer called onbattwarn that will trigger in 30 seconds". We’ll come<br />

back to the onbattwarn part in a moment. Right now we need to make sure that we don’t trigger that timer if the <strong>UPS</strong> happens to<br />

come back before the time is up. In essence, if it goes back on line, we need to cancel it. So, let’s tell upssched that.<br />

AT ONLINE * CANCEL-TIMER onbattwarn<br />

Executing commands immediately<br />

As an example, consider the scenario where a <strong>UPS</strong> goes onto battery power. However, the users are not informed until 60 seconds<br />

later - using a timer as described above. Whilst this may let the logged in users know that the <strong>UPS</strong> is on battery power, it does not<br />

inform any users subsequently logging in. To enable this we could, at the same time, create a file which is read and displayed to<br />

any user trying to login whilst the <strong>UPS</strong> is on battery power. If the <strong>UPS</strong> comes back onto utility power within 60 seconds, then we<br />

can cancel the timer and remove the file, as described above. However, if the <strong>UPS</strong> comes back onto utility power say 5 minutes<br />

later then we do not want to use any timers but we still want to remove the file. To do this we could use:<br />

AT ONLINE * EXECUTE ups-back-on-power<br />

This means that when upsmon detects that the <strong>UPS</strong> is back on utility power it will signal upssched. Upssched will see the above<br />

command and simply pass ups-back-on-power as an argument directly to CMDSCRIPT. This occurs immediately, there are no<br />

timers involved.<br />

7.2.3 Writing the command script handler<br />

OK, now that upssched knows how the timers are supposed to work, let’s give it something to do when one actually triggers. The<br />

name of the example timer is onbattwarn, so that’s the argument that will be passed into your CMDSCRIPT when it triggers.<br />

This means we need to do some shell script writing to deal with that input.<br />

#! /bin/sh<br />

case $1 in<br />

onbattwarn)<br />

echo "The <strong>UPS</strong> has been on battery for awhile" \<br />

| mail -s"<strong>UPS</strong> monitor" bofh@pager.example.com<br />

;;<br />

ups-back-on-power)<br />

/bin/rm -f /some/path/ups-on-battery<br />

;;<br />

*)<br />

logger -t upssched-cmd "Unrecognized command: $1"<br />

;;<br />

esac<br />

This is a very simple script example, but it shows how you can test for the presence of a given trigger. With multiple ATs creating<br />

various timer names, you will need to test for each possibility and handle it according to your desires.<br />

Note<br />

You can invoke just about anything from inside the CMDSCRIPT. It doesn’t need to be a shell script, either - that’s just an<br />

example. If you want to write a program that will parse argv[1] and deal with the possibilities, that will work too.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!