Use an error in log as a trigger

Moderator: leecollings

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

Re: Use an error in log as a trigger

Post by waaren »

bldewit wrote: Wednesday 03 July 2019 23:55 Because of the Unifi software on this rPi i did tell Domoticz to use a different port than the default one. This was done during the installation procedure, though....

Might this be the cause?
Don't know but maybe you could try changing the local networks settings in the domoticz Gui. (change 127.0.0.1 to 127.0.0.*

Setup -> Settings -> System setup -> local networks (NO USERNAME/PASSWORD)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bldewit
Posts: 59
Joined: Tuesday 09 May 2017 23:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Use an error in log as a trigger

Post by bldewit »

That was a briljant idea, @waaren!

Log now says:

Code: Select all

2019-07-08 10:35:00.505 Status: dzVents: Info: getStr from log: ------ Start internal script: getFailedVent2:, trigger: every 5 minutes
2019-07-08 10:35:00.508 Status: dzVents: Debug: getStr from log: OpenURL: url = http://127.0.0.1:8079/json.htm?type=command&param=getlog&lastlogtime=1562574601&loglevel=4
2019-07-08 10:35:00.508 Status: dzVents: Debug: getStr from log: OpenURL: method = GET
2019-07-08 10:35:00.508 Status: dzVents: Debug: getStr from log: OpenURL: post data = nil
2019-07-08 10:35:00.509 Status: dzVents: Debug: getStr from log: OpenURL: headers = nil
2019-07-08 10:35:00.509 Status: dzVents: Debug: getStr from log: OpenURL: callback = getDomoticzErrorLog
2019-07-08 10:35:00.512 Status: dzVents: Info: getStr from log: ------ Finished getFailedVent2
2019-07-08 10:35:01.526 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog
2019-07-08 10:35:01.526 Status: dzVents: Info: getStr from log: ------ Start internal script: getFailedVent2: HTTPResponse: "getDomoticzErrorLog"
2019-07-08 10:35:02.002 Status: dzVents: Debug: getStr from log: No (new) occurrences of string Error opening url: http://192.168.1.123 in the domoticz log
2019-07-08 10:35:02.005 Status: dzVents: Info: getStr from log: ------ Finished getFailedVent2
2019-07-08 10:35:02.002 Error: dzVents: Debug: getStr from log: Show ALL:
2019-07-08 10:35:02.002 {
2019-07-08 10:35:02.002 "LastLogTime" : "1562574603",
2019-07-08 10:35:02.002 "result" : [
2019-07-08 10:35:02.002 {
2019-07-08 10:35:02.002 "level" : 4,
2019-07-08 10:35:02.002 "message" : "2019-07-08 10:30:03.086 Error: dzVents: Debug: getStr from log: Show ALL: \n{\n \"LastLogTime\" : \"1562574302\",\n \"result\" : [\n {\n \"level\" : 4,\n \"message\" : \"2019-07-08 10:25:02.153 Error: dzVents: Debug: getStr from log: Show ALL: \\n{\\n \\\"LastLogTime\\\" : \\\"1562574001\\\",\\n \\\"result\\\" : [\\n {\\n \\\"level\\\" : 4,\\n \\\"message\\\" : \\\"2019-07-08 10:20:01.962 Error: dzVents: Debug: getStr from log: Show ALL: \\\\n{\\\\n \\\\\\\"LastLogTime\\\\\\\" : \\\\\\\"1562573701\\\\\\\",\\\\n \\\\\\\"result\\\\\\\" : [\\\\n {\\\\n \\\\\\\"level\\\\\\\" : 4,\\\\n \\\\\\\"message\\\\\\\" : \\\\\\\"2019-07-08 10:15:01.509 Error: dzVents: Debug: getStr from log: Show ALL: \\\\\\\\n{\\\\\\\\n \\\\\\\\\\\\\\\"LastLogTime\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"1562314225\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\\\\\\"result\\\\\\\\\\\\\\\" : [\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-06-30 23:42:15.245 Error: Darksky: Error getting http data!.\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-06-30 23:42:19.269 Error: Weersvoorspelling hardware (7) thread seems to have ended unexpectedly\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 04:05:21.421 Error: PVOutput (Input): Error login!\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 04:10:26.748 Error: PVOutput (Input): Error login!\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 11:30:47.780 Error: Prowl: \\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 11:30:47.782 Error: SMTP Mailer: Error sending Email to: <******@gmail.com> !\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 11:30:47.782 Error: Failed to send Email notification!\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-03 12:19:25.807 Error: RFLink: Unhandled switch command: 00\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-05 10:10:24.600 Error: GCM: Could not send message, HTTP Error\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-05 10:10:24.732 Error: Prowl: \\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-05 10:10:25.323 Error: HTTP: \\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-05 10:10:25.336 Error: SMTP Mailer: Error sending Email to: <*****@gmail.com> !\\\\\\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n {\\\\\\\\n \\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n \\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2019-07-05 10:10:25.338 Error: Failed to send Email notification!\\\\\\\\\\\\\\\"\\\\\\\\n }\\\\\\\\n ],\\\\\\\\n \\\\\\\\\\\\\\\"status\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"OK\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\\\\\\"title\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"GetLog\\\\\\\\\\\\\\\"\\\\\\\\n}\\\\\\\\n\\\\\\\"\\\\n }\\\\n ],\\\\n \\\\\\\"status\\\\\\\" : \\\\\\\"OK\\\\\\\",\\\\n \\\\\\\"title\\\\\\\" : \\\\\\\"GetLog\\\\\\\"\\\\n}\\\\n\\\"\\n }\\n ],\\n \\\"status\\\" : \\\"OK\\\",\\n \\\"title\\\" : \\\"GetLog\\\"\\n}\\n\"\n }\n ],\n \"status\" : \"OK\",\n \"title\" : \"GetLog\"\n}\n"
2019-07-08 10:35:02.002 }
2019-07-08 10:35:02.002 ],
2019-07-08 10:35:02.002 "status" : "OK",
2019-07-08 10:35:02.002 "title" : "GetLog"
2019-07-08 10:35:02.002 }
2019-07-08 10:35:02.002
Does it evaluate too many lines of log, considering the dates the debugging shows? This was not the first run anymore....
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by waaren »

