check domoticz with monit and restart when check fails Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

check domoticz with monit and restart when check fails

Post by curious »

I installed monit to check my raspberry and particular domoticz because I often have to restart the domoticz service
I use code below in monit config to restart domoticz when "things" go wrong.
The code runs fine only the check fails :
url http://127.0.0.1:8080/json.htm?type=com ... getversion
and content = '"status" : "OK"'

Does it always have to be 127.0.0.1:8080 or should it be an other ip-address (my domoticz ip for example) ?

Code: Select all

check process domoticz with pidfile /var/run/domoticz.pid
 start program = "/etc/init.d/domoticz.sh start"
 stop program = "/etc/init.d/domoticz.sh stop"
 if failed
 url http://127.0.0.1:8080/json.htm?type=command&param=getversion
 and content = '"status" : "OK"'
 for 2 cycles
 then restart
 if 5 restarts within 5 cycles then exec "/sbin/reboot"
if cpu usage > 70% for 3 cycles then restart
I am using Raspberry 2
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by jvdz »

Shouldn't this:

Code: Select all

and content = '"status" : "OK"'
be :

Code: Select all

 and content == '"status" : "OK"'
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

@Jos

I don't know. It's not what is in the downloaded code.
But should 127.0.0.1 be correct ? I can ping this address by the way but when adding portnumber it says host unknown


This is the error message :
connection failed to 127.0.0.1:8080/json.htm?type=command¶m=getversion [HTTP via TCP]
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

My monit config contains the following:-

# Monitor Domoticz
check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
url http://127.0.0.1:8080/json.htm?type=com ... getversion
and content = '"status" : "OK"'
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
#
In Domoticz on the Settings Tab do you have 127.0.0.1 entered under Local Networks (no username/password): ?
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

I indeed forgot to add the ip-address, but now I did, the errors remains.

'domoticz' failed protocol test [HTTP] at INET[127.0.0.1:8080/json.htm?type=command&param=getversion] via TCP -- HTTP error: Regular expression doesn't match: No match
Attachments
Knipsel.JPG
Knipsel.JPG (22.45 KiB) Viewed 8368 times
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

Try replacing 127.0.0.* with 127.0.0.1
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

mark.sellwood wrote: Friday 27 October 2017 12:53 Try replacing 127.0.0.* with 127.0.0.1
Still the same error
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

Are you sure the web interface is running on port 8080?

From another computer on your network what do you get if you enter:-
http://x.x.x.x:8080/json.htm?type=comma ... getversion
Where x.x.x.x is the IP of you Domoticz computer
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

I was pretty sure about that :) but checking doesn't harm.
The results are :
{
"DomoticzUpdateURL" : "http://www.domoticz.com/download.php?ch ... ine=armv7l",
"HaveUpdate" : false,
"Revision" : 8153,
"SystemName" : "linux",
"build_time" : "2017-07-30 12:19:41",
"hash" : "494fff7",
"status" : "OK",
"title" : "GetVersion",
"version" : "3.8153"
}

In the file I have this line of code too:

Code: Select all

allow 10.0.0.4/10.0.0.255        # allow localhost to connect to the server and
Should I add some other ip-addresses ?
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

I don't think the allow statement is correct from memory, I'll have a look at my config when I'm back at home later today.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

The IP-range of my local network is from 10.0.0.1-10.0.0.255
The code of the 'allow'-part :

Code: Select all

set httpd port 2812 and
 use address 10.0.0.12  # only accept connection from localhost

   allow 10.0.0.4/10.0.0.255        # allow localhost to connect to the server and
   allow admin:monit      # require user 'admin' with password 'monit'
    allow @monit           # allow users of group 'monit' to connect (rw)
    allow @users readonly  # allow users of group 'users' to connect readonly
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

My allow is:-

Code: Select all

    allow 192.168.1.0/24        # allow localhost to connect to the server and
So I think yours should be:-

Code: Select all

   allow 10.0.0.0/24
Did you try the command

Code: Select all

sudo monit -t
This should check your config file & tell you if there are any errors.

Remember to restart monit with

Code: Select all

sudo service monit reload
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

After changing the allow- line it seems to work now.
Correct me if I am wrong but the example code is not very clear.

However, thank you for your help.

EDIT : Does not work after al. I forgot to uncomment some lines. And after that the same error-message returned.
Will try to play with some ip adresses in the allow-line.
Syntax is OK
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood »

Hi,

I think the Wiki needs to be updated as things have changed in monit. I'm rebuilding my systems at present & I know I had to change my existing config as it didnt work.

Below is my config for the webserver bit

Code: Select all

Configure Webservice
	set httpd port 2812 and
   	 use address 127.0.0.1  # only accept connection from localhost
   	 allow 192.168.1.0/24        # allow localhost to connect to the server and
   	 allow admin:monit     # require user 'admin' with password 'monit'
   	 allow @monit           # allow users of group 'monit' to connect (rw)
   	 allow @users readonly  # allow users of group 'users' to connect readonly
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
curious
Posts: 132
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by curious »

Still doesn't work and as I am not a script specialist I only can rely on whats in the wiki.

So i am afraid it ends for me here. Monitor runs fine now, and I will keep watching it so now and then to see if there is something special
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by Andyf66 »

The monitor check seems to be failing at the moment on raspberry pi due to the '&' in the URL, which isn't being escaped and breaks syntax. I fixed it by changing the monitrc file to look like this:

check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"

if failed host 127.0.0.1 port 80 protocol http
and request "/json.htm?type=command&param=getversion"
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: check domoticz with monit and restart when check fails

Post by jake »

Sometimes Domoticz is acting weird with the & sign in the url.
You can try a quick work-around as I have successfully done as well in this topic: viewtopic.php?p=170057#p170057

Simply put the 'param=...' part of the url in a different order, in such a way that & isn't followed by 'p'. For the JSON command it doesn't make a difference, but it will gve you the right hyperlink without breaking it up or adding funny characters in between.

So change line 1 into line 2 to try:
http://127.0.0.1:8080/json.htm?type=com ... getversion
http://127.0.0.1:8080/json.htm?param=ge ... pe=command

I would recommond to keep for the rest the original script. In your version you're not checking for the Status = OK version, so I wonder what the script checks at the moment.
Last edited by jake on Monday 18 June 2018 19:48, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by waaren »

I check my domoticz instance using this monit check:

Code: Select all

#
# Check domoticz
#
check process Domoticz with pidfile  /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"

if not exist for 8 cycles then restart    # 8 minutes
if failed 
        url http://192.168.192.nn:nnnn/json.htm?type=command&param=getversion  # comment
        and content = '"status" : "OK"'
    for 3 cycles then restart
if memory usage > 80% then restart
if 5 restarts within 5 cycles then alert
alert [email protected]
the availability of the system itself and port 80 is checked from another system with.

Code: Select all

#
# Check PI's using ping / port
#
check host PI-1 address PI-1
if failed ping then alert
if failed port 80 protocol http then alert 
    alert [email protected] with reminder on 10 cycles

check host PI-2 address PI-2
if failed ping then alert
# if failed port 80 protocol http then alert # test system
    alert [email protected] with reminder on 10 cycles

check host PI-3 address PI-3
if failed ping then alert
# if failed port 80 protocol http  then alert  # development system
    alert [email protected] with reminder on 10 cycles
    
    
#end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Theedoek
Posts: 9
Joined: Wednesday 08 August 2018 22:09
Target OS: -
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by Theedoek »

I have the exact same thing but can't get it to work.
When I execute "http://192.168.0.100:8080/json.htm?type ... getversion" from a remote host (PC running Win10) on the same network, I get a reply containing a JSON array with data like the Domoticz version number, update url and so on.
If I execute "curl http://127.0.0.1:8080/json.htm?type=com ... getversion" from the command line (via putty), I get a

Code: Select all

{
   "status" : "ERR"
}
I have added 127.0.0.1 to the local networks list. Before I did that I used to get an access denied message.
What can be wrong here? I am dying to get this sorted out, but I am not a guru in this :D
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by waaren »

Theedoek wrote: Thursday 09 August 2018 19:29 I have the exact same thing but can't get it to work.
When I execute "http://192.168.0.100:8080/json.htm?type ... getversion" from a remote host (PC running Win10) on the same network, I get a reply containing a JSON array with data like the Domoticz version number, update url and so on.
If I execute "curl http://127.0.0.1:8080/json.htm?type=com ... getversion" from the command line (via putty), I get a

Code: Select all

{
   "status" : "ERR"
}
You could try with

Code: Select all

curl -s -X GET "http://127.0.0.1:8080/json.htm?type=command&param=getversion"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Daro1003 and 1 guest