YAP (yet another pinger)

Moderator: leecollings

Post Reply
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

YAP (yet another pinger)

Post by waaren »

Yet another pinger solution.

new version 20191031 !

Have Fun !

Code: Select all

  --[[ pinger: requires - dzVents >= 2.4, 
                       - find Operating System command available and executable by domoticz user
                       - ping Operating System command available and executable by domoticz user
                       - nmap Operating System command available and executable by domoticz user (only when also scanning TCP ports)
    
    This script checks if systems are reacting to a ping command or if a tcp port is responding with "open" to a nmap command
    The systems to be checked are in the table sites2Check.
    
    when no port(s) is/are in that the table, a standard ping is executed at the OS level and the returnCode is evaluated
    The default settings for notifications are entered in the table "defaults".
    These defaults can be overruled by entering them in the table sites2Check (see the example)
    When no message is entered in the table sites2Check, the composed Operating System command is used as message
    
    NB. silentTime "never" or "24:00"  means allways notify. (never silent = ) 
    
    The script checks the modification dates of the script and its companion datafile 
    to ensure a refresh or initialization of __data_scriptname.lua after any
    change to the script. 
    Note: After a refresh the number of fails and the isMessageSend flag are preserved.
   
   
    History
    ========
    20181026 Start coding
    20181027 First version active and shared on forum
    20181109 Bugfixes
    20181109 Script will recognize requirement to refresh datafile
    20181109 Add option to check ports (with nmap)
    20181109 Add option to suppress notifications / Email after first message of the day 
    20181109 Add option for non standard message
    20191031 Fixed bug ( t.consecutiveFailCount not initialized) 
    
 ]]--

 return {
    on      =   {   timer   = { "every 5 minutes"},   
                   devices  = { "Pinger"},                      -- Used for test / development. Can be ignored
                },
                
    logging =   {   level   = domoticz.LOG_DEBUG ,              -- Change to ERROR when script is behaving as expected  
                    marker  = ""},                              -- Will be set in execute = function block 
            
    data    =   {   sites2Check   =      { initial = {}   }},   -- Iitialize empty table

                 

 execute = function(dz,_,info)                             -- We don't use the trigger but we do need the info (for scriptName) 
        
        local sites2Check , defaults  = {}, {}             -- Initialize empty tables

        -- **************************************************************** Your settings below this line
       
        defaults  = {   messageClearTime        = "05:05",    -- must be a multiple of 5 ( or change the on = { timer - {} setting
                                                              -- Once a day the sendMessage flag must be cleared; it will happen at this time      
                        maxExecutionTime        = 3.0,        -- If multiple pings fail the script will run too long. This will 
                                                              -- ensure the script stops after maxExecutionTime seconds
                        pingWaitTime            = 1,          -- the ping command parm -w is how long the ping should wait for an answer
                                                              -- if one second is not long enough you can set it to an higher value here
                        maxFailsBeforeMessage   = 3,          -- the message will only be send after this amount of consecutive failed pings or nmaps 
                        repeatMessageAfterFails = 5,          -- number of consecutive fails before Message will be send again repeat  
                        
                        silentTime     = "23:00-07:00",       -- The time window when no messages are to be send
                        repeatMessage  = false,               -- When set to false only first message on a day will be send, 
                                                              -- when true every x fails a message will be send 
                        toLog          = true,                -- used in report (should we send message to log on failure)
                        toEmail        = false,               -- used in report (should we send message to Email on failure)
                        notify         = true,                -- used in report (should we send message to notification system on failure)
                        notifyPriority = dz.PRIORITY_NORMAL,  
                        mailAddress    = "[email protected]",
                } 
                    
     -- sites2Check.example      = {address = "192.168.193.1", toEmail = true, silentTime = "never" ,repeatMessage = true }
     -- sites2Check.example2     = {address = "RaspBerry1", port = { 80,8084,1111,8080 }, message = "nmap to port failed" }
            
    --    sites2Check.HomeWizard   = {address =  "192.168.192.61" }           -- Label, Address (dns name or IP ), defaultOverrides, port(s)
    --    sites2Check.PI2          = {address = "PI-2" }                     
        sites2Check.Google       = {address = "google-public-dns-a.google.com"}
    --    sites2Check.synology     = {address = "LM46" }

        sites2Check.router       = {    address                 = "192.168.20.1",
                                        toEmail                 = true,                              -- Overrule defaults
                                        silentTime              = "01:00-06:00",                     -- Overrule defaults
                                        notifyPriority          = dz.PRIORITY_HIGH,                  -- Overrule defaults
                                        message                 = "Ping to router failed"    -- Overrule defaults
                                   }
       
        sites2Check.test         = {    address                 = "192.168.20.32",         -- address (mandatory) , port(s) (optional)
         --                               port                    = { 82 },            -- this will cause the use of nmap 
                                        maxFailsBeforeMessage   = 5,                           -- Overrule defaults   
                                        silentTime              = "00:00-07:00",               -- Overrule defaults
                                        notifyPriority          = dz.PRIORITY_HIGH,                  -- Overrule defaults
                                   } 
        
        myNotificationTable     =  {
                                     -- table with one or more notification system. 
                                     -- uncomment the notification systems that you want to be used
                                     -- Can be one or more of
                                     
                                     -- dz.NSS_GOOGLE_CLOUD_MESSAGING, 
                                     dz.NSS_PUSHOVER,               
                                     -- dz.NSS_HTTP, 
                                     -- dz.NSS_KODI, 
                                     -- dz.NSS_LOGITECH_MEDIASERVER, 
                                     -- dz.NSS_NMA,
                                     -- dz.NSS_PROWL, 
                                     -- dz.NSS_PUSHALOT, 
                                     -- dz.NSS_PUSHBULLET, 
                                     -- dz.NSS_PUSHOVER, 
                                     -- dz.NSS_PUSHSAFER,                        
                                    }
  -- **************************************************************** No changes required below this  
  
        _G.logMarker                    = info.scriptName     -- sets the logmarker for dz.log
        local messageSendClearRequired  = dz.time.matchesRule("at " .. defaults.messageClearTime)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

        -- initialise persistent data
        local function initSites2Check()
            dz.data.sites2Check.defaults = defaults
            for system,_ in pairs(sites2Check) do                                   -- We only need the system names or IP, ports, consecutive failCount and flag isMessageSend
                dz.data.sites2Check[system] = dz.data.sites2Check[system] or {}
                if sites2Check[system].port then 
                    for i,portNumber in ipairs(sites2Check[system].port) do
                        dz.data.sites2Check[system][portNumber] = {}
                        dz.data.sites2Check[system][portNumber].consecutiveFailCount    =  
                        dz.data.sites2Check[system][portNumber].consecutiveFailCount or 0
                        dz.data.sites2Check[system][portNumber].isMessageSend             = 
                        dz.data.sites2Check[system][portNumber].isMessageSend or false
                    end
                else
                    dz.data.sites2Check[system].consecutiveFailCount    = 
                    dz.data.sites2Check[system].consecutiveFailCount or 0
                    dz.data.sites2Check[system].isMessageSend             = 
                    dz.data.sites2Check[system].isMessageSend or false
                end            
            end            
        end
        
        --Report to log and/or Email and/or noticication system
        local function report(systemName,returnCode,commandUsed,messageCount,isMessageSend)
            
            local system        = sites2Check[systemName]
            logWrite("default repeatMessage in report: " .. tostring(defaults.repeatMessage))
            logWrite(systemName .. " repeatMessage in report: " .. tostring(system.repeatMessage ))
            
            local repeatMessage             = system.repeatMessage           or defaults.repeatMessage
            local repeatMessageAfterFails   = system.repeatMessageAfterFails or defaults.repeatMessageAfterFails
            local priority                  = tonumber(system.notifyPriority or defaults.notifyPriority)
            local defaults                  = dz.data.sites2Check.defaults
            local message                   = system.message or  
                                                "osCommand ".. commandUsed .. " failed for " .. systemName .. ": ReturnCode ==>>: " .. returnCode
        
            local function doReport(str)
                local returnValue = false
                local silent  = dz.time.matchesRule("at " .. (system.silentTime or defaults.silentTime)) 
                local toLog   = system.toLog            or defaults.toLog 
                local toEmail = ( system.toEmail        or defaults.toEmail ) and not silent 
                local mailTo  = system.mailAddress      or defaults.mailAddress
                local notify  = ( system.notify         or defaults.notify ) and not silent
                            
                if toLog then logWrite(str,dz.LOG_FORCE) end
                if toEmail then 
                    dz.email(info.scriptName,str,mailTo) 
                    returnValue = true 
                end
           
                if notify then 
                    dz.notify(info.scriptName, str, priority, dz.SOUND_INTERMISSION,"",   myNotificationTable ) 
                    returnValue = true 
                end
                return returnValue
            end
            
            local messageCountFence = math.min(defaults.maxFailsBeforeMessage,system.maxFailsBeforeMessage or 99)
            
            if messageCount == messageCountFence then
                return doReport("initial: ".. message)
            elseif messageCount % repeatMessageAfterFails == 0 and repeatMessage and isMessageSend then
                return doReport("repeated: ".. message)
            elseif messageCount > messageCountFence  and messageCount % repeatMessageAfterFails == 0 and repeatMessage and not isMessageSend then
                return doReport("initial but delayed: " .. message)
            elseif isMessageSend then
               return true
            elseif messageCount < messageCountFence then
               return false
            end
        end
        
        local function osCommand(commandString)
            local fileHandle     = assert(io.popen(commandString, 'r'))
            local commandOutput  = assert(fileHandle:read('*a'))
            local returnTable    = {fileHandle:close()}
            return commandOutput,returnTable[3]                     -- returnTable[3] contains returnCode
        end
                
        local function evalReturnCode(t,returnCode,systemName,cmdString)
            if returnCode ~= 0 then
                t.consecutiveFailCount = ( t.consecutiveFailCount or 0 ) + 1
                t.isMessageSend = report(systemName,returnCode,cmdString,t.consecutiveFailCount,t.isMessageSend) 
            else
                t.consecutiveFailCount = 0
                t.isMessageSend = false
            end
        end
        
        local function fileExists(filename)
            local file = io.open(filename, "r")
            if file ~= nil then io.close(file) return true end
            return false 
        end
        
        local function getPersistentDataFileName()
            return globalvariables['script_path'] .. "data/__data_" .. info.scriptName .. ".lua"
        end
        
        local function invalidPersistentDatafile()
            local dataFile  = getPersistentDataFileName()
            if not fileExists(dataFile) then
                logWrite("initSites2Check() must be called. (file does not exist)" )
                return true
            end
            
            if fileExists(_G.generatedScriptsFolderPath ..  info.scriptName .. ".lua") then
                script = _G.generatedScriptsFolderPath ..  info.scriptName .. ".lua"
            else
                script = globalvariables['script_path'] .. "scripts/" .. info.scriptName .. ".lua"
            end

            if (select(1,osCommand("find " .. script .." -newer " .. dataFile))):find(script) then
                logWrite("initSites2Check() must be called. (script newer than datafile)" )
                return true
            end
            return false
        end

        local function clearMessageSend()
            logWrite("isMessageSend will be cleared")
            for systemName,attributes in pairs(sites2Check) do
                if attributes.address ~= nil then         -- defaults does not have an address
                    if attributes.port ~= nil then  -- Ports defined so we need to call nmap (ping cannot do this)
                        for i=1,#attributes.port do
                            attributes.port.isMessageSend = false
                            dz.data.sites2Check[systemName].port.isMessageSend = false
                        end    
                    else 
                        attributes.isMessageSend = false
                        dz.data.sites2Check[systemName].isMessageSend = false
                    end
                end
            end
            return true
        end
        
        local function isExecutionTimeTooLong(startedAt)
            return (os.clock() - startedAt) > defaults.maxExecutionTime 
        end
        
        
        -- main 
        local startedAt  = os.clock()
        if messageSendClearRequired then clearMessageSend() end
        if invalidPersistentDatafile() then initSites2Check() end
               
        for systemName,attributes in pairs(sites2Check) do
            if attributes.address ~= nil then         -- defaults does not have an address
                local cmdString 
                local message
                local system        = dz.data.sites2Check[systemName]
                if isExecutionTimeTooLong(startedAt) then logWrite("break main") break end
                if attributes.port ~= nil then  -- Ports defined so we need to call nmap (ping cannot do this)
                    for i=1,#attributes.port do
                        logWrite("ports defined; Checking " .. attributes.address .. " for port " .. attributes.port[i])
                        cmdString = "nmap " .. attributes.address .. " -p " .. attributes.port[i] .. " | grep open"
                        evalReturnCode(system[attributes.port[i]],select(2,osCommand(cmdString)),systemName,cmdString)
                        if isExecutionTimeTooLong(startedAt) then break end
                    end    
                else -- Simple ping command
                    local pingWaitTime = attributes.pingWaitTime or defaults.pingWaitTime
                    logWrite("Checking " .. attributes.address )
                    cmdString = "ping -c1 -w " .. pingWaitTime .. " >/dev/null " .. attributes.address
                    evalReturnCode(system,select(2,osCommand(cmdString)),systemName,cmdString)
                    if isExecutionTimeTooLong(startedAt) then break end
                end
            end
        end
    end
}
Last edited by waaren on Friday 09 November 2018 7:53, edited 2 times in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pavelbor
Posts: 35
Joined: Sunday 18 December 2016 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Tallinn / Estonia
Contact:

Re: YAP (yet another pinger)

Post by pavelbor »

Hello,

thanx for example of the script. But when started, and detected that some device is offline, script start to send notification every 5 minutes until device becomes online. It will produce lot of spamming notification.
Would be nice to set some variable (for each device), like notification_sent_deviceNAME (initial = 0).

When script detect that device is offline, variable notification_sent_deviceNAME becomes 1, first notification will be sended, and then with every cycle variable increased by +1.
Next notification may be sended in next 24hr, for example - notification_sent_deviceNAME ==288, and at that time variable could be reseted back to 0.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: YAP (yet another pinger)

Post by waaren »

pavelbor wrote: Thursday 08 November 2018 10:19 Hello,

thanx for example of the script. But when started, and detected that some device is offline, script start to send notification every 5 minutes until device becomes online. It will produce lot of spamming notification.
Would be nice to set some variable (for each device), like notification_sent_deviceNAME (initial = 0).

When script detect that device is offline, variable notification_sent_deviceNAME becomes 1, first notification will be sended, and then with every cycle variable increased by +1.
Next notification may be sended in next 24hr, for example - notification_sent_deviceNAME ==288, and at that time variable could be reseted back to 0.
New version is being tested as we speak.
Version will include your proposed improvement and also possibility to check ports (using nmap)
I will probably post the update tomorrow
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: YAP (yet another pinger)

Post by waaren »

New version posted here
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
megamarco83
Posts: 108
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: YAP (yet another pinger)

Post by megamarco83 »

hi to all, i'm using this script but i find one issue related maybe to my configuration:
i have some devices that take some time to respond, maybe because they are on wifi and the signal is not so strong....so i receive false massage, i mean that i receve notification that device is not conttected, but in reality that devices is connected. i try to use this parameter inside the script:

Code: Select all

pingWaitTime = 2,


if i understand well the code, it use inside ping command the parametr -w2
but in this case, if from windows system i open cmd shell and i try to use:
ping 192.168.0.200 -w2
i receive some errors
if i use:
ping 192.168.0.200
(whitout parameter -w2)
i receive the response without errors.
here one picture:
https://ibb.co/G9wXGck


in your opinion could be that one the issue related to false message coming from telegram ?
thanks to all :-)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: YAP (yet another pinger)

Post by waaren »

megamarco83 wrote: Thursday 09 January 2020 19:30 I try to use this parameter inside the script:

Code: Select all

pingWaitTime = 2,


if i understand well the code, it use inside ping command the parametr -w2
but in this case, if from windows system i open cmd shell and i try to use:
ping 192.168.0.200 -w2
Funny stuff going on here. Linux reacts different to these parameters compared to Windows.

On linux all below ping parameter variants work as expected.
Spoiler: show

Code: Select all


waaren@NUC: 192.168.192.115:/usr/local/domotica:$ping -w2 pi-1
PING PI-1 (192.168.192.51) 56(84) bytes of data.
64 bytes from PI-1 (192.168.192.51): icmp_seq=1 ttl=64 time=3.45 ms
64 bytes from PI-1 (192.168.192.51): icmp_seq=2 ttl=64 time=5.29 ms

--- PI-1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 3.450/4.371/5.293/0.923 ms

waaren@NUC: 192.168.192.115:/usr/local/domotica:$ping -w 2 pi-1
PING PI-1 (192.168.192.51) 56(84) bytes of data.
64 bytes from PI-1 (192.168.192.51): icmp_seq=1 ttl=64 time=3.74 ms
64 bytes from PI-1 (192.168.192.51): icmp_seq=2 ttl=64 time=4.72 ms

--- PI-1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 3.739/4.228/4.717/0.489 ms

waaren@NUC: 192.168.192.115:/usr/local/domotica:$ping -c 1 -w2 pi-1
PING PI-1 (192.168.192.51) 56(84) bytes of data.
64 bytes from PI-1 (192.168.192.51): icmp_seq=1 ttl=64 time=2.60 ms

--- PI-1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.596/2.596/2.596/0.000 ms
root@NUC: 192.168.192.115:/usr/local/domotica:#ping -c 1 -w 2 pi-1
PING PI-1 (192.168.192.51) 56(84) bytes of data.
64 bytes from PI-1 (192.168.192.51): icmp_seq=1 ttl=64 time=3.39 ms

--- PI-1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.390/3.390/3.390/0.000 ms
root@NUC: 192.168.192.115:/usr/local/domotica:#ping -w 2 -c 1  pi-1
PING PI-1 (192.168.192.51) 56(84) bytes of data.
64 bytes from PI-1 (192.168.192.51): icmp_seq=1 ttl=64 time=11.0 ms

--- PI-1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 11.005/11.005/11.005/0.000 ms

Windows does NOT like some of these variants
Spoiler: show

Code: Select all

Microsoft Windows [Version 10.0.19041.1]
(c) 2019 Microsoft Corporation. 

C:\WINDOWS\system32>ping -c1 -w2 192.168.192.66

Pinging 192.168.192.66 with 32 bytes of data:
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.192.66:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\WINDOWS\system32>ping -w2 192.168.192.66
IP address must be specified.

C:\WINDOWS\system32>ping -w 2 192.168.192.66

Pinging 192.168.192.66 with 32 bytes of data:
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64
Reply from 192.168.192.66: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.192.66:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms


C:\WINDOWS\system32>ping -c1 -w 2  192.168.192.66
Bad parameter 192.168.192.66.

C:\WINDOWS\system32>ping -w2  -c1 192.168.192.66

Pinging 192.168.192.66 with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.

Ping statistics for 192.168.192.66:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

So I don't see a relation between the problem you see with the Ping command on Windows and your extra Telegram messages.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
megamarco83
Posts: 108
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: YAP (yet another pinger)

Post by megamarco83 »

waaren wrote: Thursday 09 January 2020 22:27

Windows does NOT like some of these variants

So I don't see a relation between the problem you see with the Ping command on Windows and your extra Telegram messages.
Hi Waaren, yes, you are right, i tested the ping command on raspberry and it works in a different way compared to windows

Code: Select all

pi@raspberrypi:~ $ ping -c2 -w2 192.168.0.200
PING 192.168.0.200 (192.168.0.200) 56(84) bytes of data.
64 bytes from 192.168.0.200: icmp_seq=1 ttl=255 time=9.80 ms
64 bytes from 192.168.0.200: icmp_seq=2 ttl=255 time=94.3 ms

--- 192.168.0.200 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 9.807/52.078/94.350/42.272 ms
pi@raspberrypi:~ $
but my issue is related to receving false notification related to a device that for the script is disconnected but in realty it isn't.

just an example of some minutes ago.
my device that has ip 192.168.0.200

here in this picture you can see that the device is active since more that 6 days....

Image


here you can see that i receive a message this evening comin from telegram, trigered by the script, about a disconnection of my devices.

Image

these are my parameters inside the script:

Code: Select all

                                                              -- Once a day the sendMessage flag must be cleared; it will happen at this time      
                        maxExecutionTime        = 3.0,        -- If multiple pings fail the script will run too long this will 
                                                              -- ensure the script stops after maxExecutionTime seconds
                        pingWaitTime            = 2,          -- the ping command parm -w is how log the ping should wait for an answer
                                                              -- if one second is not long enough you can set it to an higher value here
                        maxFailsBeforeMessage   = 3,          -- the message will only be send after this amount of consecutive failed pings or nmaps 
                        silentTime              = "23:00-07:00",  -- The time window when no messages are to be send.  
                                                                  --NB. silentTime "never" or "24:00"  means allways notify. (never silent = )
                        repeatMessage           = false,      -- When set to false only first message on a day will be send, 
                                                              -- when true every x fails a message will be send 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: YAP (yet another pinger)

Post by waaren »

megamarco83 wrote: Thursday 09 January 2020 23:27 but my issue is related to receving false notification related to a device that for the script is disconnected but in realty it isn't.
here in this picture you can see that the device is active since more that 6 days....
The ping script does not test if a system is active or not. It tests if it reacts to ping within the set time. If it does not react within that time, the script will give you a message so you can investigate what is causing this.
A number of issues can lead to a ping not being successful within a given time.
The system could be very busy or heavy traffic on the network or a switch problem or a router restart and I am sure you can think of a couple of other reasons. But that's why the script sends the message to help you by giving an early warning so you can investigate and try to solve it before it get serious.
If the ping method used in this script to check this particular connection to the system is not giving the result you can work with then maybe you can use another method to check if the system is still working as designed.
Because of the design of domoticz event system it is not advisable to extend the time ping waits for a response to be much longer as you will block the complete event-system for the time it waits for a response.
Alongside this ping script I use monit as my main tool to check critical systems, tools, connections and backups. It could be wort-while for you to see if it could be of any use in your setup.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
megamarco83
Posts: 108
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: YAP (yet another pinger)

Post by megamarco83 »

hi, thanks for reply.
i use this script to ask a responde to my esp8266 devices. it's very usefull to investigate if devices are off line.
sometime happen that an esp8266 go off line, and i need to reboot manually the esp, simply remove its power and then power on again.
i notice that on two devices that are positioned quite far from the router and in a postition difficult to reach also manually, you can see the signal Db that is -91db, sometimes i receive from script messges that this device is disconnect, but in realty it is still on, maybe during the ping from script, the device react slowly so it send the message.
what do you think?
maybe i can solve just increasing the ping time?
if i understand correct is the parameter -w that in the script:
pingWaitTime = 2,
maybe i can increase a bit the value?
do you have a suggestion for it?

related to "monit", i do not know what is it and how it is working :-)
i will try to search on google :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: YAP (yet another pinger)