bldewit wrote: Monday 08 July 2019 10:33 Does it evaluate too many lines of log, considering the dates the debugging shows? This was not the first run anymore....
Are the subsequent runs OK now ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bldewit
Posts: 59
Joined: Tuesday 09 May 2017 23:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Use an error in log as a trigger

Post by bldewit »

It does seem to have settled down now. I had several runs containing these large amounts of info but as of today the log is shorter:
2019-07-09 23:35:00.635 Status: dzVents: Info: getStr from log: ------ Start internal script: getFailedVent2:, trigger: every 5 minutes
2019-07-09 23:35:00.638 Status: dzVents: Debug: getStr from log: OpenURL: url = http://127.0.0.1:8079/json.htm?type=com ... loglevel=4
2019-07-09 23:35:00.639 Status: dzVents: Debug: getStr from log: OpenURL: method = GET
2019-07-09 23:35:00.639 Status: dzVents: Debug: getStr from log: OpenURL: post data = nil
2019-07-09 23:35:00.639 Status: dzVents: Debug: getStr from log: OpenURL: headers = nil
2019-07-09 23:35:00.640 Status: dzVents: Debug: getStr from log: OpenURL: callback = getDomoticzErrorLog
2019-07-09 23:35:00.643 Status: dzVents: Info: getStr from log: ------ Finished getFailedVent2
2019-07-09 23:35:01.452 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog
2019-07-09 23:35:01.453 Status: dzVents: Info: getStr from log: ------ Start internal script: getFailedVent2: HTTPResponse: "getDomoticzErrorLog"
2019-07-09 23:35:01.518 Status: dzVents: Debug: getStr from log: Show ALL:
2019-07-09 23:35:01.518 {
2019-07-09 23:35:01.518 "status" : "OK",
2019-07-09 23:35:01.518 "title" : "GetLog"
2019-07-09 23:35:01.518 }
2019-07-09 23:35:01.518
2019-07-09 23:35:01.531 Status: dzVents: Debug: getStr from log: No (new) occurrences of string Error opening url: http://192.168.1.123 in the domoticz log
2019-07-09 23:35:01.534 Status: dzVents: Info: getStr from log: ------ Finished getFailedVent2
Time to REM out the debug-lines?
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
bldewit
Posts: 59
Joined: Tuesday 09 May 2017 23:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: NL
Contact:

Re: Use an error in log as a trigger

Post by bldewit »

@waaren, thx for all your help and patience!!! Kudo's to you!
-‐----------------------------------------------------------
Running on rPi 3b (main) and rPi 2b (somfy), both RFLink
IthoRemote, Xiaomi Gateway, KAKU
niki_lauda
Posts: 115
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Use an error in log as a trigger

Post by niki_lauda »

waaren wrote: Monday 10 June 2019 15:06
bldewit wrote: Monday 10 June 2019 13:41 It would be great if we could use an error message in the log as a trigger for a script. This way one could send a message after not being able to connect to a URL when switching network connected devices or for instance send the same command again after X seconds.
Is there a way to read the log and use the text in (e.g.) a LUA script?
Maybe this can get you started.

When not yet familiar with dzVents please start with reading Get started Before implementing. Special attention please for
"In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Hi Waaren
The url you gave is not working any more can you point me in the right direction?

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

Re: Use an error in log as a trigger

Post by waaren »

niki_lauda wrote: Sunday 26 April 2020 10:24 The url you gave is not working any more can you point me in the right direction?
Probably the location of the post moved. I guess it was this one
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 636
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by madpatrick »

Hi,

I've changed the script a little bit to get a message when any error is in the log file, but i see a error line in the log running the script.
Not sure that it means or whether it is an problem

Code: Select all

2021-01-23 14:51:00.559 Error: dzVents: Info: getStr from log: ------ Start internal script: Log Error: HTTPResponse: "getDomoticzErrorLog"

Code: Select all

2021-01-23 14:51:00.396 Status: dzVents: Info: getStr from log: ------ Start internal script: Log Error:, trigger: "every minute"
2021-01-23 14:51:00.396 Status: dzVents: Debug: getStr from log: OpenURL: url = http://127.0.0.1:9200/json.htm?type=command&param=getlog&lastlogtime=1611409800&loglevel=4
2021-01-23 14:51:00.396 Status: dzVents: Debug: getStr from log: OpenURL: method = GET
2021-01-23 14:51:00.396 Status: dzVents: Debug: getStr from log: OpenURL: post data = nil
2021-01-23 14:51:00.396 Status: dzVents: Debug: getStr from log: OpenURL: headers = nil
2021-01-23 14:51:00.396 Status: dzVents: Debug: getStr from log: OpenURL: callback = getDomoticzErrorLog
2021-01-23 14:51:00.397 Status: dzVents: Info: getStr from log: ------ Finished Log Error
2021-01-23 14:51:00.559 Status: dzVents: Debug: getStr from log: Show ALL:
2021-01-23 14:51:00.559 {
2021-01-23 14:51:00.559 "status" : "OK",
2021-01-23 14:51:00.559 "title" : "GetLog"
2021-01-23 14:51:00.559 }
2021-01-23 14:51:00.559
2021-01-23 14:51:00.559 Status: dzVents: Debug: getStr from log: No (new) occurrences of string Error in the domoticz log
2021-01-23 14:51:00.559 Status: dzVents: Info: getStr from log: ------ Finished Log Error
2021-01-23 14:51:00.559 Error: dzVents: Info: getStr from log: ------ Start internal script: Log Error: HTTPResponse: "getDomoticzErrorLog"
My script

