Network UPS Tools User Manual
Network UPS Tools User Manual
Network UPS Tools User Manual
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> 32 / 84<br />
7.1 The simple approach, using your own script<br />
7.1.1 How it works relative to upsmon<br />
Your command will be called with the full text of the message as one argument.<br />
For the default values, refer to the sample upsmon.conf file.<br />
The environment string NOTIFYTYPE will contain the type string of whatever caused this event to happen - ONLINE, ONBATT,<br />
LOWBATT, . . .<br />
Making this some sort of shell script might be a good idea, but the helper can be in any programming or scripting language.<br />
Note<br />
Remember that your helper must be executable. If you are using a script, make sure the execution flags are set.<br />
For more information, refer to upsmon(8) and upsmon.conf(5) manual pages.<br />
7.1.2 Setting up everything<br />
• Set EXEC flags on various things in upsmon.conf(5):<br />
NOTIFYFLAG ONBATT EXEC<br />
NOTIFYFLAG ONLINE EXEC<br />
If you want other things like WALL or SYSLOG to happen, just add them:<br />
NOTIFYFLAG ONBATT EXEC+WALL+SYSLOG<br />
You get the idea.<br />
• Tell upsmon where your script is<br />
NOTIFYCMD /path/to/my/script<br />
• Make a simple script like this at that location:<br />
#! /bin/bash<br />
echo "$*" | sendmail -F"ups@mybox" bofh@pager.example.com<br />
• Restart upsmon, pull the plug, and see what happens.<br />
That approach is bare-bones, but you should get the text content of the alert in the body of the message, since upsmon passes the<br />
alert text (from NOTIFYMSG) as an argument.<br />
7.1.3 Using more advanced features<br />
Your helper script will be run with a few environment variables set.<br />
• <strong>UPS</strong>NAME: the name of the system that generated the change.<br />
This will be one of your identifiers from the MONITOR lines in upsmon.conf.<br />
• NOTIFYTYPE: this will be ONLINE, ONBATT, or whatever event took place which made upsmon call your script.<br />
You can use these to do different things based on which system has changed state. You could have it only send pages for an<br />
important system while totally ignoring a known trouble spot, for example.