Advanced network monitoring

Moderator: leecollings

Post Reply
franzelare
Posts: 141
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Advanced network monitoring

Post by franzelare »

I have combined a few scripts in Domoticz to monitor my network performance that I like to share.

This is the floorplan with all my network vitals displayed in one quick overview
floorplan.jpg
floorplan.jpg (206.32 KiB) Viewed 5174 times
Checking if network devices are online
I have multiple scripts runing, first the ARP scan to detect if devices are on or off, this way you don't have to know the IP of the devices in your network and can use a DHCP server.
This script is based on this topic on domoticz forum: viewtopic.php?f=23&t=5256
I have 3 user variable strings with the mac addresses and device ID's with it.

The Lua time script runing in domoticz
Spoiler: show

Code: Select all

-- source https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

PRINT_MODE = false					-- when true wil print output to log and send notifications
 

    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

    function CheckMac(maclist)
        Lines=splitString(maclist,"|")
        for i,line in pairs(Lines) do
            macs=splitString(line,";")
            if PRINT_MODE == true then
                print ("MAC Address to Poll: "..macs[1].." On IDX:"..macs[2])
            end
            execcommand="sudo /home/pi/domoticz/scripts/bash/Check_MAC.sh "..macs[1].." "..macs[2].." &"
            os.execute(execcommand)
        end
    end

    commandArray = {}
    if PRINT_MODE == true then
        print ("Checking presence list 1")
    end
    list1= uservariables['PRESENCE_LIST1']
    CheckMac(list1)


    if PRINT_MODE == true then
        print ("Checking presence list 2")
    end
    list2= uservariables['PRESENCE_LIST2']
    CheckMac(list2)
    
    if PRINT_MODE == true then
        print ("Checking presence list 3")
    end
    list3= uservariables['PRESENCE_LIST3']
    CheckMac(list3)
The bash scripts it is calling out to:
Spoiler: show

Code: Select all

    #!/bin/bash
    MAC=$1
    IDX=$2

    sudo arp-scan --localnet | grep -e $MAC

    if [ $? -eq 1 ]
    then
    echo "Device $MAC Not in LOCAL LAN"
    curl "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=$IDX&switchcmd=Off"
    else
    echo "Device $MAC in LOCAL LAN"
    curl "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=$IDX&switchcmd=On"
    fi
Mysensor node online detection
For my mysensor units I have a watchdog script runing, that sends an on switch command to every mysensor unit (ESP units over WiFi and NRF24 units over the mysensor network mesh) every unit responds by toggeling the switch off again so I know the unit is still alive. For the ESP units I have a timeout of 1 minute in the hardware configuration in domoticz, so it will try to re-connect if there is no response to the heartbeat ChildID and on the mysensor nodes I have one output pin to pull the reset to ground in case no heartbeat ID is received for 5 minutes. with this watchdog script I assume a node to be dead when I miss 2 heartbeats, so I miss one and cannot connect again within 1 minute, meaning the node has crashed and need to wait until the watchdog timer on the unit runs out and a hard reset is done... (soft resets fail often on the ESP units) I also track failing nodes in a log file on the server.
for details see my post in this topic on the hardware and code: viewtopic.php?f=42&t=9775
Spoiler: show

Code: Select all

commandArray = {}

PRINT_MODE = false		-- when true wil print output to log and send notifications

function timedifference (s)
  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)
  t1 = os.time()
  t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
  difference = os.difftime (t1, t2)
  return difference
end

LastupdateESPstalletje = otherdevices_lastupdate['HeartbeatESPStalletje']
ESPStaldifference=timedifference (LastupdateESPstalletje)
	if PRINT_MODE == true then
	    print('Lastupdate ESP stalletje ' .. LastupdateESPstalletje)
        print('Time difference ' .. ESPStaldifference)
    end
    