Code: Select all

myHttpResponse = "getDomoticzErrorLog"

return {
    on      =   {   httpResponses   =   { myHttpResponse },
                    timer           =   { "every minute"},
                },

    logging =   {   level           =   domoticz.LOG_DEBUG,
                    marker          =   "getStr from log"    },

    data    =   {   lastlogtime     =   { initial = 0 }}, 

    execute = function(dz, trigger)
        
        local searchStr = "Error"          -- Change to reflect the messages you want to catch

        local function askDomoticzForLogLines()
            local lastLogTime = dz.data.lastlogtime            -- get time last logrequest
            local logLevel    = 4                              -- loglevel (1=normal,2=Status,4=error,268435455=all
            local jsonString  = "/json.htm?type=command" .. 
                                "&param=getlog" ..
                                "&lastlogtime=" .. tostring(lastLogTime) ..
                                "&loglevel=" .. tostring(logLevel)
            
            local logURL      =  dz.settings["Domoticz url"] .. jsonString
            
            dz.openURL  ({ url      = logURL,
                           method   = "GET", 
                           callback = myHttpResponse 
                        })

            dz.data.lastlogtime = dz.time.dDate        -- store current Time as seconds from epoch  
        end

        local function findString()
           if trigger.json.result ~= nil then               -- Only when there are errormessages in the log
               local resultTable = trigger.json.result
               for i = #resultTable,1,-1 do                 -- traverse backwards to get latest violation first
                    local s = resultTable[i].message
                    local found = s:find(searchStr,1,true) -- searcg plain string starting at pos 1 (no pattern) 
                    local dzVents = s:find("dzVents")
                    if found and not(dzVents) then
                       return true
                    end
                end
            end
        end

        if trigger.isDevice or trigger.isTimer then
            askDomoticzForLogLines()                     -- get the relevant loglines
        elseif trigger.ok then
            dz.log("Show ALL: \n" .. trigger.data,dz.LOG_DEBUG)
            if findString() then
                dz.log("Log " .. searchStr .. " found! ",dz.LOG_DEBUG)
                dz.notify("Log " .. searchStr .. " found! ",dz.PRIORITY_HIGH)
            else    
                dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_DEBUG)
            end    
        else
            dz.log("Access problem to log. Data found: " .. trigger.data,dz.LOG_ERROR)
       end
    end
}
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by waaren »

madpatrick wrote: Saturday 23 January 2021 14:54 I've changed the script a little bit to get a message when any error is in the log file, but i see a error line in the log running the script.
Not sure that it means or whether it is an problem
That should not be a problem. Domoticz recognize the word Error and report that in the log as a log message with type Error.
The functionality of the script is not hampered by that behavior.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 636
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by madpatrick »

OK. Thanks.

Is it possible to filter out the reporting which a specific word is in an error message.
I've have regularly this error in the log, button don't want to script to log or report this.

Code: Select all

 Error: CheckAuthToken(83ac3e6a227dda5d7c0af393a3a99d27_NQtYzBiYzc3NjNkNDYy) : session id not found
So, can i filter out the CheckAuthToken errors ?
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by waaren »

madpatrick wrote: Saturday 23 January 2021 20:09 Is it possible to filter out the reporting which a specific word is in an error message.
In below version you can filter out 0 or more strings you don't want to be reported on.

Code: Select all

scriptVar = "getDomoticzErrorLog"

