Page 1 of 2

check domoticz with monit and restart when check fails

Posted: Thursday 26 October 2017 20:26
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

Re: check domoticz with monit and restart when check fails

Posted: Thursday 26 October 2017 20:53
by jvdz
Shouldn't this:

Code: Select all

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

Code: Select all

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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 9:28
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]

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 10:45
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): ?

Re: check domoticz with monit and restart when check fails

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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 12:53
by mark.sellwood
Try replacing 127.0.0.* with 127.0.0.1

Re: check domoticz with monit and restart when check fails

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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 15:01
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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 15:12
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 ?

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 15:50
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.

Re: check domoticz with monit and restart when check fails

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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 18:22
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

Re: check domoticz with monit and restart when check fails

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

Re: check domoticz with monit and restart when check fails

Posted: Friday 27 October 2017 21:30
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

Re: check domoticz with monit and restart when check fails

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

Re: check domoticz with monit and restart when check fails

Posted: Monday 18 June 2018 19:06
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"

Re: check domoticz with monit and restart when check fails

Posted: Monday 18 June 2018 19:48
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.

Re: check domoticz with monit and restart when check fails

Posted: Monday 18 June 2018 19:55
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

Re: check domoticz with monit and restart when check fails

Posted: Thursday 09 August 2018 19:29
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

Re: check domoticz with monit and restart when check fails

Posted: Thursday 09 August 2018 20:24
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"