Commands won't run from filters

Forum for questions and support relating to the 1.30.x releases only.
Locked
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Commands won't run from filters

Post by empty01 »

Hi
Related to another issue I have raised, I have written a python script to restart my cameras, using onvif commands. I would like to run this when a filter detects signal loss on any particular camera. I can run the python script on the command line without problems, and it restarts my camera. But when I paste the command into 'Execute command on all matches' in my filter, it doesn't work. I checked my /var/log/syslog and it gives the following error:

Nov 2 10:47:56 SUNFIRE zmfilter[28883]: ERR [Command 'python /usr/local/bin/IPCam_Restart_Scripts/RB_Robox3.py /usr/share/zoneminder/www/events/1/17/10/25/06/28/49' exited with status: 1]

The command I wanted to run is:

python /usr/local/bin/IPCam_Restart_Scripts/RB_Robox3.py

But the filter seems to have added some guff:
'/usr/share/zoneminder/www/events/1/17/10/25/06/28/49'

Wading through treacle

All best

Mark
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

BTW: Yes, the owner of this python script is root. I tried with versions owned by me in my home directory, and in some /usr/local/bin directory.
And yes, I did chmod +x on the .py script
And yes, I tried putting a shebang in the python script
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Commands won't run from filters

Post by rockedge »

try using a Bash script instead in the execute a command field in the filter. The bash script starts the python program.

Code: Select all

#!/bin/sh
python /usr/local/bin/IPCam_Restart_Scripts/RB_Robox3.py.
for some reason I had a similar thing going on in a setup and that was a work around that got my python program to run from a ZM command.
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

Hi
Thanks, but I already tried that and it didn't work. Gave me the message:

Nov 2 16:37:13 SUNFIRE zmfilter[1730]: INF [Executing '/home/mark/python-onvif/IPCam_Restart_Scripts/RB_Robox3.sh /usr/share/zoneminder/www/events/11/17/11/02/16/30/41']
Nov 2 16:37:13 SUNFIRE zmfilter[1730]: ERR [Command '/home/mark/python-onvif/IPCam_Restart_Scripts/RB_Robox3.sh /usr/share/zoneminder/www/events/11/17/11/02/16/30/41' exited with status: 72057594037927935]

It won't even let me run simple commands, like deleting some dummy file.

All best

Mark
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

The reason I want to do this relates to my other major post on this forum: 'Signal loss causes blue screen that requires camera reset'

I was unable to resolve that problem, despite much advice and getting a much more powerful server to run zm. It seems my cameras are dropping their RTSP streams, and I get the following error:

'Unable to open input rtsp://192.168.1.???:554/ch01.264 due to: Connection timed out'

The only way I could get the camera's RTSP streams back was to reboot them.

After pulling all my hair out and losing the will to live, I decided to try automating the rebooting using onvif commands.

So I tried installing Node.js and npm, as it has an onvif implementation. After much more pain, I concluded that it was not possible to get this to work - I couldn't even get basic Node.js and npm working.

Then I came across quatanium/python-onvif. I have a bit of a python background so had a go, and got some onvif commands to work, including the 'SystemReboot' command. So now I have a bunch of python scripts that will reboot my cameras, and want to trigger them when I get signal loss on specific cameras.

Interestingly, when using python-onvif, it turns out I don't need to send the onvif 'SystemReboot' command to get my RTSP stream back - I merely need to create a camera instance and it comes back on. Makes me suspect that zm is not handling the RTSP stream properly.

Anyway, it now turns out that zm filters don't do what they are supposed to do and run user-specified commands.

So my main question is 'how should I kill myself?' I understand from reading around the subject that a slow and painful death can be quite unpleasant. On the other hand, apart from my zm woes, I have led a productive and meaningful life, and it seems a shame to shake off this mortal coil without any drama.

Any advice gratefully received.
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

Re: Commands won't run from filters

Post by snake »

You can also use the API instead of filters.

It may be that ZM is running the command as the apache user (www-user). Did you try chmod 777 and see if that works as a test? Folder permissions may also be an issue. Filters should be able to execute a command in 1.30.4. Troubleshoot that first.

Also, OS? What guide did you use to install ZM?
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

Have tried using API, but with zero success.
When I run:
curl -d "username=****&password=****&action=login&view=console" -c cookies.txt http://192.168.1.134/zm/index.php

I get the response:
curl: (6) Could not resolve host: username=****&password=****&action=login&view=console
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://192.168.1.134/zm/index.php">here</a>.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 192.168.1.134 Port 80</address>
</body></html>

