Re: [Nut-upsuser] Unable run command on notify events
Hi, My deep apologizes... /tmp/alarms.txt is written when upsmon is started as daemon. So the script is called but doesn't work in that case. What are the restriction for the execution contexte called by NOTIFYCMD? Antoine De : nut-upsuser-bounces+antoine.gatineau=alcatel-lucent@lists.alioth.debian.org [mailto:nut-upsuser-bounces+antoine.gatineau=alcatel-lucent@lists.alioth.debian.org] De la part de GATINEAU, ANTOINE (ANTOINE) Envoyé : jeudi 7 avril 2011 18:44 À : Arnaud Quette Cc : nut-upsuser@lists.alioth.debian.org Objet : Re: [Nut-upsuser] Unable run command on notify events Hi Arnaud, my answers below in the mail Antoine De : Arnaud Quette [mailto:aquette@gmail.com] Envoyé : jeudi 7 avril 2011 17:57 À : GATINEAU, ANTOINE (ANTOINE) Cc : nut-upsuser@lists.alioth.debian.org Objet : Re: [Nut-upsuser] Unable run command on notify events Hi Antoine, 2011/4/7 GATINEAU, ANTOINE (ANTOINE) antoine.gatin...@alcatel-lucent.commailto:antoine.gatin...@alcatel-lucent.com Hello, I'm trying to integrate upsmon with my alarm management application. For that I wan't to use NOTIFYCMD from upsmon. I am having troubles making everything work together. I'm using nut version 2.4.3 I created a nutmon user and my script defined in NOTIFYCMD works perfectly when executed in a nutmon shell. I have configured RUN_AS_USER nutmon Here is upsmon.conf : MONITOR ups_on_usb@localhost 1 nut nut master RUN_AS_USER nutmon SHUTDOWNCMD /sbin/shutdown -h +0 MINSUPPLIES 1 POLLFREQ 30 POLLFREQALERT 30 HOSTSYNC 15 DEADTIME 60 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5 NOTIFYCMD upsAlarmManager NOTIFYMSG ONLINE UPS %s state is on line NOTIFYMSG ONBATT UPS %s state is on battery NOTIFYMSG LOWBATT UPS %s battery level is low NOTIFYMSG SHUTDOWN UPS %s triggered a server shutdown NOTIFYMSG REPLBATT UPS %s battery needs to be replaced NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+EXEC upsAlarmManager's path is defined i environment variable $PATH and i have the same behavior using the complete path. as a general best practice, prefer to use absolute path. this way, you avoid path related issues due to the launch context (see below) In order to check if it is called, the script writes in /tmp/alarm.txt Here are my results : Upsmon runing as daemon by service ups start = /tmp/alarm.txt empty, alarms are not sent Upsmon runing using command line as root /usr/sbin/upsmon = /tmp/alarm.txt empty, alarms are not sent Upsmon runing in debug using command line as root /usr/sbin/upsmon -D = /tmp/alarm.txt is written, alarms are sent to my alarm management framework. are you cleaning the testbed before each tests (ie rm -f /tmp/alarm.txt), just to be sure? I didn't delete alarm.txt each time... Here are the permissions of the file. -rw-r--r-- 1 nutmon nutmon 183 Apr 7 16:38 /tmp/alarms.txt so i don't think write permission are an issue. However, i will retry tomorrow. I want it to work as daemon. Did i miss something, what is the difference between debug and the other modes? the user context you launched the command from... but more probably here, the way you retrieve data from upsAlarmManager to write it to the file and send it. To be sure the script works in the nutmon user context, i have opened a shell using su - nutmon and executed the 2 commands : export NOTIFYTYPE=ONLINE upsAlarmManager It works so i don't think the user context is an issue unless upsmon loads only a minimal context... To be able to confirm, or at least troubleshoot this issue, I'd need, if possible, to have a look at your script. If that pose a problem to do it publicly, don't hesitate to send it to my @eaton.comhttp://eaton.com address. Here is the upsAlarmManager script (sendAlarm path is in the $PATH env variable, it is a cli command to actually send the alarm to alarm server): #!/bin/sh echo start upsAlarManager $(date) /tmp/alarms.txt Error () { echo upsAlarmManager must be called by upsmon. echo Wrong argument, an error occured exit 1 } msg=$@ COMPONENT_NAME=UPS CORRELATOR=UPSALR ClearAlarms () { CLEARID=UPS-5 echo sendAlarm $COMPONENT_NAME $CLEARID $CORRELATOR /tmp/alarms.txt sendAlarm $COMPONENT_NAME $CLEARID $CORRELATOR $msg } doSendAlarm () { alarmid=$1 echo sendAlarm $COMPONENT_NAME $alarmid $CORRELATOR /tmp/alarms.txt sendAlarm $COMPONENT_NAME $alarmid $CORRELATOR $msg } case $NOTIFYTYPE in ONLINE) ClearAlarms ;; ONBATT) ClearAlarms ALARMID=UPS-1 doSendAlarm $ALARMID ;; LOWBATT) ClearAlarms ALARMID=UPS-2 doSendAlarm $ALARMID ;; SHUTDOWN) ClearAlarms ALARMID=UPS-3 doSendAlarm $ALARMID ;; REPLBATT) ALARMID=UPS-4 doSendAlarm $ALARMID ;; *) Error ;; esac cheers, Arnaud -- Linux / Unix Expert RD - Eaton - http://powerquality.eaton.com
Re: [Nut-upsuser] Unable run command on notify events
Hi again, I got it working. Aparently, the script is launched as the specified user but without the environment variables. To make it work, i have defined NOTIFYCMD as following : NOTIFYCMD /bin/bah -c 'source /etc/profile ; /path/to/script/scriptname Is there a better way or is this the best way? Thanks for your help Arnaud. Antoine De : GATINEAU, ANTOINE (ANTOINE) Envoyé : vendredi 8 avril 2011 10:54 À : GATINEAU, ANTOINE (ANTOINE); Arnaud Quette Cc : nut-upsuser@lists.alioth.debian.org Objet : RE: [Nut-upsuser] Unable run command on notify events Hi, My deep apologizes... /tmp/alarms.txt is written when upsmon is started as daemon. So the script is called but doesn't work in that case. What are the restriction for the execution contexte called by NOTIFYCMD? Antoine De : nut-upsuser-bounces+antoine.gatineau=alcatel-lucent@lists.alioth.debian.org [mailto:nut-upsuser-bounces+antoine.gatineau=alcatel-lucent@lists.alioth.debian.org] De la part de GATINEAU, ANTOINE (ANTOINE) Envoyé : jeudi 7 avril 2011 18:44 À : Arnaud Quette Cc : nut-upsuser@lists.alioth.debian.org Objet : Re: [Nut-upsuser] Unable run command on notify events Hi Arnaud, my answers below in the mail Antoine De : Arnaud Quette [mailto:aquette@gmail.com] Envoyé : jeudi 7 avril 2011 17:57 À : GATINEAU, ANTOINE (ANTOINE) Cc : nut-upsuser@lists.alioth.debian.org Objet : Re: [Nut-upsuser] Unable run command on notify events Hi Antoine, 2011/4/7 GATINEAU, ANTOINE (ANTOINE) antoine.gatin...@alcatel-lucent.commailto:antoine.gatin...@alcatel-lucent.com Hello, I'm trying to integrate upsmon with my alarm management application. For that I wan't to use NOTIFYCMD from upsmon. I am having troubles making everything work together. I'm using nut version 2.4.3 I created a nutmon user and my script defined in NOTIFYCMD works perfectly when executed in a nutmon shell. I have configured RUN_AS_USER nutmon Here is upsmon.conf : MONITOR ups_on_usb@localhost 1 nut nut master RUN_AS_USER nutmon SHUTDOWNCMD /sbin/shutdown -h +0 MINSUPPLIES 1 POLLFREQ 30 POLLFREQALERT 30 HOSTSYNC 15 DEADTIME 60 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5 NOTIFYCMD upsAlarmManager NOTIFYMSG ONLINE UPS %s state is on line NOTIFYMSG ONBATT UPS %s state is on battery NOTIFYMSG LOWBATT UPS %s battery level is low NOTIFYMSG SHUTDOWN UPS %s triggered a server shutdown NOTIFYMSG REPLBATT UPS %s battery needs to be replaced NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+EXEC upsAlarmManager's path is defined i environment variable $PATH and i have the same behavior using the complete path. as a general best practice, prefer to use absolute path. this way, you avoid path related issues due to the launch context (see below) In order to check if it is called, the script writes in /tmp/alarm.txt Here are my results : Upsmon runing as daemon by service ups start = /tmp/alarm.txt empty, alarms are not sent Upsmon runing using command line as root /usr/sbin/upsmon = /tmp/alarm.txt empty, alarms are not sent Upsmon runing in debug using command line as root /usr/sbin/upsmon -D = /tmp/alarm.txt is written, alarms are sent to my alarm management framework. are you cleaning the testbed before each tests (ie rm -f /tmp/alarm.txt), just to be sure? I didn't delete alarm.txt each time... Here are the permissions of the file. -rw-r--r-- 1 nutmon nutmon 183 Apr 7 16:38 /tmp/alarms.txt so i don't think write permission are an issue. However, i will retry tomorrow. I want it to work as daemon. Did i miss something, what is the difference between debug and the other modes? the user context you launched the command from... but more probably here, the way you retrieve data from upsAlarmManager to write it to the file and send it. To be sure the script works in the nutmon user context, i have opened a shell using su - nutmon and executed the 2 commands : export NOTIFYTYPE=ONLINE upsAlarmManager It works so i don't think the user context is an issue unless upsmon loads only a minimal context... To be able to confirm, or at least troubleshoot this issue, I'd need, if possible, to have a look at your script. If that pose a problem to do it publicly, don't hesitate to send it to my @eaton.comhttp://eaton.com address. Here is the upsAlarmManager script (sendAlarm path is in the $PATH env variable, it is a cli command to actually send the alarm to alarm server): #!/bin/sh echo start upsAlarManager $(date) /tmp/alarms.txt Error () { echo upsAlarmManager must be called by upsmon. echo Wrong argument, an error occured exit 1 } msg=$@ COMPONENT_NAME=UPS CORRELATOR=UPSALR ClearAlarms () { CLEARID=UPS-5 echo sendAlarm $COMPONENT_NAME $CLEARID $CORRELATOR /tmp/alarms.txt sendAlarm $COMPONENT_NAME
Re: [Nut-upsuser] Unable run command on notify events
Citeren GATINEAU, ANTOINE (ANTOINE) antoine.gatin...@alcatel-lucent.com: I got it working. Aparently, the script is launched as the specified user but without the environment variables. To make it work, i have defined NOTIFYCMD as following : NOTIFYCMD /bin/bah -c 'source /etc/profile ; /path/to/script/scriptname Is there a better way or is this the best way? Scripts must be self-contained. It is grievous mistake to assume anything about the environment. So it is best to follow Arnaud's advice and use absolute paths to other scripts/binaries that you need. If that's not possible, it is probably better to source /etc/profile from within the script you're running. Best regards, Arjen -- Please keep list traffic on the list (off-list replies will be rejected) ___ Nut-upsuser mailing list Nut-upsuser@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/nut-upsuser