Post by waaren »

megamarco83 wrote: Friday 10 January 2020 11:04 if i understand correct is the parameter -w that in the script: pingWaitTime = 2, maybe i can increase a bit the value?
Yes you can. Don't do it by changing the default but change it only for systems where you need it. (in the sites2Check)
You also might need to increase the overall maxExecutionTime (in the defaults)
related to "monit", i do not know what is it and how it is working :-)
i will try to search on google :)
Google is your friend :) but also on this forum you wil get > 300 hits when you use the search word monit, So it's fair to say that this forum is also a friend :D
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
megamarco83
Posts: 108
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: YAP (yet another pinger)

Post by megamarco83 »

waaren wrote: Friday 10 January 2020 17:08 Yes you can. Don't do it by changing the default but change it only for systems where you need it. (in the sites2Check)
You also might need to increase the overall maxExecutionTime (in the defaults)
you mean for example changing this:
sites2Check.Sonoff_200_VCM_mansarda = {address = "192.168.0.200" ,message = "disconnesso Sonoff_200_VCM_mansarda"}

to this:

sites2Check.Sonoff_200_VCM_mansarda = {address = "192.168.0.200" , pingWaitTime = 4, maxFailsBeforeMessage = 6 message = "disconnesso Sonoff_200_VCM_mansarda"}
that will be executed only for this devices, all other devices will keep the defaul ping, right?
thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest