<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.3698" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2>My deep apologizes... /tmp/alarms.txt is written when
upsmon is started as daemon.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2>So the script is called but doesn't work in that case. What
are the restriction for the execution contexte called by
NOTIFYCMD?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=238385108-08042011><FONT face=Arial
color=#0000ff size=2>Antoine</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=fr dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>De :</B>
nut-upsuser-bounces+antoine.gatineau=alcatel-lucent.com@lists.alioth.debian.org
[mailto:nut-upsuser-bounces+antoine.gatineau=alcatel-lucent.com@lists.alioth.debian.org]
<B>De la part de</B> GATINEAU, ANTOINE (ANTOINE)<BR><B>Envoyé :</B> jeudi 7
avril 2011 18:44<BR><B>À :</B> Arnaud Quette<BR><B>Cc :</B>
nut-upsuser@lists.alioth.debian.org<BR><B>Objet :</B> Re: [Nut-upsuser]
Unable run command on notify events<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>Hi Arnaud,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2><SPAN class=226273516-07042011>my answers below in the
mail</SPAN></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2><SPAN
class=226273516-07042011>Antoine</SPAN></FONT></DIV></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=fr dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>De :</B> Arnaud Quette
[mailto:aquette.dev@gmail.com] <BR><B>Envoyé :</B> jeudi 7 avril 2011
17:57<BR><B>À :</B> GATINEAU, ANTOINE (ANTOINE)<BR><B>Cc :</B>
nut-upsuser@lists.alioth.debian.org<BR><B>Objet :</B> Re: [Nut-upsuser]
Unable run command on notify events<BR></FONT><BR></DIV>
<DIV></DIV>Hi Antoine,<BR><BR>
<DIV class=gmail_quote>2011/4/7 GATINEAU, ANTOINE (ANTOINE) <SPAN dir=ltr><<A
href="mailto:antoine.gatineau@alcatel-lucent.com">antoine.gatineau@alcatel-lucent.com</A>></SPAN><BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">Hello,<BR><BR>I'm
trying to integrate upsmon with my alarm management application.<BR>For that I
wan't to use NOTIFYCMD from upsmon. I am having troubles making everything
work together.<BR><BR>I'm using nut version 2.4.3<BR><BR>I created a nutmon
user and my script defined in NOTIFYCMD works perfectly when executed in a
nutmon shell.<BR>I have configured RUN_AS_USER nutmon<BR><BR>Here is
upsmon.conf :<BR>MONITOR ups_on_usb@localhost 1 nut nut master<BR>RUN_AS_USER
nutmon<BR>SHUTDOWNCMD "/sbin/shutdown -h +0"<BR>MINSUPPLIES 1<BR>POLLFREQ
30<BR>POLLFREQALERT 30<BR>HOSTSYNC 15<BR>DEADTIME 60<BR>POWERDOWNFLAG
/etc/killpower<BR>RBWARNTIME 43200<BR>NOCOMMWARNTIME 300<BR>FINALDELAY
5<BR>NOTIFYCMD "upsAlarmManager"<BR>NOTIFYMSG ONLINE "UPS %s state is on
line"<BR>NOTIFYMSG ONBATT "UPS %s state is on battery"<BR>NOTIFYMSG LOWBATT
"UPS %s battery level is low"<BR>NOTIFYMSG SHUTDOWN "UPS %s triggered a server
shutdown"<BR>NOTIFYMSG REPLBATT "UPS %s battery needs to be
replaced"<BR>NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC<BR>NOTIFYFLAG ONBATT
SYSLOG+WALL+EXEC<BR>NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC<BR>NOTIFYFLAG SHUTDOWN
SYSLOG+WALL+EXEC<BR>NOTIFYFLAG REPLBATT SYSLOG+EXEC<BR><BR>upsAlarmManager's
path is defined i environment variable $PATH and i have the same behavior
using the complete path.<BR></BLOCKQUOTE>
<DIV><BR>as a general best practice, prefer to use absolute path.<BR>this way,
you avoid path related issues due to the launch context (see
below)<BR> </DIV>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">In
order to check if it is called, the script writes in
/tmp/alarm.txt<BR><BR>Here are my results :<BR>Upsmon runing as daemon by
"service ups start" => /tmp/alarm.txt empty, alarms are not sent<BR>Upsmon
runing using command line as root "/usr/sbin/upsmon" => /tmp/alarm.txt
empty, alarms are not sent<BR>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.<BR></BLOCKQUOTE>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><BR>are you cleaning the testbed before each tests (ie "rm -f
/tmp/alarm.txt"), just to be sure?<SPAN class=226273516-07042011><FONT
face=Arial color=#0000ff size=2> </FONT></SPAN><BR> </DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>I didn't delete alarm.txt each time... Here are the
permissions of the file.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>-rw-r--r-- 1 nutmon nutmon 183 Apr 7 16:38
/tmp/alarms.txt</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial><FONT
color=#0000ff><FONT size=2>so i don't think write permission are an issue.
However, i will retry tomorrow.<SPAN
class=226273516-07042011> </SPAN></FONT></FONT></FONT></SPAN></DIV></BLOCKQUOTE>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial><FONT
color=#0000ff><FONT size=2><SPAN
class=226273516-07042011></SPAN></FONT></FONT></FONT></SPAN> </DIV>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">I
want it to work as daemon. Did i miss something, what is the difference
between debug and the other modes?<BR></BLOCKQUOTE></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><BR>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.<SPAN class=226273516-07042011><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV><SPAN class=226273516-07042011>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>To be sure the script works in the nutmon user context,
i have opened a shell using su - nutmon and executed the 2 commands
:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>export NOTIFYTYPE=ONLINE</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>upsAlarmManager</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>It works so i don't think the user context is an issue
unless upsmon loads only a minimal context...</FONT></SPAN> <SPAN
class=226273516-07042011><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV dir=ltr align=left></SPAN>To be able to confirm, or at least troubleshoot
this issue, I'd need, if possible, to have a look at your script.<BR>If that
pose a problem to do it publicly, don't hesitate to send it to my @<A
href="http://eaton.com">eaton.com</A> address.<BR><SPAN
class=226273516-07042011><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=226273516-07042011>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>Here is the upsAlarmManager script (sendAlarm path
is in the $PATH env variable<SPAN class=226273516-07042011>, it is a cli
command to actually send the alarm to alarm
server</SPAN>):</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=793572316-07042011><FONT face=Arial
color=#0000ff size=2>#!/bin/sh</FONT></SPAN></DIV>
<DIV><SPAN class=793572316-07042011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=793572316-07042011><FONT face=Arial color=#0000ff
size=2>echo "start upsAlarManager $(date)" >>
/tmp/alarms.txt</FONT></SPAN><SPAN class=793572316-07042011></DIV>
<DIV dir=ltr align=left><BR><FONT face=Arial color=#0000ff size=2>Error
()<BR>{<BR>echo "upsAlarmManager must be called by upsmon."<BR>echo "Wrong
argument, an error occured"<BR>exit 1<BR>}</FONT></DIV>
<DIV><BR><FONT face=Arial color=#0000ff size=2>msg="$@"</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV dir=ltr align=left><BR><FONT face=Arial color=#0000ff
size=2>COMPONENT_NAME=UPS<BR>CORRELATOR=UPSALR</FONT></DIV>
<DIV><BR><FONT face=Arial color=#0000ff size=2>ClearAlarms
()<BR>{<BR> CLEARID="UPS-5"</FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=793572316-07042011> </SPAN>echo "sendAlarm $COMPONENT_NAME
$CLEARID $CORRELATOR" >> /tmp/alarms.txt<BR> sendAlarm
$COMPONENT_NAME $CLEARID $CORRELATOR "$msg"<BR>}</FONT></FONT></FONT></DIV>
<DIV><BR><FONT face=Arial color=#0000ff size=2>doSendAlarm
()<BR>{<BR> alarmid=$1</FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=793572316-07042011></SPAN> echo "sendAlarm $COMPONENT_NAME
$alarmid $CORRELATOR" >> /tmp/alarms.txt<BR> sendAlarm
$COMPONENT_NAME $alarmid $CORRELATOR "$msg"<BR>}</FONT></FONT></FONT></DIV>
<DIV><BR><FONT face=Arial color=#0000ff size=2>case $NOTIFYTYPE
in<BR> ONLINE)<BR> ClearAlarms<BR> ;;<BR> ONBATT)<BR> ClearAlarms<BR> ALARMID="UPS-1"<BR> doSendAlarm
$ALARMID<BR> ;;<BR> LOWBATT)<BR> ClearAlarms<BR> ALARMID="UPS-2"<BR> doSendAlarm
$ALARMID<BR> ;;<BR> SHUTDOWN)<BR> ClearAlarms<BR> ALARMID="UPS-3"<BR> doSendAlarm
$ALARMID<BR> ;;<BR> REPLBATT)<BR> ALARMID="UPS-4"<BR> doSendAlarm
$ALARMID<BR> ;;<BR> *)<BR> Error<BR> ;;<BR>esac</FONT></DIV></BLOCKQUOTE></SPAN><BR> </SPAN><BR>cheers,<BR>Arnaud<BR>--
<BR>Linux / Unix Expert R&D - Eaton - <A
href="http://powerquality.eaton.com"
target=_blank>http://powerquality.eaton.com</A><BR>Network UPS Tools (NUT)
Project Leader - <A href="http://www.networkupstools.org/"
target=_blank>http://www.networkupstools.org/</A><BR>Debian Developer - <A
href="http://www.debian.org" target=_blank>http://www.debian.org</A><BR>Free
Software Developer - <A href="http://arnaud.quette.free.fr/"
target=_blank>http://arnaud.quette.free.fr/</A><BR><BR></DIV></BLOCKQUOTE></BODY></HTML>