Check if a site is still working
Posted: 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:
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
)
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' })
end
if (item.isHTTPResponse) then
if (item.ok) then
domoticz.email('Web server status', 'mySite is active', '[email protected]')
domoticz.devices('mySite').switchOn()
else
domoticz.email('Web server status', 'mySite is down', '[email protected]')
domoticz.devices('mySite').switchOff()
end
end
end
}
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
