[Nut-upsuser] NOTIFYCMD not running

Max Pierson-Liénard maxpierson at gmail.com
Wed Feb 12 19:51:46 GMT 2020


I finally got this working, for the sake of anyone else who comes across
this thread with a similar problem:

Since NOTIFYCMD was working fine with bash scripts, I had it point to a
bash script which I used to call my python script, and I set up the bash
script to capture errors and write them to a log file:
/etc/nut/ups-log.py > /home/pi/Documents/scripts/mylog 2>&1
I didn't realize that bash doesn't log errors anywhere by default.   Once I
had that, I was able to see immediately that the error was from a partial
file path that occurred early in the python script, before any of the
logging that I had set up had a chance to kick in.   So now I know to use
full paths with python.

Thanks everyone for your helpful replies, sorry to take up your time
with something that ended up not being a NUT problem at all

On Wed, Feb 12, 2020 at 4:00 AM <nut-upsuser-request at alioth-lists.debian.net>
wrote:

> Send Nut-upsuser mailing list submissions to
>         nut-upsuser at alioth-lists.debian.net
>
> To subscribe or unsubscribe via the World Wide Web, visit
>
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
> or, via email, send a message with subject or body 'help' to
>         nut-upsuser-request at alioth-lists.debian.net
>
> You can reach the person managing the list at
>         nut-upsuser-owner at alioth-lists.debian.net
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Nut-upsuser digest..."
>
>
> Today's Topics:
>
>    1. Re: NOTIFYCMD not running (Roger Price)
>    2. Re: NOTIFYCMD not running (Max Pierson-Liénard)
>    3. Re: NOTIFYCMD not running (Roger Price)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 11 Feb 2020 17:18:13 +0100 (CET)
> From: Roger Price <roger at rogerprice.org>
> To: nut-upsuser Mailing List <nut-upsuser at lists.alioth.debian.org>
> Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> Message-ID: <alpine.LSU.2.20.2002111700480.5507 at titan>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> On Tue, 11 Feb 2020, Max Pierson-Liénard wrote:
>
> > >  When you run that command, does "some text" appear in the system
> log?
> > When I run Documents/scripts/ups-log.py manually I do see the expected
> text echo'ed to the command line.  It actually appends to a Google
> > Sheet, not the internal log files.
> >
> > When I would expect to see it triggered by NOTIFYCMD, I don't see any
> text printed and nothing shows up at the google sheets.  If the
> > permission was being denied, would that be logged somewhere?
>
> Suggestion: in the ups-log.py script, open a local debug logging file with
> handle "fd_log" in mode "append".  Record every call of ups-log.py in
> "fd_log",
> whether valid or not.  Does "some text" appear in "fd_log"?  For the other
> calls
> of ups-log.py, does anything appear in "fd_log"?
>
> Roger
>
> For example:
>
> # Function open_log_file opens a file for logging
> # The file owner will be uid, with group gid, e.g. upsd:daemon
> # Returns file handle
> def open_log_file (logfile, uid, gid) :
>    try :
>      fd_log = open(logfile, 'a')   # Opened for current user, re-open if
> user change
>      os.chmod(logfile, 0o664)
>      os.chown(logfile, uid, gid)
>      return fd_log
>    except :
>      Your favourite error handling ...
>
> ------------------------------
>
> Message: 2
> Date: Wed, 12 Feb 2020 00:54:19 -0800
> From: Max Pierson-Liénard <maxpierson at gmail.com>
> To: nut-upsuser at alioth-lists.debian.net
> Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> Message-ID:
>         <
> CAK31S7b1Y_O9UJnQcyFXgRN+QVt+Dhrb2puSJyNYqCfFe5YZAA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Philippe Andersson I think tried to respond on this thread but all I see is
> your corporate email signature?
>
> I did some more troubleshooting tonight.  TL;DR at the end.  First,
> confirmed that NOTIFYCMD is in fact firing.  So I changed it to:
> NOTIFYCMD logger "NOTIFYCMD FIRED!"
> followed by:
> sudo service nut-client restart
> and that message does show up in /var/log/messages when I pull the plug on
> the ups, so something is happening.
>
> Next I tried changing the command to a bash script:
> NOTIFYCMD /etc/nut/call-ups-log.sh
>
> Inside that bash script, I just have this:
>
> #!/bin/sh
> logger "called call-ups-log.sh"
> /home/pi/Documents/scripts/ups-log.py "$*"
>
> "called call-ups-log.sh" shows up in /var/log/messages as expected, but the
> python script still isn't getting called.  I thought maybe it was something
> to do with the directory Documents/scripts/ so I moved it to /etc/nut/ and
> reconfigured everything, same result.  But at this point the bash script
> and python script are in the same directory with the same owner and
> permissions.
>
> TL;DR: I think at this point I've eliminated permissions problems, but
> there's something that is preventing NUT NOTIFYCMD from calling a python
> script properly.  The python script I'm using is here, it's working fine
> when I call it from a command line:
> https://pastebin.com/AXi67sV6
>
> Thanks for all the help and sorry for the text brick!
>
>
> Moved call-ups-log.sh to Documents/scripts, and all of a sudden it's not
> working anymore either.  Okay, so maybe it's the directory.
>
> On Tue, Feb 11, 2020 at 6:56 AM <
> nut-upsuser-request at alioth-lists.debian.net>
> wrote:
>
> > Send Nut-upsuser mailing list submissions to
> >         nut-upsuser at alioth-lists.debian.net
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >
> > https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
> > or, via email, send a message with subject or body 'help' to
> >         nut-upsuser-request at alioth-lists.debian.net
> >
> > You can reach the person managing the list at
> >         nut-upsuser-owner at alioth-lists.debian.net
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Nut-upsuser digest..."
> >
> >
> > Today's Topics:
> >
> >    1. Re: NOTIFYCMD not running (Philippe Andersson)
> >    2. Re: NOTIFYCMD not running (Philippe Andersson)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Tue, 11 Feb 2020 14:19:58 +0100
> > From: Philippe Andersson <pan at iba-group.com>
> > To: <nut-upsuser at alioth-lists.debian.net>
> > Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> > Message-ID: <32476bb1-9b33-b73e-a766-0e524b77c7db at iba-group.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> >
> > Disclaimer | Use of IBA e-communication<
> > https://iba-worldwide.com/disclaimer>
> >
> > The contents of this e-mail message and any attachments are intended
> > solely for the recipient (s) named above. This communication is intended
> to
> > be and to remain confidential and may be protected by intellectual
> property
> > rights. Any use of the information contained herein (including but not
> > limited to, total or partial reproduction, communication or distribution
> of
> > any form) by persons other than the designated recipient(s) is
> prohibited.
> > Please notify the sender immediately by e-mail if you have received this
> > e-mail by mistake and delete this e-mail from your system. E-mail
> > transmission cannot be guaranteed to be secure or error-free. Ion Beam
> > Applications does not accept liability for any such errors. Thank you for
> > your cooperation.
> > -------------- next part --------------
> > An embedded message was scrubbed...
> > From: Philippe Andersson <pan at iba-group.com>
> > Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> > Date: Tue, 11 Feb 2020 14:19:58 +0100
> > Size: 16341
> > URL: <
> >
> http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20200211/44658975/attachment-0001.mht
> > >
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Tue, 11 Feb 2020 15:41:50 +0100
> > From: Philippe Andersson <pan at iba-group.com>
> > To: <nut-upsuser at alioth-lists.debian.net>
> > Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> > Message-ID: <846787f4-4e74-742f-8708-cd1b1cd9c1df at iba-group.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> >
> > Disclaimer | Use of IBA e-communication<
> > https://iba-worldwide.com/disclaimer>
> >
> > The contents of this e-mail message and any attachments are intended
> > solely for the recipient (s) named above. This communication is intended
> to
> > be and to remain confidential and may be protected by intellectual
> property
> > rights. Any use of the information contained herein (including but not
> > limited to, total or partial reproduction, communication or distribution
> of
> > any form) by persons other than the designated recipient(s) is
> prohibited.
> > Please notify the sender immediately by e-mail if you have received this
> > e-mail by mistake and delete this e-mail from your system. E-mail
> > transmission cannot be guaranteed to be secure or error-free. Ion Beam
> > Applications does not accept liability for any such errors. Thank you for
> > your cooperation.
> > -------------- next part --------------
> > An embedded message was scrubbed...
> > From: Philippe Andersson <pan at iba-group.com>
> > Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> > Date: Tue, 11 Feb 2020 15:41:50 +0100
> > Size: 32550
> > URL: <
> >
> http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20200211/4a868e92/attachment.mht
> > >
> >
> > ------------------------------
> >
> > Subject: Digest Footer
> >
> > _______________________________________________
> > Nut-upsuser mailing list
> > Nut-upsuser at alioth-lists.debian.net
> > https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
> >
> > ------------------------------
> >
> > End of Nut-upsuser Digest, Vol 176, Issue 6
> > *******************************************
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20200212/a19625c2/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Wed, 12 Feb 2020 10:17:31 +0100 (CET)
> From: Roger Price <roger at rogerprice.org>
> To: nut-upsuser Mailing List <nut-upsuser at lists.alioth.debian.org>
> Subject: Re: [Nut-upsuser] NOTIFYCMD not running
> Message-ID: <alpine.LSU.2.20.2002121013070.5507 at titan>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> On Wed, 12 Feb 2020, Max Pierson-Liénard wrote:
>
> > Next I tried changing the command to a bash script:
> > NOTIFYCMD /etc/nut/call-ups-log.sh
> >
> > Inside that bash script, I just have this:
> >
> > #!/bin/sh
> > logger "called call-ups-log.sh"
> > /home/pi/Documents/scripts/ups-log.py "$*"
> >
> > "called call-ups-log.sh" shows up in /var/log/messages as expected, but
> the python script still isn't getting called.
>
> The good news is that the NOTIFYCMD mechanism is working.  This is
> beginning to
> look like a Python problem.
>
> Roger
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Nut-upsuser mailing list
> Nut-upsuser at alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
>
> ------------------------------
>
> End of Nut-upsuser Digest, Vol 176, Issue 7
> *******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20200212/5d98256a/attachment-0001.html>


More information about the Nut-upsuser mailing list