Garrett Michael Hayes
2017-Oct-31 15:09 UTC
[Nut-upsuser] Email Alerts for Multiple UPSs with upssched
Greetings Gentlebeings, I have started deploying a number of NUT instances on Raspberry Pi machines (Raspbian Jessie) across my network. The purpose of these "nutcases" as we refer to them is to monitor the status of the UPSs supporting our network switching infrastructure and notify us of power and battery events via email. No shutdown or other actions are required. Everything is going spiffy as all get-out so far. But now I'm running up against a configuration issue I don't quite know how to address. Thus far each "nutcase" has been configured to monitor a single UPS. Now I want to deploy one to monitor three UPSs in a larger switch closet. Adding the additional UPSs to ups.conf and upsmon.conf is fairly straightforward. But I'm darned if I can figure out how to configure the email alerts to let me know WHICH UPS is the source of an event. I'm using upssched as my NOTIFYCMD, and it in turn is calling a little shell script that reads the flag that's passed and sends an email. What I can't figure out is how (if there is a way) to determine the originating UPS. It seems that only the status flag makes it across to the shell script. Or at least if it's passing more than that, I don't know how to retrieve it. I'm sure I must be missing something simple. Any thoughts/pointers would be appreciated! Garrett Michael Hayes -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20171031/7134c5d9/attachment.html>
O'Shaughnessy, Mike
2017-Oct-31 16:45 UTC
[Nut-upsuser] Email Alerts for Multiple UPSs with upssched
I'm running a single "nut-server" that monitors seven ups units. In upsmon.conf: MONITOR ups-1 0 <User> <Pw> master MONITOR ups-2 0 <User> <Pw> master MONITOR ups-3 0 <User> <Pw> master MONITOR ups-4 0 <User> <Pw> master MONITOR ups-5 1 <User> <Pw> master MONITOR ups-6 1 <User> <Pw> master MONITOR ups-7 0 <User> <Pw> master NOTIFYCMD /sbin/upssched NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG FSD SYSLOG+WALL+EXEC NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC In upssched.conf CMDSCRIPT /bin/upssched-cmd AT LOWBATT ups-1 EXECUTE ups-1-low AT LOWBATT ups-2 EXECUTE ups-2-low AT LOWBATT ups-3 EXECUTE ups-3-low AT LOWBATT ups-4 EXECUTE ups-4-low AT LOWBATT ups-5 EXECUTE ups-5-low AT LOWBATT ups-6 EXECUTE ups-6-low AT LOWBATT ups-7 EXECUTE ups-7-low Upssched-cmd: echo "upssched-cmd entry was $1" case $1 in ups-1-low) /ws/tools/shutdownUps-1 logger -t upssched-cmd "UPS 1 low battery" ;; ups-2-low) /ws/tools/shutdownUps-2 logger -t upssched-cmd "UPS 2 low battery" ;; ups-3-low) /ws/tools/shutdownUps-3 logger -t upssched-cmd "UPS 3 low battery" ;; ups-4-low) /ws/tools/shutdownUps-4 logger -t upssched-cmd "UPS 4 low battery" ;; ups-5-low) /ws/tools/shutdownUps-5 logger -t upssched-cmd "UPS 5 low battery" ;; ups-6-low) /ws/tools/shutdownUps-6 logger -t upssched-cmd "UPS 6 low battery" ;; ups-7-low) /ws/tools/shutdownUps-7 logger -t upssched-cmd "UPS 7 low battery" ;; Esac Scripts like 'shutdownUPS-N' do this: * Foreach linux box on the ups, log in and issue "shutdown -h now" * Foreach VMWare server on the ups, log in and issue "/sbin/shutdown.sh && /sbin/poweroff" Hope that helps! Mike From: Nut-upsuser [mailto:nut-upsuser-bounces+mike.oshaughnessy=gd-ms.com at lists.alioth.debian.org] On Behalf Of Garrett Michael Hayes Sent: Tuesday, October 31, 2017 11:10 AM To: nut-upsuser at lists.alioth.debian.org Subject: [Nut-upsuser] Email Alerts for Multiple UPSs with upssched Greetings Gentlebeings, I have started deploying a number of NUT instances on Raspberry Pi machines (Raspbian Jessie) across my network. The purpose of these "nutcases" as we refer to them is to monitor the status of the UPSs supporting our network switching infrastructure and notify us of power and battery events via email. No shutdown or other actions are required. Everything is going spiffy as all get-out so far. But now I'm running up against a configuration issue I don't quite know how to address. Thus far each "nutcase" has been configured to monitor a single UPS. Now I want to deploy one to monitor three UPSs in a larger switch closet. Adding the additional UPSs to ups.conf and upsmon.conf is fairly straightforward. But I'm darned if I can figure out how to configure the email alerts to let me know WHICH UPS is the source of an event. I'm using upssched as my NOTIFYCMD, and it in turn is calling a little shell script that reads the flag that's passed and sends an email. What I can't figure out is how (if there is a way) to determine the originating UPS. It seems that only the status flag makes it across to the shell script. Or at least if it's passing more than that, I don't know how to retrieve it. I'm sure I must be missing something simple. Any thoughts/pointers would be appreciated! Garrett Michael Hayes -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20171031/72dfb815/attachment-0001.html>
Garrett Michael Hayes
2017-Oct-31 17:18 UTC
[Nut-upsuser] Email Alerts for Multiple UPSs with upssched
Ah! So I can detect the source UPS in the upssched.conf and pass it as a distinct event to the shell script. That sounds like an excellent approach. Thanks! GMH From: O'Shaughnessy, Mike [mailto:Mike.OShaughnessy at gd-ms.com] Sent: Tuesday, October 31, 2017 12:46 PM To: Garrett Michael Hayes <Garrett at VerbalImaging.com>; nut-upsuser at lists.alioth.debian.org Subject: RE: Email Alerts for Multiple UPSs with upssched I'm running a single "nut-server" that monitors seven ups units. In upsmon.conf: MONITOR ups-1 0 <User> <Pw> master MONITOR ups-2 0 <User> <Pw> master MONITOR ups-3 0 <User> <Pw> master MONITOR ups-4 0 <User> <Pw> master MONITOR ups-5 1 <User> <Pw> master MONITOR ups-6 1 <User> <Pw> master MONITOR ups-7 0 <User> <Pw> master NOTIFYCMD /sbin/upssched NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG FSD SYSLOG+WALL+EXEC NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC In upssched.conf CMDSCRIPT /bin/upssched-cmd AT LOWBATT ups-1 EXECUTE ups-1-low AT LOWBATT ups-2 EXECUTE ups-2-low AT LOWBATT ups-3 EXECUTE ups-3-low AT LOWBATT ups-4 EXECUTE ups-4-low AT LOWBATT ups-5 EXECUTE ups-5-low AT LOWBATT ups-6 EXECUTE ups-6-low AT LOWBATT ups-7 EXECUTE ups-7-low Upssched-cmd: echo "upssched-cmd entry was $1" case $1 in ups-1-low) /ws/tools/shutdownUps-1 logger -t upssched-cmd "UPS 1 low battery" ;; ups-2-low) /ws/tools/shutdownUps-2 logger -t upssched-cmd "UPS 2 low battery" ;; ups-3-low) /ws/tools/shutdownUps-3 logger -t upssched-cmd "UPS 3 low battery" ;; ups-4-low) /ws/tools/shutdownUps-4 logger -t upssched-cmd "UPS 4 low battery" ;; ups-5-low) /ws/tools/shutdownUps-5 logger -t upssched-cmd "UPS 5 low battery" ;; ups-6-low) /ws/tools/shutdownUps-6 logger -t upssched-cmd "UPS 6 low battery" ;; ups-7-low) /ws/tools/shutdownUps-7 logger -t upssched-cmd "UPS 7 low battery" ;; Esac Scripts like 'shutdownUPS-N' do this: * Foreach linux box on the ups, log in and issue "shutdown -h now" * Foreach VMWare server on the ups, log in and issue "/sbin/shutdown.sh && /sbin/poweroff" Hope that helps! Mike From: Nut-upsuser [mailto:nut-upsuser-bounces+mike.oshaughnessy=gd-ms.com at lists.alioth.debian.org] On Behalf Of Garrett Michael Hayes Sent: Tuesday, October 31, 2017 11:10 AM To: nut-upsuser at lists.alioth.debian.org<mailto:nut-upsuser at lists.alioth.debian.org> Subject: [Nut-upsuser] Email Alerts for Multiple UPSs with upssched Greetings Gentlebeings, I have started deploying a number of NUT instances on Raspberry Pi machines (Raspbian Jessie) across my network. The purpose of these "nutcases" as we refer to them is to monitor the status of the UPSs supporting our network switching infrastructure and notify us of power and battery events via email. No shutdown or other actions are required. Everything is going spiffy as all get-out so far. But now I'm running up against a configuration issue I don't quite know how to address. Thus far each "nutcase" has been configured to monitor a single UPS. Now I want to deploy one to monitor three UPSs in a larger switch closet. Adding the additional UPSs to ups.conf and upsmon.conf is fairly straightforward. But I'm darned if I can figure out how to configure the email alerts to let me know WHICH UPS is the source of an event. I'm using upssched as my NOTIFYCMD, and it in turn is calling a little shell script that reads the flag that's passed and sends an email. What I can't figure out is how (if there is a way) to determine the originating UPS. It seems that only the status flag makes it across to the shell script. Or at least if it's passing more than that, I don't know how to retrieve it. I'm sure I must be missing something simple. Any thoughts/pointers would be appreciated! Garrett Michael Hayes -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20171031/4a208b28/attachment.html>
Jim Klimov
2017-Oct-31 17:36 UTC
[Nut-upsuser] Email Alerts for Multiple UPSs with upssched
On October 31, 2017 4:09:46 PM GMT+01:00, Garrett Michael Hayes <Garrett at VerbalImaging.com> wrote:>Greetings Gentlebeings, > >I have started deploying a number of NUT instances on Raspberry Pi >machines (Raspbian Jessie) across my network. The purpose of these >"nutcases" as we refer to them is to monitor the status of the UPSs >supporting our network switching infrastructure and notify us of power >and battery events via email. No shutdown or other actions are >required. > >Everything is going spiffy as all get-out so far. But now I'm running >up against a configuration issue I don't quite know how to address. > >Thus far each "nutcase" has been configured to monitor a single UPS. >Now I want to deploy one to monitor three UPSs in a larger switch >closet. Adding the additional UPSs to ups.conf and upsmon.conf is >fairly straightforward. But I'm darned if I can figure out how to >configure the email alerts to let me know WHICH UPS is the source of an >event. > >I'm using upssched as my NOTIFYCMD, and it in turn is calling a little >shell script that reads the flag that's passed and sends an email. >What I can't figure out is how (if there is a way) to determine the >originating UPS. It seems that only the status flag makes it across to >the shell script. Or at least if it's passing more than that, I don't >know how to retrieve it. > >I'm sure I must be missing something simple. Any thoughts/pointers >would be appreciated! > >Garrett Michael HayesTry $UPSNAME (this and other vars are RTFMed somewhere, maybe comments to configs) - I used it in NOTIFYCMD handling by scripts directly, maybe it would pass through upssched too? Also a script can call `set` to print out its env, as well as you can inspect /proc/PID/environ on linux to get the envvars of a running process. Jim -- Typos courtesy of K-9 Mail on my Android
Garrett Michael Hayes
2017-Nov-01 15:34 UTC
[Nut-upsuser] Email Alerts for Multiple UPSs with upssched
This was the secret sauce! I first modified my BASH script to stuff the output of the 'set' command into a variable, then passed that variable in to my email command. Then I triggered an event and saw what variables were there in the body of the message. Voila! $UPSNAME and $NOTIFYTYPE were there and available. I modified the script to pump THOSE into the mail command, and the problem is (at least partially) solved. The next challenge is going to be sorting out which UPS is being seen on which USB port. Thanks everyone!! GMH -----Original Message----- From: Jim Klimov [mailto:jimklimov at cos.ru] Sent: Tuesday, October 31, 2017 1:36 PM To: nut-upsuser at lists.alioth.debian.org; Garrett Michael Hayes <Garrett at VerbalImaging.com>; nut-upsuser at lists.alioth.debian.org Subject: Re: [Nut-upsuser] Email Alerts for Multiple UPSs with upssched On October 31, 2017 4:09:46 PM GMT+01:00, Garrett Michael Hayes <Garrett at VerbalImaging.com> wrote:>Greetings Gentlebeings, > >I have started deploying a number of NUT instances on Raspberry Pi >machines (Raspbian Jessie) across my network. The purpose of these >"nutcases" as we refer to them is to monitor the status of the UPSs >supporting our network switching infrastructure and notify us of power >and battery events via email. No shutdown or other actions are >required. > >Everything is going spiffy as all get-out so far. But now I'm running >up against a configuration issue I don't quite know how to address. > >Thus far each "nutcase" has been configured to monitor a single UPS. >Now I want to deploy one to monitor three UPSs in a larger switch >closet. Adding the additional UPSs to ups.conf and upsmon.conf is >fairly straightforward. But I'm darned if I can figure out how to >configure the email alerts to let me know WHICH UPS is the source of an >event. > >I'm using upssched as my NOTIFYCMD, and it in turn is calling a little >shell script that reads the flag that's passed and sends an email. >What I can't figure out is how (if there is a way) to determine the >originating UPS. It seems that only the status flag makes it across to >the shell script. Or at least if it's passing more than that, I don't >know how to retrieve it. > >I'm sure I must be missing something simple. Any thoughts/pointers >would be appreciated! > >Garrett Michael HayesTry $UPSNAME (this and other vars are RTFMed somewhere, maybe comments to configs) - I used it in NOTIFYCMD handling by scripts directly, maybe it would pass through upssched too? Also a script can call `set` to print out its env, as well as you can inspect /proc/PID/environ on linux to get the envvars of a running process. Jim -- Typos courtesy of K-9 Mail on my Android