I think the main problem is the docs are written by people who know what they are doing (which is good), but for people who already know what they are doing and don't really need to read the docs.

zm is running on Unbuntu 16.04. I followed this:
http://zoneminder.readthedocs.io/en/lat ... untu-16-04

Have now done that ~6 times on 3 different machines.

I tried creating my scripts as me, and as root (putting them in a root-owned directory). No banana.
Also tried using chmod 777 (all that changes is giving the 'all users' write permission).

I created some dummy file and tested with a simple 'rm' command - still doesn't work. According to the logs (see above) it seems to be adding some extra stuff to my commands.
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

Re: Commands won't run from filters

Post by snake »

empty01 wrote: Thu Nov 02, 2017 9:53 pm zm is running on Unbuntu 16.04. I followed this:
http://zoneminder.readthedocs.io/en/lat ... untu-16-04

Have now done that ~6 times on 3 different machines.
It's generally advised to follow the install docs on the wiki.
https://wiki.zoneminder.com/Helpful_use ... _Procedure

If you've customized your setup in any way this might be why you're seeing problems. However, I have confirmed that Zoneminder runs on libre distributions such as Trisquel, as well as other init systems such as Devuan, so it is not fragile by any means. I have heard of gotchas with container based systems.
User avatar
iconnor
Posts: 2900
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Commands won't run from filters

Post by iconnor »

Let's get back to the problem at hand, the command doesn't seem to be running.

ZM is showing you exactly the command it is trying to run. Perhaps there is some output that could shed some light. Try running the command from the command line and see what happens.

You will have to run it as the www-data user, as that is what ZM will be running it as.

sudo su -s/bin/bash -c"'python /usr/local/bin/IPCam_Restart_Scripts/RB_Robox3.py /usr/share/zoneminder/www/events/1/17/10/25/06/28/49" www-data
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

Apologies for the delay - been away.

I don't get this. Who is the www-data user? Is that a user? How do I find out what users there are on my system (I thought there was just me and root).
I'm happy to try the line, but I don't understand what it is supposed to do.

All best

Mark
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

I tried going down the API route, but fell at the first hurdle with curl (it works finr from a browser but that's not much use for me).

I tried:
curl -d "username='********'&password='**********'&action=login&view=console" -c cookies.txt https://localhost/zm/index.php
I get the errors:
curl: (6) Could not resolve host: username='*******'&password='***********'&action=login&view=console
curl: (51) SSL: certificate subject name (SUNFIRE) does not match target host name 'localhost'

All best

Mark
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

Re: Commands won't run from filters

Post by snake »

empty01 wrote: Thu Nov 23, 2017 9:43 pm I don't get this. Who is the www-data user? Is that a user? How do I find out what users there are on my system (I thought there was just me and root).
You may want to do a web search on "linux users and groups", and another on "www-data user linux". You are lacking fundamental knowledge of GNU/Linux that would help you. Another way to obtain basic knowledge is to install Gentoo. You could also install a LAMP stack from scratch to understand better how Zoneminder works with Apache. Many users have already done this, so take it for granted.

The API is failing because you are using curl to https, not http. Forget about the API.

It's amazing you can write a python script but don't know about www-data. Never too late to learn, though.
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

I've learnt on a need to know basis. So i've been using unix for 30 years, have published several pieces of python software, and now mainly write in C++ (all in an academic setting), but have never been formally taught any, so I guess my knowledge is good in places, but poor in others, and poorly structured.
Anyway, will check those out.
So will curl simply not work with https? I set up some redirect so that all http traffic is redirected to https - was that a bad idea?
Since Filters can detect signal alarms, and since my python onvif scripts do work (i.e. restart the cameras when needed), using them does seem to be the best route - will go deeper.
Many thanks
Mark
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

Wow! So many users! So many groups!
More groups than users - who would have thought it?
The fog is beginning to clear - thanks
empty01
Posts: 50
Joined: Tue Mar 28, 2017 1:30 pm

Re: Commands won't run from filters

Post by empty01 »

So tried:
sudo su -s/bin/bash -c"python /home/mark/python-onvif/IPCam_Restart_Scripts/RB_Robox3.py " www-data

and got:

[Errno 13] Permission denied

so yes, it seems www-data doesn't have permission to run my python scripts.

But i'm still confused as I did chmod 777 on the target file. Does 'everyone' not mean 'everyone'?
Or is it python that www-data doesn't have permission to access?

What's the best fix? Use chown to make the scripts owned by www-data? Or some group reassignment?
All best

Mark
Locked