<!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>&nbsp;</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>&nbsp;</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>&nbsp;</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&nbsp;:</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é&nbsp;:</B> jeudi 7 
avril 2011 18:44<BR><B>À&nbsp;:</B> Arnaud Quette<BR><B>Cc&nbsp;:</B> 
nut-upsuser@lists.alioth.debian.org<BR><B>Objet&nbsp;:</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>&nbsp;</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>&nbsp;</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&nbsp;:</B> Arnaud Quette 
[mailto:aquette.dev@gmail.com] <BR><B>Envoyé&nbsp;:</B> jeudi 7 avril 2011 
17:57<BR><B>À&nbsp;:</B> GATINEAU, ANTOINE (ANTOINE)<BR><B>Cc&nbsp;:</B> 
nut-upsuser@lists.alioth.debian.org<BR><B>Objet&nbsp;:</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>&lt;<A 
href="mailto:antoine.gatineau@alcatel-lucent.com">antoine.gatineau@alcatel-lucent.com</A>&gt;</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>&nbsp;</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" =&gt; /tmp/alarm.txt empty, alarms are not sent<BR>Upsmon 
  runing using command line as root "/usr/sbin/upsmon" =&gt; /tmp/alarm.txt 
  empty, alarms are not sent<BR>Upsmon runing in debug using command line as 
  root "/usr/sbin/upsmon -D" =&gt; /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>&nbsp;&nbsp;</FONT></SPAN><BR>&nbsp;</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&nbsp; 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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;<SPAN 
    class=226273516-07042011><FONT face=Arial color=#0000ff 
    size=2>&nbsp;</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>&nbsp;</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&nbsp;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>&nbsp;</DIV>
    <DIV><SPAN class=793572316-07042011><FONT face=Arial color=#0000ff 
    size=2>echo "start upsAlarManager $(date)" &gt;&gt; 
    /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>&nbsp;</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>&nbsp;CLEARID="UPS-5"</FONT></DIV>
    <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
    class=793572316-07042011>&nbsp;</SPAN>echo "sendAlarm $COMPONENT_NAME 
    $CLEARID $CORRELATOR" &gt;&gt; /tmp/alarms.txt<BR>&nbsp;sendAlarm 
    $COMPONENT_NAME $CLEARID $CORRELATOR "$msg"<BR>}</FONT></FONT></FONT></DIV>
    <DIV><BR><FONT face=Arial color=#0000ff size=2>doSendAlarm 
    ()<BR>{<BR>&nbsp;alarmid=$1</FONT></DIV>
    <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
    class=793572316-07042011></SPAN>&nbsp;echo "sendAlarm $COMPONENT_NAME 
    $alarmid $CORRELATOR" &gt;&gt; /tmp/alarms.txt<BR>&nbsp;sendAlarm 
    $COMPONENT_NAME $alarmid $CORRELATOR "$msg"<BR>}</FONT></FONT></FONT></DIV>
    <DIV><BR><FONT face=Arial color=#0000ff size=2>case $NOTIFYTYPE 
    in<BR>&nbsp;ONLINE)<BR>&nbsp;&nbsp;ClearAlarms<BR>&nbsp;&nbsp;;;<BR>&nbsp;ONBATT)<BR>&nbsp;&nbsp;ClearAlarms<BR>&nbsp;&nbsp;ALARMID="UPS-1"<BR>&nbsp;&nbsp;doSendAlarm 
    $ALARMID<BR>&nbsp;&nbsp;;;<BR>&nbsp;LOWBATT)<BR>&nbsp;&nbsp;ClearAlarms<BR>&nbsp;&nbsp;ALARMID="UPS-2"<BR>&nbsp;&nbsp;doSendAlarm 
    $ALARMID<BR>&nbsp;&nbsp;;;<BR>&nbsp;SHUTDOWN)<BR>&nbsp;&nbsp;ClearAlarms<BR>&nbsp;&nbsp;ALARMID="UPS-3"<BR>&nbsp;&nbsp;doSendAlarm 
    $ALARMID<BR>&nbsp;&nbsp;;;<BR>&nbsp;REPLBATT)<BR>&nbsp;&nbsp;ALARMID="UPS-4"<BR>&nbsp;&nbsp;doSendAlarm 
    $ALARMID<BR>&nbsp;&nbsp;;;<BR>&nbsp;*)<BR>&nbsp;&nbsp;Error<BR>&nbsp;&nbsp;;;<BR>esac</FONT></DIV></BLOCKQUOTE></SPAN><BR>&nbsp;</SPAN><BR>cheers,<BR>Arnaud<BR>-- 
  <BR>Linux / Unix Expert R&amp;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>