if (ESPStaldifference>=130 and otherdevices['ESPStalletjeAlive'] == 'On')then
    commandArray['ESPStalletjeAlive'] = 'Off'
    if PRINT_MODE == true then
        print('Lost connection with ESP Stalletje')
    end    
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP stalletje connection lost" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end
if (ESPStaldifference<=130 and otherdevices['ESPStalletjeAlive'] == 'Off')then
	if PRINT_MODE == true then
        print('ESP stalletje is a live again')
    end
    commandArray['ESPStalletjeAlive'] = 'On'
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP stalletje connection operational again" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end


LastupdateESPIR = otherdevices_lastupdate['HeartbeatESPIRRemote']
ESPIRdifference=timedifference (LastupdateESPIR)
	if PRINT_MODE == true then
	    print('Lastupdate ESP IR Remote ' .. LastupdateESPIR)
        print('Time difference ' .. ESPIRdifference)
    end
    
if (ESPIRdifference>=130 and otherdevices['ESPIRAlive'] == 'On') then
    commandArray['ESPIRAlive'] = 'Off'
    if PRINT_MODE == true then
        print('Lost connection with ESP IR Remote')
    end    
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP IR Remote connection lost" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end
if (ESPIRdifference<=130 and otherdevices['ESPIRAlive'] == 'Off')then
	if PRINT_MODE == true then
        print('ESP IR Remote is a live again')
    end
    commandArray['ESPIRAlive'] = 'On'
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP IR Remote connection operational again" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end

LastupdateESPGSR = otherdevices_lastupdate['GSRHEARTBEAT']
ESPGSRdifference=timedifference (LastupdateESPGSR)
	if PRINT_MODE == true then
	    print('Lastupdate ESP GSR ' .. LastupdateESPGSR)
        print('Time difference ' .. ESPGSRdifference)
    end
    
if (ESPGSRdifference>=130 and otherdevices['ESPGSRAlive'] == 'On') then
    commandArray['ESPGSRAlive'] = 'Off'
    if PRINT_MODE == true then
        print('Lost connection with ESP GSR')
    end    
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP GSR connection lost" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end
if (ESPGSRdifference<=130 and otherdevices['ESPGSRAlive'] == 'Off')then
	if PRINT_MODE == true then
        print('ESP GSR is a live again')
    end
    commandArray['ESPGSRAlive'] = 'On'
    CurrentTime=os.date("%Y-%m-%d %H:%M:%S")
    file = io.open("/home/pi/domoticz/www/log/MysensorWatchdog.log", "a")
        io.output(file)
        io.write(CurrentTime.. " Mysensor ESP GSR connection operational again" .. "\n")
        io.close(file)
    	if PRINT_MODE == true then
            print('Writing to error log')
        end
end

-- send watchdog signals to mysensor gateway's
            commandArray['HeartBeatBedLight'] = 'On'
            commandArray['HeartbeatESPStalletje'] = 'On'
            commandArray['HeartbeatArduinoVoordeur'] = 'On'

            commandArray['GSRHEARTBEAT'] = 'On'
            commandArray['GSLHEARTBEAT'] = 'On'
            commandArray['GWRHEARTBEAT'] = 'On'
            commandArray['GWLHEARTBEAT'] = 'On'

            commandArray['HeartbeatESPIRRemote'] = 'On'
--            commandArray['HeartbeatESPVerwarming'] = 'On'
--            commandArray['HeartbeatESPRGB'] = 'On'
return commandArray
Ping times inside my network
Secondly I run a Ping script for the main devices in my network that have a fixed IP, like ESP units that run as Mysensor nodes and my switches and network drives.
This is derrived from the arp scan script and this topic on the domoticz forum: viewtopic.php?f=38&t=13421
This is the time based lua script runing in domoticz
Spoiler: show

Code: Select all

PRINT_MODE = false					-- when true wil print output to log and send notifications
 

    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


    function CheckIP(IPlist)
        Lines=splitString(IPlist,"|")
        for i,line in pairs(Lines) do
            IP=splitString(line,";")
            if PRINT_MODE == true then
                print ("Check if device is on to ping : "..IP[2])
            end
            pingdevice = tostring(IP[2])
            if otherdevices [pingdevice] == 'On' then
                if PRINT_MODE == true then
                    print ("Device " ..IP[2].. " is on")
                    print ("IP Address to Poll: "..IP[1].." With 3 counts for IDX "..IP[3])
                end
                execcommand="sudo /home/pi/domoticz/scripts/bash/ping.sh " ..IP[1].." 3 "..IP[3].." &"
                os.execute(execcommand)
            else
                if PRINT_MODE == true then
                    print ("Device " ..IP[2].. " is off")
                end
            end
        end        
    end

    commandArray = {}
    if PRINT_MODE == true then
        print ("Checking ping list 1")
    end
    list1= uservariables['PING_LIST1']
    CheckIP(list1)


    if PRINT_MODE == true then
        print ("Checking ping list 2")
    end
    list2= uservariables['PING_LIST2']
    CheckIP(list2)

    if PRINT_MODE == true then
        print ("Checking ping list 3")
    end
    list3= uservariables['PING_LIST3']
    CheckIP(list3)
The bash script it is calling out to
Spoiler: show

Code: Select all

host=$1

count=$2

idx=$3

name=$4

domoticz=127.0.0.1

multiply=1000



value=`ping -c $count $host | awk -F '/' 'END {print $5}'`

value2=$(echo "$value*$multiply" | bc)

value3=${value2%.*}

echo "$4 $value3"

curl "$domoticz:8080/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$value3"
Uptime tracking of network devices
For some devices I also want to know the uptime, since I'm suffering from devices in my network loosing communication, so I track the time decives are on with a custom counter and a lua script runing from domoticz.
This script is based on this forum topic: viewtopic.php?f=38&t=11985
Spoiler: show

Code: Select all

-- this script is to detect Uptime of devices in domoticz
-- based on the script of mvzut that can be found here on the forum 
-- https://www.domoticz.com/forum/viewtopic.php?f=38&t=11985
-- this has to be a time based lua script in domoticz (as device script this will not work)

-- for every device to monitor a counter has to be created as virtual devicecount
-- Create an custom counter using the Dummy hardware component (first add this component if you haven't already done so before, using Setup>Hardware). 
-- Then go to the Utility section, change the type of your new counter from Energy to Counter, and fill in the Value Quantity (e.g. "On time") and Value Units ("Minutes"). 
-- Check the Device ID (idx) that is given to the new counter device.

-- this script can be run in combination with an ping, bluetooth scan or an arp scan what is in some cases more reliable
    -- ping: https://www.domoticz.com/wiki/Presence_detection
    -- bluetooth: https://www.domoticz.com/wiki/Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)
    -- arp scan: https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

-- define general script values
devicecount = 8                     -- number of deviced to be cheked by the script for on time
PRINT_MODE = false					-- when true wil print output to log and send notifications

-- create a table to store device information
devicetable = {}

-- Device 1
device = 1
devicetable["name" .. device] = 'KPN Modem'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime KPN Modem'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 368                       -- idx of the counter created for this device

-- Device 2
device=2
devicetable["name" .. device] = 'Pi2Heating'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime Pi2Heating'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 369                      -- idx of the counter created for this device

-- Device 3
device=3
devicetable["name" .. device] = 'ESPIRAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime IR remote'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 370                       -- idx of the counter created for this device

-- Device 4
device=4
devicetable["name" .. device] = 'ESPStalletjeAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime Schuur'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 371                       -- idx of the counter created for this device

-- Device 5
device=5
devicetable["name" .. device] = 'ESPGSRAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime ESP GSR'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 372                       -- idx of the counter created for this device

-- Device 6
device=6
devicetable["name" .. device] = 'ESPGSLAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime ESP GSL'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 373                       -- idx of the counter created for this device

-- Device 7
device=7
devicetable["name" .. device] = 'ESPGWRAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime ESP GWR'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 374                       -- idx of the counter created for this device

-- Device 8
device=8
devicetable["name" .. device] = 'ESPGWLAlive'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'Uptime ESP GWR'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 375                       -- idx of the counter created for this device





commandArray = {}
for i=1,devicecount do
    if otherdevices[devicetable["name" .. i]] == 'On' then
	    TotalMinutesUp = tonumber(otherdevices_svalues[devicetable["timer" .. i]])
    	TotalMinutesUpNew = TotalMinutesUp + 1
    	TimerID = tonumber(devicetable["ID" .. i])
            execcommandUp="sudo /home/pi/domoticz/scripts/bash/SetCounter.sh "..TimerID.." "..TotalMinutesUpNew.." &"
            os.execute(execcommandUp)
            
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device name detected On :' .. devicetable["name" .. i])
            print('Device name On timer :' .. devicetable["timer" .. i])
            print('Device ID timer counter :' .. TimerID)
            

		    print('Previous Uptime: ' .. TotalMinutesOn)
		    print('New Uptime: ' .. TotalMinutesOnNew)
        end
    elseif otherdevices[devicetable["name" .. i]] == 'Off' then
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected Off: ' .. devicetable["name" .. i])
            print('Resetting uptimer to 0')
            Reset=0
            execcommandUp="sudo /home/pi/domoticz/scripts/bash/SetCounter.sh "..TimerID.." "..Reset.." &"
            os.execute(execcommandUp)
        end
    else
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device ERROR: ' .. devicetable["name" .. i])
        end
    end

end

return commandArray
Since I want to update multiple customer counters, i need to do this through a bash script, since lua in domoticz will only update the last custom device called out to.
Spoiler: show

Code: Select all

    #!/bin/bash
    IDX=$1
    COUNT=$2
	curl "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=$COUNT"
Ontime tracking of devices in my network
Last I want to monitor ontime for some devices, just to see how often the phones, TV and so on is switched on... just because I can...
Spoiler: show

Code: Select all

-- this script is to detect on time of devices in domoticz
-- based on the script of mvzut that can be found here on the forum 
-- https://www.domoticz.com/forum/viewtopic.php?f=38
-- this has to be a time based lua script in domoticz (as device script this will not work

-- for every device to monitor a counter has to be created as virtual devicecount
-- Create an incremental counter using the Dummy hardware component (first add this component if you haven't already done so before, using Setup>Hardware). 
-- Then go to the Utility section, change the type of your new counter from Energy to Counter, and fill in the Value Quantity (e.g. "On time") and Value Units ("Minutes"). 
-- Check the Device ID (idx) that is given to the new counter device.

-- this script can be run in combination with an ping, bluetooth scan or an arp scan what is in some cases more reliable
    -- ping: https://www.domoticz.com/wiki/Presence_detection
    -- bluetooth: https://www.domoticz.com/wiki/Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)
    -- arp scan: https://www.domoticz.com/forum/viewtopic.php?f=23&t=5256

-- define general script values
devicecount = 11                     -- number of deviced to be cheked by the script for on time
PRINT_MODE = false					-- when true wil print output to log and send notifications

-- create a table to store device information
devicetable = {}

-- Device 1
device = 1
devicetable["name" .. device] = 'FransMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 237                       -- idx of the counter created for this device

-- Device 2
device=2
devicetable["name" .. device] = 'SusanMobiel'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanMobielTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 238                       -- idx of the counter created for this device

-- Device 3
device=3
devicetable["name" .. device] = 'FransTablet'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransTabletTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 239                       -- idx of the counter created for this device

-- Device 4
device=4
devicetable["name" .. device] = 'SusanTablet'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanTabletTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 240                       -- idx of the counter created for this device

-- Device 5
device=5
devicetable["name" .. device] = 'FransPC'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'FransPCTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 241                       -- idx of the counter created for this device

-- Device 6
device=6
devicetable["name" .. device] = 'SusanPC'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SusanPCTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 242                       -- idx of the counter created for this device

-- Device 7
device=7
devicetable["name" .. device] = 'SonyBlueRay'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'SonyBlueRayTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 243                       -- idx of the counter created for this device

-- Device 8
device=8
devicetable["name" .. device] = 'ITV receiver'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ITV receiverTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 244                       -- idx of the counter created for this device


-- Device 9
device=9
devicetable["name" .. device] = 'ASM-Lan'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ASM-LanTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 245                       -- idx of the counter created for this device

-- Device 10
device=10
devicetable["name" .. device] = 'ASM-Wifi'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ASM-WifiTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 246                       -- idx of the counter created for this device

-- Device 11
device=11
devicetable["name" .. device] = 'Chromecast'           -- exact name of the device to be checked for on time
devicetable["timer" .. device] = 'ChromecastTimer'     -- exact name of the counter created for this device
devicetable["ID" .. device] = 247                       -- idx of the counter created for this device



commandArray = {}
for i=1,devicecount do
    if otherdevices[devicetable["name" .. i]] == 'On' then
	    TotalMinutesOn = tonumber(otherdevices_svalues[devicetable["timer" .. i]])
    	TotalMinutesOnNew = TotalMinutesOn + 1
    	TimerID = tonumber(devicetable["ID" .. i])
--	    commandArray['UpdateDevice'] =  TimerID .. '|0|' .. tonumber(TotalMinutesOnNew)
            execcommandOn="sudo /home/pi/domoticz/scripts/bash/SetCounter.sh "..TimerID.." "..TotalMinutesOnNew.." &"
            os.execute(execcommandOn)
            
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device name detected On :' .. devicetable["name" .. i])
            print('Device name On timer :' .. devicetable["timer" .. i])
            print('Device ID timer counter :' .. TimerID)
            

		    print('Previous on time: ' .. TotalMinutesOn)
		    print('New on time: ' .. TotalMinutesOnNew)
        end
    elseif otherdevices[devicetable["name" .. i]] == 'Off' then
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device detected Off: ' .. devicetable["name" .. i])
            print('No update of the timer needed')
        end
    else
        if PRINT_MODE == true then
            print('Device sequence: ' .. i)
            print('Device ERROR: ' .. devicetable["name" .. i])
        end
    end

end

return commandArray
Reboot scripts
For the domoticz servers I use them to do a crosscheck if domoticz is still runing and if not reboot the server, since just restarting domoticz is not always working. I do this with a time based lua script on both servers
Spoiler: show

Code: Select all

PRINT_MODE = false					-- when true wil print output to log and send notifications

commandArray = {}
    if PRINT_MODE == true then
        print ("Checking if heating Pi 2 is online")
    end
        execcommand="sudo /home/pi/domoticz/scripts/bash/CheckOnline.sh"
        os.execute(execcommand)
return commandArray
calling out for the following bash script
Spoiler: show

Code: Select all

#!/bin/sh
# check domoticz
status=`curl -s -i -H "Accept: application/json" "http://192.168.2.141:8080/json.htm?type=devices&rid=1" | grep "status"| awk -F: '{print $2}'|sed 's/,//'| sed 's/\"//g'`
if [ $status ]
then
echo "Domoticz draait nog"
else
echo "Domoticz draait niet meer, rebooting server"
curl "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=146&switchcmd=On"
sshpass -p 'xxxxxxxx' ssh [email protected] 'sudo reboot'
fi
sshpass you have to login manually first to accept the key presented, but after that it will run from the script
The script switches a virtual switch to let me know it rebooted the other server, in the startup script of the other server it sends an off command again so I can see in the logging that the reboot was successful
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Advanced network monitoring

Post by emme »

I love it!!!!!! :o :o :o :o :o :o :o :o
The most dangerous phrase in any language is:
"We always done this way"
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Advanced network monitoring

Post by sincze »

Whaaaah nice

Sent from my SM-G925F using Tapatalk
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: Advanced network monitoring

Post by korniza »

Nice! I have a similar plan but I use Alert sensors as I do not need the real values of ping response and get a better visualisation as alert sensor has 3 states (green,orange,red)
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest