I have 2 domoticz servers.
I want to make sure both are running. I want to receive an alert when one of them is down.
I want to accomplish this from within domoticz.
What is the easiest way to accomplish this?
As far as my knowledge goes: the most logical method todo this, would be to do a HTTP check to one another and based on response code send an alert.
Or maybe this can be done through the remote server option?
Lua is also an option but i want the most easy way.
Monitoring external Domoticz servers
Moderators: leecollings, remb0
-
- Posts: 25
- Joined: Friday 07 November 2014 19:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Monitoring external Domoticz servers
I eventually fixed this by sharing a device between the two domoticz instances (CPU percentage) and then i used LUA to see if that device has been available during the last 15 minutes.
If not:Send a notification.
If not:Send a notification.
Code: Select all
-- script_time_failoverpi.lua
t1 = os.time()
s = otherdevices_lastupdate['FailoverCPU']
-- returns a date time like 2013-07-11 17:23:12
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
commandArray = {}
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (difference > 900 and difference < 1000) then
commandArray['SendNotification']='Failover PI#FailoverPI een kwartier niet meer gemeten'
end
return commandArray
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: Monitoring external Domoticz servers
Nice simple specific solution.alttab wrote:I eventually fixed this by sharing a device between the two domoticz instances (CPU percentage) and then i used LUA to see if that device has been available during the last 15 minutes.
If not:Send a notification.
Reading your solution, I realise I am doing the same thing in a more complicated but also more flexible way.
I have adapted the referenced forum post code which uses arp-scan to retrieve the MAC addresses of all the devices on my network once every minute, on my Raspberry Pi 1 B this only takes 3 seconds no matter how many devices you want to check for (I currently check for 20). In your case obviously you only want to check for 2 devices or even 1 on each Domoticz instance and then similar to your solution the switch notification lets me know when critical devies are not available.
Code: Select all
-- script_time_devices.lua
-- derived from https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256
-- For each device you want to check create a Domoticz dummy switch - DeviceName1 etc. DeviceName2
-- Then create a string uservariable called DeviceList which contains "mac address;First Device Name;0|mac address;Second Device Name;0"
-- without the quotes, so for example
-- 01:02:03:04:AB:CD:EF:00;House Domoticz;0|02:03:04:05:AB:CD:EF:00;Garden Domoticz;0
-- The script will change the switch to on when device is present on the network and to off when no present
-- Use notification on switch to be alerted to changes
function splitString(str, delim, maxNb)
-- Eliminate bad cases...
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gmatch(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
-- Handle the last field
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
commandArray = {}
--Get the list of devices to check on
devicelist = uservariables['DeviceList']
-- String type uservariables only store 256 characters so if you have more devices then just append multiple variable together
devicelist = uservariables['DeviceList1'] .. '|' .. uservariables['DeviceList2'] .. '|' .. uservariables['DeviceList3']
--Do an arp-scan on the localnet
--and search for the mac adresses
if devicelist ~= nil then
local newdevicelist =""
local currenttime = os.time()
local outdoorsdelay = 0
--do the arp scan and store the result
-- local command = "sudo arp-scan --interface=eth0 192.168.xxx.1-192.168.xxx.yyy --retry=5 --ignoredups"
local command = "sudo arp-scan --localnet --retry=5 --ignoredups"
local handle = io.popen(command)
local result = handle:read("*all")
handle:close()
--print(result)
--Get a list of all devices
devices=splitString(devicelist,"|")
--Search arp-scan result for presence of MAC for each device
for i,line in pairs(devices) do
--print('Devices List')
--print(line)
--Get the data for this device
device=splitString(line,";")
--and the switch state
switchstate = otherdevices[device[2]]
--Fill a new list with devices
if i > 1 then newdevicelist = newdevicelist.."|" end
newdevicelist = newdevicelist..device[1]..";"..device[2]
-- If device detected write current time and switch on
-- else switch off after the given delay time
if string.find(result, string.lower(device[1])) ~= nil then
device[3] = currenttime
if string.lower(switchstate) == 'off' then
commandArray[device[2]] = 'On'
end
else
if tonumber(currenttime) > (tonumber(device[3]) + outdoorsdelay) and string.lower(switchstate) == 'on' then
commandArray[device[2]] = 'Off'
print(device[2].."; now:"..os.date("%Y-%m-%d %H:%M:%S", currenttime).."; last seen: "..os.date("%Y-%m-%d %H:%M:%S",tonumber(device[3])))
end
end
newdevicelist = newdevicelist..";"..device[3]
end
--print(newdevicelist)
commandArray['Variable:DeviceList']= newdevicelist
else
print("Uservariable 'DeviceList' not found!")
end
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 25
- Joined: Friday 07 November 2014 19:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Monitoring external Domoticz servers
The problem with mac adresses is: it says nothing about domoticz.
It says only that the server has a network connection.
I have noticed Domoticz crashes some times in an older version, and with a defective power supply.
This would go unnoticed when i would check only for mac adresses.
It says only that the server has a network connection.
I have noticed Domoticz crashes some times in an older version, and with a defective power supply.
This would go unnoticed when i would check only for mac adresses.
Who is online
Users browsing this forum: No registered users and 1 guest