return
{
    on =
    {
        httpResponses =
        {
            scriptVar,
        },
        timer =
        {
            "every minute"
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data =
    {
        lastlogtime =
        {
            initial = 0
        }
    },

    execute = function(dz, item)

        local searchStr = "Error"          -- Change to reflect the messages you want to catch

        local ignoreStrings = -- Enter all strings to be ignored in this table
        {
            'CheckAuthToken',
            'dzVents: Info:',
            'dzVents: !Info:',
            'dzVents: Debug:',
        }

        local function trueError(str)
            for _, ignore in ipairs(ignoreStrings) do
                if str:find(ignore) then return false end
            end
            return true
        end

        local function askDomoticzForLogLines()
            local lastLogTime = dz.data.lastlogtime            -- get time last logrequest
            local logLevel    = 4                              -- loglevel (1=normal,2=Status,4=error,268435455=all
            local jsonString  = "/json.htm?type=command" .. "&param=getlog" .. "&lastlogtime=" .. tostring(lastLogTime) .. "&loglevel=" .. tostring(logLevel)
            dz.openURL(
            {
                url = dz.settings["Domoticz url"] .. jsonString
                callback = scriptVar
            })
            dz.data.lastlogtime = os.time()        -- store current Time as seconds from epoch
        end

        local function findString()
           if item.json.result then               -- Only when there are errormessages in the log
               local rt = item.json.result
               for i = #rt, 1, -1 do                 -- traverse backwards to get latest violation first
                    local msg = rt[i].message
                    if msg:find('%s%s' .. searchStr) and trueError(msg) then return msg end
                end
            end
        end

        if item.isDevice or item.isTimer then
            askDomoticzForLogLines()                     -- get the relevant loglines
        elseif item.json then
            dz.log("Show ALL: \n" .. item.data,dz.LOG_DEBUG)
            local line = findString()
            if line then
                dz.log("Log " .. searchStr .. " found! ",dz.LOG_DEBUG)
                dz.notify("Log " .. line .. " found! ",dz.PRIORITY_HIGH)
            else
                dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_DEBUG)
            end
        else
            dz.log("Access problem to log. Data found: " .. item.data,dz.LOG_ERROR)
       end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

Hi i copy and paste and get following error:

...domoticz/scripts/dzVents/generated_scripts/Script #5.lua:47: '}' expected (to close '{' at line 45) near 'callback'

What am i doing wrong please?

And its possible to use it as “on device” instead of httpresponses and timer every minute??

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

Re: Use an error in log as a trigger

Post by waaren »

Biiiiino wrote: Monday 19 April 2021 18:20 ...domoticz/scripts/dzVents/generated_scripts/Script #5.lua:47: '}' expected (to close '{' at line 45) near 'callback'
Is it possible to use it as “on device” instead of httpresponses and timer every minute??
Change line

Code: Select all

 url = dz.settings["Domoticz url"] .. jsonString
to

Code: Select all

 url = dz.settings["Domoticz url"] .. jsonString,
The on = httpResponses is required and cannot be left out. You could change the timer = "every minute" into device = 'device name', but you might miss some messages because the amount of lines in the log buffer is not unlimited.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

Hi waaren,

thank you for you reply, it looks scripts work almost as expected. Script is looking for string but before that string is loged so it inform me: "No (new) occurrences of string Error" screen attached.

Also another question its possible to add there one more searchstring with "if" different action ?

Thank you in advance
Attachments
Log
Log
dzvent.png (96.62 KiB) Viewed 2897 times
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

maybe this is the way ".afterSec(10)" but i didnt found the correct place where to put it on :D
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by waaren »

Biiiiino wrote: Tuesday 20 April 2021 12:04 maybe this is the way ".afterSec(10)" but i didnt found the correct place where to put it on :D
Can you share the log and your script both between code tags and not as image? That will allow me to add some extra debug statements to help solving your issue.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

Hi sure thank you

log:

Code: Select all

 2021-04-20 12:24:22.097 (Virtual devices) Light/Switch (test_switch)
2021-04-20 12:24:22.096 Status: User: Admin initiated a switch command (2/test_switch/On)
2021-04-20 12:24:22.122 Status: dzVents: Info: Handling events for: "test_switch", value: "On"
2021-04-20 12:24:22.122 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 12:24:22.122 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618913951&loglevel=4
2021-04-20 12:24:22.122 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 12:24:22.122 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 12:24:22.122 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 12:24:22.122 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 12:24:22.122 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 12:24:22.122 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 12:24:22.159 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 12:24:22.159 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 12:24:22.160 Status: dzVents: Debug: getDomoticzErrorLog: Show ALL:
2021-04-20 12:24:22.160 {
2021-04-20 12:24:22.160 "status" : "OK",
2021-04-20 12:24:22.160 "title" : "GetLog"
2021-04-20 12:24:22.160 }
2021-04-20 12:24:22.160
2021-04-20 12:24:22.160 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 12:24:22.160 Error: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string Error: Error opening url: http://www.TESTERROR in the domoticz log
2021-04-20 12:24:22.302 Error: Error opening url: http://www.TESTERROR 


script:

Code: Select all

scriptVar = "getDomoticzErrorLog"

return
{
    on =
    {
        httpResponses =
        {
            scriptVar,
        },
        devices =
        {
            "test_switch"
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data =
    {
        lastlogtime =
        {
            initial = 0
        }
    },

    execute = function(dz, item)

        local searchStr = "http://www.TESTERROR"          -- Change to reflect the messages you want to catch

        local ignoreStrings = -- Enter all strings to be ignored in this table
        {
            'CheckAuthToken',
            'dzVents: Info:',
            'dzVents: !Info:',
            'dzVents: Debug:',
        }

        local function trueError(str)
            for _, ignore in ipairs(ignoreStrings) do
                if str:find(ignore) then return false end
            end
            return true
        end

        local function askDomoticzForLogLines()
            local lastLogTime = dz.data.lastlogtime            -- get time last logrequest
            local logLevel    = 4                              -- loglevel (1=normal,2=Status,4=error,268435455=all
            local jsonString  = "/json.htm?type=command" .. "&param=getlog" .. "&lastlogtime=" .. tostring(lastLogTime) .. "&loglevel=" .. tostring(logLevel)
            dz.openURL(
            {
                url = dz.settings["Domoticz url"] .. jsonString,
                callback = scriptVar
            })
            dz.data.lastlogtime = os.time()        -- store current Time as seconds from epoch
        end

        local function findString()
           if item.json.result then               -- Only when there are errormessages in the log
               local rt = item.json.result
               for i = #rt, 1, -1 do                 -- traverse backwards to get latest violation first
                    local msg = rt[i].message
                    if msg:find('%s%s' .. searchStr) and trueError(msg) then return msg end
                end
            end
        end

        if item.isDevice or item.isTimer then
            askDomoticzForLogLines()                     -- get the relevant loglines
        elseif item.json then
            dz.log("Show ALL: \n" .. item.data,dz.LOG_DEBUG)
            local line = findString()
            if line then
                dz.log("Log " .. searchStr .. " found! ",dz.LOG_DEBUG)
                dz.notify("Log " .. line .. " found! ",dz.PRIORITY_HIGH)
            else
                dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_DEBUG)
            end
        else
            dz.log("Access problem to log. Data found: " .. item.data,dz.LOG_ERROR)
       end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use an error in log as a trigger

Post by waaren »

Biiiiino wrote: Tuesday 20 April 2021 12:26 2021-04-20 12:24:22.160 Error: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string Error: Error opening url:
Please note that the script only find real errors. So no test messages send to the OS file with the domoticz log.

Can you try this one?

Code: Select all

local scriptVar = "getDomoticzErrorLog"

return
{
    on =
    {
        httpResponses =
        {
            scriptVar,
        },
        devices =
        {
            "test_switch",
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data =
    {
        lastlogtime =
        {
            initial = 0,
        },
        previousTime =
        {
            initial = 0,
        },
    },

    execute = function(dz, item)

        local searchStr = "Error: Error opening url: http://www.TESTERROR"          -- Change to reflect the messages you want to catch

        local ignoreStrings = -- Enter all strings to be ignored in this table
        {
            'CheckAuthToken',
            'dzVents: Info:',
            'dzVents: !Info:',
            'dzVents: Debug:',
        }

        local function trueError(str)
            for _, ignore in ipairs(ignoreStrings) do
                if str:find(ignore) then return false end
            end
            return true
        end

        local function askDomoticzForLogLines()
            local lastLogTime = dz.data.lastlogtime            -- get time last logrequest
            local logLevel    = 4                             -- loglevel (1=normal,2=Status,4=error,268435455=all
            local jsonString  = "/json.htm?type=command" .. "&param=getlog" .. "&lastlogtime=" .. tostring(lastLogTime) .. "&loglevel=" .. tostring(logLevel)
            dz.openURL(
            {
                url = dz.settings["Domoticz url"] .. jsonString,
                callback = scriptVar
            })
            dz.data.previousTime = dz.data.lastlogtime
            dz.data.lastlogtime = os.time() - 1        -- store current Time as seconds from epoch
        end

        local function findString()
           if item.json.result then               -- Only when there are errormessages in the log
               local rt = item.json.result
               for i = #rt, 1, -1 do                 -- traverse backwards to get latest violation first
                    local msg = rt[i].message
                    if msg:find('%s%s' .. searchStr) and trueError(msg) then return msg end
                end
                dz.log('No resulting loglines found for the set logLevel / searchstrings in the last ' .. ( os.time() - dz.data.previousTime ) .. ' seconds.',dz.LOG_DEBUG)
            else
                dz.log('No resulting loglines found for the set logLevel in the last ' .. ( os.time() - dz.data.previousTime ) .. ' seconds.',dz.LOG_DEBUG)
            end
        end

        if item.isDevice or item.isTimer then
            askDomoticzForLogLines()                     -- get the relevant loglines
        elseif item.json then
            local line = findString()
            if line then
                dz.log("Log " .. searchStr .. " found! ",dz.LOG_DEBUG)
                dz.notify("Log " .. line .. " found! ",dz.PRIORITY_HIGH)
            else
                dz.log("Show ALL: \n" .. item.data,dz.LOG_DEBUG)
                dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_DEBUG)
                dz.openURL('http://www.TESTERROR') -- Force real error to log (only during debug)
            end
        else
            dz.log("Access problem to log. Data found: " .. item.data,dz.LOG_ERROR)
       end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

This is not test message. Its a button with not existing URL on action - thats what i want to monitor, if i turn on heating and device (esp8266) is not respondig, revert status of my switch back by call url directly to device in domoticz.. Maybe this is not the correct way, because now is searching for all erros in log.

Code: Select all

 2021-04-20 13:31:01.259 Status: User: Admin initiated a switch command (2/test_switch/On)
2021-04-20 13:31:01.286 Status: dzVents: Info: Handling events for: "test_switch", value: "On"
2021-04-20 13:31:01.286 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 13:31:01.286 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618918167&loglevel=4
2021-04-20 13:31:01.286 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:31:01.286 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:31:01.286 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:31:01.286 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 13:31:01.287 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:31:01.287 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:31:01.346 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 13:31:01.346 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: No resulting loglines found for the set logLevel / searchstrings in the last 94 seconds.
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string Error opening url in the domoticz log
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://www.TESTERROR
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:31:01.347 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = nil
2021-04-20 13:31:01.347 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:31:01.347 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:31:01.347 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL:
2021-04-20 13:31:01.347 {
2021-04-20 13:31:01.347 "LastLogTime" : "1618918168",
2021-04-20 13:31:01.347 "result" :
2021-04-20 13:31:01.347 [
2021-04-20 13:31:01.347 {
2021-04-20 13:31:01.347 "level" : 4,
2021-04-20 13:31:01.347 "message" : "2021-04-20 13:29:28.565 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \n{\n\t\"LastLogTime\" : \"1618918157\",\n\t\"result\" : \n\t[\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:17.334 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\n{\\n\\t\\\"LastLogTime\\\" : \\\"1618917940\\\",\\n\\t\\\"result\\\" : \\n\\t[\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:25:13.881 Error: dzVents: Debug: getDomoticzErrorLog: Log Error: Error opening url: http://www.TESTERROR found! \\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:25:14.063 Error: Error opening url: http://test_off_error\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:25:35.675 Error: Error opening url: http://www.TESTERROR\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:25:40.648 Error: Error opening url: http://test_off_error\\\"\\n\\t\\t}\\n\\t],\\n\\t\\\"status\\\" : \\\"OK\\\",\\n\\t\\\"title\\\" : \\\"GetLog\\\"\\n}\\n\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:17.356 Error: Error opening url: http://www.TESTERROR\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:17.477 Error: Error opening url: http://www.TESTERROR\"\n\t\t}\n\t],\n\t\"status\" : \"OK\",\n\t\"title\" : \"GetLog\"\n}\n"
2021-04-20 13:31:01.347 },
2021-04-20 13:31:01.347 {
2021-04-20 13:31:01.347 "level" : 4,
2021-04-20 13:31:01.347 "message" : "2021-04-20 13:29:28.586 Error: Error opening url: http://www.TESTERROR"
2021-04-20 13:31:01.347 },
2021-04-20 13:31:01.347 {
2021-04-20 13:31:01.347 "level" : 4,
2021-04-20 13:31:01.347 "message" : "2021-04-20 13:29:28.707 Error: Error opening url: http://test_off_error"
2021-04-20 13:31:01.347 }
2021-04-20 13:31:01.347 ],
2021-04-20 13:31:01.347 "status" : "OK",
2021-04-20 13:31:01.347 "title" : "GetLog"
2021-04-20 13:31:01.347 }
2021-04-20 13:31:01.347
2021-04-20 13:31:01.368 Error: Error opening url: http://www.TESTERROR
2021-04-20 13:31:01.489 Error: Error opening url: http://www.TESTERROR
2021-04-20 13:31:58.663 (Virtual devices) Light/Switch (test_switch)
2021-04-20 13:31:58.662 Status: User: Admin initiated a switch command (2/test_switch/Off)
2021-04-20 13:31:58.685 Status: dzVents: Info: Handling events for: "test_switch", value: "Off"
2021-04-20 13:31:58.686 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 13:31:58.686 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618918260&loglevel=4
2021-04-20 13:31:58.686 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:31:58.686 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:31:58.686 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:31:58.686 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 13:31:58.686 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:31:58.686 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:31:58.725 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 13:31:58.725 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: No resulting loglines found for the set logLevel / searchstrings in the last 58 seconds.
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string Error opening url in the domoticz log
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://www.TESTERROR
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:31:58.727 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = nil
2021-04-20 13:31:58.727 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:31:58.727 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:31:58.727 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL:
2021-04-20 13:31:58.727 {
2021-04-20 13:31:58.727 "LastLogTime" : "1618918261",
2021-04-20 13:31:58.727 "result" :
2021-04-20 13:31:58.727 [
2021-04-20 13:31:58.727 {
2021-04-20 13:31:58.727 "level" : 4,
2021-04-20 13:31:58.727 "message" : "2021-04-20 13:31:01.347 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \n{\n\t\"LastLogTime\" : \"1618918168\",\n\t\"result\" : \n\t[\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:28.565 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\n{\\n\\t\\\"LastLogTime\\\" : \\\"1618918157\\\",\\n\\t\\\"result\\\" : \\n\\t[\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:17.334 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\\\n{\\\\n\\\\t\\\\\\\"LastLogTime\\\\\\\" : \\\\\\\"1618917940\\\\\\\",\\\\n\\\\t\\\\\\\"result\\\\\\\" : \\\\n\\\\t[\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:25:13.881 Error: dzVents: Debug: getDomoticzErrorLog: Log Error: Error opening url: http://www.TESTERROR found! \\\\\\\"\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:25:14.063 Error: Error opening url: http://test_off_error\\\\\\\"\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:25:35.675 Error: Error opening url: http://www.TESTERROR\\\\\\\"\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:25:40.648 Error: Error opening url: http://test_off_error\\\\\\\"\\\\n\\\\t\\\\t}\\\\n\\\\t],\\\\n\\\\t\\\\\\\"status\\\\\\\" : \\\\\\\"OK\\\\\\\",\\\\n\\\\t\\\\\\\"title\\\\\\\" : \\\\\\\"GetLog\\\\\\\"\\\\n}\\\\n\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:17.356 Error: Error opening url: http://www.TESTERROR\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:17.477 Error: Error opening url: http://www.TESTERROR\\\"\\n\\t\\t}\\n\\t],\\n\\t\\\"status\\\" : \\\"OK\\\",\\n\\t\\\"title\\\" : \\\"GetLog\\\"\\n}\\n\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:28.586 Error: Error opening url: http://www.TESTERROR\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:29:28.707 Error: Error opening url: http://test_off_error\"\n\t\t}\n\t],\n\t\"status\" : \"OK\",\n\t\"title\" : \"GetLog\"\n}\n"
2021-04-20 13:31:58.727 },
2021-04-20 13:31:58.727 {
2021-04-20 13:31:58.727 "level" : 4,
2021-04-20 13:31:58.727 "message" : "2021-04-20 13:31:01.368 Error: Error opening url: http://www.TESTERROR"
2021-04-20 13:31:58.727 },
2021-04-20 13:31:58.727 {
2021-04-20 13:31:58.727 "level" : 4,
2021-04-20 13:31:58.727 "message" : "2021-04-20 13:31:01.489 Error: Error opening url: http://www.TESTERROR"
2021-04-20 13:31:58.727 }
2021-04-20 13:31:58.727 ],
2021-04-20 13:31:58.727 "status" : "OK",
2021-04-20 13:31:58.727 "title" : "GetLog"
2021-04-20 13:31:58.727 }
2021-04-20 13:31:58.727
2021-04-20 13:31:58.747 Error: Error opening url: http://www.TESTERROR
2021-04-20 13:31:58.868 Error: Error opening url: http://test_off_error
2021-04-20 13:31:59.849 (RFlink) Temp + Humidity (Spalna)
2021-04-20 13:32:06.848 Status: EventSystem: reset all events...
2021-04-20 13:32:06.848 Status: dzVents: Write file: /root/dev-domoticz/scripts/dzVents/generated_scripts/Script #4.lua
2021-04-20 13:32:06.848 Status: dzVents: Write file: /root/dev-domoticz/scripts/dzVents/generated_scripts/Script #5.lua
2021-04-20 13:32:16.043 Status: EventSystem: reset all events...
2021-04-20 13:32:16.043 Status: dzVents: Write file: /root/dev-domoticz/scripts/dzVents/generated_scripts/Script #4.lua
2021-04-20 13:32:16.043 Status: dzVents: Write file: /root/dev-domoticz/scripts/dzVents/generated_scripts/Script #5.lua
2021-04-20 13:32:21.902 Status: EventSystem: reset all device statuses...
2021-04-20 13:32:36.236 (Virtual devices) Light/Switch (test_switch)
2021-04-20 13:32:36.236 Status: User: Admin initiated a switch command (2/test_switch/On)
2021-04-20 13:32:36.262 Status: dzVents: Info: Handling events for: "test_switch", value: "On"
2021-04-20 13:32:36.262 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 13:32:36.262 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618918317&loglevel=4
2021-04-20 13:32:36.262 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:32:36.262 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:32:36.262 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:32:36.262 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 13:32:36.262 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:32:36.262 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:32:36.299 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 13:32:36.300 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: No resulting loglines found for the set logLevel / searchstrings in the last 39 seconds.
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string www.TEST in the domoticz log
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://www.TESTERROR
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 13:32:36.302 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = nil
2021-04-20 13:32:36.303 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 13:32:36.303 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 13:32:36.302 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL:
2021-04-20 13:32:36.302 {
2021-04-20 13:32:36.302 "LastLogTime" : "1618918318",
2021-04-20 13:32:36.302 "result" :
2021-04-20 13:32:36.302 [
2021-04-20 13:32:36.302 {
2021-04-20 13:32:36.302 "level" : 4,
2021-04-20 13:32:36.302 "message" : "2021-04-20 13:31:58.727 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \n{\n\t\"LastLogTime\" : \"1618918261\",\n\t\"result\" : \n\t[\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:31:01.347 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\n{\\n\\t\\\"LastLogTime\\\" : \\\"1618918168\\\",\\n\\t\\\"result\\\" : \\n\\t[\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:28.565 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\\\n{\\\\n\\\\t\\\\\\\"LastLogTime\\\\\\\" : \\\\\\\"1618918157\\\\\\\",\\\\n\\\\t\\\\\\\"result\\\\\\\" : \\\\n\\\\t[\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:29:17.334 Error: dzVents: Debug: getDomoticzErrorLog: Show ALL: \\\\\\\\n{\\\\\\\\n\\\\\\\\t\\\\\\\\\\\\\\\"LastLogTime\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"1618917940\\\\\\\\\\\\\\\",\\\\\\\\n\\\\\\\\t\\\\\\\\\\\\\\\"result\\\\\\\\\\\\\\\" : \\\\\\\\n\\\\\\\\t[\\\\\\\\n\\\\\\\\t\\\\\\\\t{\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2021-04-20 13:25:13.881 Error: dzVents: Debug: getDomoticzErrorLog: Log Error: Error opening url: http://www.TESTERROR found! \\\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\\t\\\\\\\\t},\\\\\\\\n\\\\\\\\t\\\\\\\\t{\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2021-04-20 13:25:14.063 Error: Error opening url: http://test_off_error\\\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\\t\\\\\\\\t},\\\\\\\\n\\\\\\\\t\\\\\\\\t{\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2021-04-20 13:25:35.675 Error: Error opening url: http://www.TESTERROR\\\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\\t\\\\\\\\t},\\\\\\\\n\\\\\\\\t\\\\\\\\t{\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"level\\\\\\\\\\\\\\\" : 4,\\\\\\\\n\\\\\\\\t\\\\\\\\t\\\\\\\\t\\\\\\\\\\\\\\\"message\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"2021-04-20 13:25:40.648 Error: Error opening url: http://test_off_error\\\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\\t\\\\\\\\t}\\\\\\\\n\\\\\\\\t],\\\\\\\\n\\\\\\\\t\\\\\\\\\\\\\\\"status\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"OK\\\\\\\\\\\\\\\",\\\\\\\\n\\\\\\\\t\\\\\\\\\\\\\\\"title\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\"GetLog\\\\\\\\\\\\\\\"\\\\\\\\n}\\\\\\\\n\\\\\\\"\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:29:17.356 Error: Error opening url: http://www.TESTERROR\\\\\\\"\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\t{\\\\n\\\\t\\\\t\\\\t\\\\\\\"level\\\\\\\" : 4,\\\\n\\\\t\\\\t\\\\t\\\\\\\"message\\\\\\\" : \\\\\\\"2021-04-20 13:29:17.477 Error: Error opening url: http://www.TESTERROR\\\\\\\"\\\\n\\\\t\\\\t}\\\\n\\\\t],\\\\n\\\\t\\\\\\\"status\\\\\\\" : \\\\\\\"OK\\\\\\\",\\\\n\\\\t\\\\\\\"title\\\\\\\" : \\\\\\\"GetLog\\\\\\\"\\\\n}\\\\n\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:28.586 Error: Error opening url: http://www.TESTERROR\\\"\\n\\t\\t},\\n\\t\\t{\\n\\t\\t\\t\\\"level\\\" : 4,\\n\\t\\t\\t\\\"message\\\" : \\\"2021-04-20 13:29:28.707 Error: Error opening url: http://test_off_error\\\"\\n\\t\\t}\\n\\t],\\n\\t\\\"status\\\" : \\\"OK\\\",\\n\\t\\\"title\\\" : \\\"GetLog\\\"\\n}\\n\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:31:01.368 Error: Error opening url: http://www.TESTERROR\"\n\t\t},\n\t\t{\n\t\t\t\"level\" : 4,\n\t\t\t\"message\" : \"2021-04-20 13:31:01.489 Error: Error opening url: http://www.TESTERROR\"\n\t\t}\n\t],\n\t\"status\" : \"OK\",\n\t\"title\" : \"GetLog\"\n}\n"
2021-04-20 13:32:36.302 },
2021-04-20 13:32:36.302 {
2021-04-20 13:32:36.302 "level" : 4,
2021-04-20 13:32:36.302 "message" : "2021-04-20 13:31:58.747 Error: Error opening url: http://www.TESTERROR"
2021-04-20 13:32:36.302 },
2021-04-20 13:32:36.302 {
2021-04-20 13:32:36.302 "level" : 4,
2021-04-20 13:32:36.302 "message" : "2021-04-20 13:31:58.868 Error: Error opening url: http://test_off_error"
2021-04-20 13:32:36.302 }
2021-04-20 13:32:36.302 ],
2021-04-20 13:32:36.302 "status" : "OK",
2021-04-20 13:32:36.302 "title" : "GetLog"
2021-04-20 13:32:36.302 }
2021-04-20 13:32:36.302
2021-04-20 13:32:36.317 Error: Error opening url: http://www.TESTERROR 

Do you know any better way how to monitor and revert back if URL of switch is not accessible ?

Thank you a lot again
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Use an error in log as a trigger

Post by Biiiiino »

Sorry for previus log, misstake on my side... this is log:

Code: Select all

 2021-04-20 14:07:54.697 (Virtual devices) Light/Switch (test_switch)
2021-04-20 14:07:54.696 Status: User: Admin initiated a switch command (2/test_switch/On)
2021-04-20 14:07:54.719 Status: dzVents: Info: Handling events for: "test_switch", value: "On"
2021-04-20 14:07:54.719 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 14:07:54.719 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618919908&loglevel=4
2021-04-20 14:07:54.719 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 14:07:54.719 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 14:07:54.719 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 14:07:54.719 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 14:07:54.720 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 14:07:54.720 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 14:07:54.752 Status: Incoming connection from: 127.0.0.1
2021-04-20 14:07:54.770 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 14:07:54.770 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: No resulting loglines found for the set logLevel in the last 566 seconds.
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: Show ALL:
2021-04-20 14:07:54.770 {
2021-04-20 14:07:54.770 "status" : "OK",
2021-04-20 14:07:54.770 "title" : "GetLog"
2021-04-20 14:07:54.770 }
2021-04-20 14:07:54.770
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://www.TESTERROR
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 14:07:54.770 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = nil
2021-04-20 14:07:54.771 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 14:07:54.771 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 14:07:54.770 Error: dzVents: Debug: getDomoticzErrorLog: No (new) occurrences of string Error: Error opening url: http://www.TESTERROR in the domoticz log
2021-04-20 14:07:54.794 Error: Error opening url: http://www.TESTERROR
2021-04-20 14:07:54.915 Error: Error opening url: http://www.TESTERROR
2021-04-20 14:08:15.825 (Virtual devices) Light/Switch (test_switch)
2021-04-20 14:08:15.924 Notification sent (browser) => Success
2021-04-20 14:08:15.824 Status: User: Admin initiated a switch command (2/test_switch/Off)
2021-04-20 14:08:15.846 Status: dzVents: Info: Handling events for: "test_switch", value: "Off"
2021-04-20 14:08:15.847 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: Device: "test_switch (Virtual devices)", Index: 2
2021-04-20 14:08:15.847 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=getlog&lastlogtime=1618920473&loglevel=4
2021-04-20 14:08:15.847 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: method = GET
2021-04-20 14:08:15.847 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: post data = nil
2021-04-20 14:08:15.847 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: headers = nil
2021-04-20 14:08:15.847 Status: dzVents: Debug: getDomoticzErrorLog: OpenURL: callback = getDomoticzErrorLog
2021-04-20 14:08:15.847 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 14:08:15.847 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 14:08:15.904 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2021-04-20 14:08:15.904 Status: dzVents: Info: getDomoticzErrorLog: ------ Start internal script: Script #5: HTTPResponse: "getDomoticzErrorLog"
2021-04-20 14:08:15.905 Status: dzVents: Info: getDomoticzErrorLog: ------ Finished Script #5
2021-04-20 14:08:15.905 Status: EventSystem: Script event triggered: /root/dev-domoticz/dzVents/runtime/dzVents.lua
2021-04-20 14:08:15.924 Status: Notification: Log 2021-04-20 14:07:54.915 Error: Error opening url: http://www.TESTERROR found!
2021-04-20 14:08:15.905 Error: dzVents: Debug: getDomoticzErrorLog: Log Error: Error opening url: http://www.TESTERROR found!
2021-04-20 14:08:16.505 Notification sent (fcm) => Success
2021-04-20 14:08:16.049 Error: Error opening url: http://test_off_error 

It does not recognize it at first time, just second time ... and i receive GCM notification to my mobile just "1"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest