Check if a site is still working

Post Reply
Posts: 1448
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo

Check if a site is still working

Post by dannybloe » Monday 16 April 2018 19:32

Howdee folks,

I have a couple of webservers running and at some point one of them was not working anymore so I thought it was about time to do some regular monitoring. Of course there are plenty solutions out there but I though: let's do it with dzVents. And... turns out it is very simple to do.

So, I started by creating a dummy switch 'mySiteA' that will represent the state of my website A. If the switch is Off then... well.. the site is down. I also create a switch 'testSite' so I can manually trigger a test. Then I created this script:

Code: Select all

return {
	on = {
		timer = { 'at 09:00' },
		devices = { 'testSite' },
		httpResponses = { 'mySite'}
	execute = function(domoticz, item)

		if (item.isTimer or item.isDevice) then 
			-- start the test
			domoticz.openURL({ url = 'http://mysite', callback = 'mySite', method = 'GET' })
		if (item.isHTTPResponse) then 		    
			if (item.ok) then'Web server status', 'mySite is active', '')
			else'Web server status', 'mySite is down', '')
Of course this is a simple test and it tests only one site. But you can test many sites like this and you can adjust the timer to check every hour or whatever. Also, in this case I do a simple GET request but you can also do POST requests for instance if you want to test if a contact form actually works. In the example above I test for for the ok response but you can inspect all response headers or the returned data.

Oh, and the switch mySite is just there so you can see in Domoticz the state of your site as well. In case you missed the email (you might create a script to test that as well if this is the case ;-) )
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests