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.
curious
Posts: 136
Joined: Saturday 02 April 2016 19:38
Target OS: -
Domoticz version:
Contact:

check domoticz with monit and restart when check fails

Post by curious » Thursday 26 October 2017 20:26

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: 1463
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by jvdz » Thursday 26 October 2017 20:53

Shouldn't this:

Code: Select all

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

Code: Select all

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

curious
Posts: 136
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 » Friday 27 October 2017 9:28

@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: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 10:45

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: 136
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 » Friday 27 October 2017 12:00

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 2841 times

mark.sellwood
Posts: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 12:53

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: 136
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 » Friday 27 October 2017 14:30

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: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 15:01

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: 136
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 » Friday 27 October 2017 15:12

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: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 15:50

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: 136
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 » Friday 27 October 2017 16:57

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: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 18:22

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: 136
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 » Friday 27 October 2017 20:27

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: 56
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: check domoticz with monit and restart when check fails

Post by mark.sellwood » Friday 27 October 2017 21:30

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: 136
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 » Friday 27 October 2017 21:54

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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: check domoticz with monit and restart when check fails

Post by Andyf66 » Monday 18 June 2018 19:06

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: 491
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: check domoticz with monit and restart when check fails

Post by jake » Monday 18 June 2018 19:48

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: 1345
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by waaren » Monday 18 June 2018 19:55

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 xxxxxx@pomail.net
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 xxxxxxxxxx@pomail.net 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 xxxxxxxxx@pomail.net 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 xxxxxxx@pomail.net with reminder on 10 cycles
    
    
#end
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

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 » 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"
}
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: 1345
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: check domoticz with monit and restart when check fails

Post by waaren » Thursday 09 August 2018 20:24

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"
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests