Page 1 of 1
Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 12:37
by alanlsmith
There is the following error appearing in the log every minute after updating to
Domoticz beta v4.11696 - dzVents 3.0.0
Code: Select all
Error: EventSystem: in /home/user/domoticz/dzVents/runtime/dzVents.lua: /home/user/domoticz/dzVents/runtime/EventHelpers.lua:462: bad argument #1 to 'for iterator' (table expected, got string)
I have only one dzVents script which was triggered on a time every 10 minutes. I have now changed this to be triggered by a switch but the error persists.
No other dzVents debugging messages are displayed with the error
Just for completeness. If I disable dzVents the error stops.
I have a number of vanilla lua time based scripts.
Edit: Just see another reference to this message, with no further details and perhaps I should have put this in the 'Bugs' section, although I'm not sure if it is. Could just be something I've done, although can't think what.
Re: Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 12:50
by waaren
alanlsmith wrote: ↑Tuesday 18 February 2020 12:37
Code: Select all
Error: EventSystem: in /home/user/domoticz/dzVents/runtime/dzVents.lua: /home/user/domoticz/dzVents/runtime/EventHelpers.lua:462: bad argument #1 to 'for iterator' (table expected, got string)
Can you please put this as line 461 in <domoticz dir>/dzVents/runtime/EventHelpers.lua ? It will not solve the error but will give some extra information in the logfile. Thx.
Code: Select all
utils.log(timeRules, utils.LOG_ERROR)
Can you also check there a no 'old' scripts left in <domoticz dir>/scripts/dzVents/scripts/ and/or in
<domoticz dir>/scripts/dzVents/generated_scripts/
Re: Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 14:39
by alanlsmith
Sorry for the delay.
After adding your code line to 'EventHelpers.lua' . The log now shows:
Code: Select all
020-02-18 13:20:00.139 Error: dzVents: Error: (3.0.0) {"every 5 minutes"}
2020-02-18 13:20:00.139 Error: dzVents: Error: (3.0.0) every minute
2020-02-18 13:20:00.139 Error:EventSystem:i n/home/user/domoticz/dzVents/runtime/dzVents.lua: /home/user/domoticz/dzVents/runtime/EventHelpers.lua:464: bad argument #1 to 'for iterator' (table expected, got string)
I had 2 scripts in the ~scripts/dzVents/scripts folder one was a "test" which I had forgotten about with a 1 munute timer and the other was the "check_for_intruders.lua" from this forum
If I remove the script with the 1 minute time the original error goes away and only the line in the log remains every minute.
Code: Select all
020-02-18 13:20:00.139 Error: dzVents: Error: (3.0.0) {"every 5 minutes"}
Also, significantly the script does not run at 5 minute intervals, or at all for that matter.
The first part of the script looks okay to me
Code: Select all
on = { httpResponses = { myHttpResponse },
timer = { 'every 5 minutes'},
},
Re: Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 15:40
by waaren
alanlsmith wrote: ↑Tuesday 18 February 2020 14:39
If I remove the script with the 1 minute time the original error goes away and only the line in the log remains every minute.
Code: Select all
020-02-18 13:20:00.139 Error: dzVents: Error: (3.0.0) {"every 5 minutes"}
Also, significantly the script does not run at 5 minute intervals, or at all for that matter.
The first part of the script looks okay to me
Code: Select all
on = { httpResponses = { myHttpResponse },
timer = { 'every 5 minutes'},
},
OK you can remove the extra line now. It served its purpose as it identified the line with the error. ( The one with timer = 'every minute' )
Please show the complete script. and all the loglines. myHttpResponse without any context wil not work. It should be set before.
Re: Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 18:56
by alanlsmith
@Warren, Thanks for your quick and helpful replies.
The simple problem with the "Every minute" script was that I had not put curly brackets around 'every minute'
The "every 5 minutes script" however still does not run at the specified intervals, it did before the last update.
'myHttpResponse' is defined as myHttpResponse = "getDomoticzErrorLog"
Here is the complete script. there doesn't seem to be any errors in the log related to this.
Code: Select all
-- getFailedLogin.lua
myHttpResponse = "getDomoticzErrorLog"
return {
on = { httpResponses = { myHttpResponse },
timer = { 'every 5 minutes'},
-- devices = { "getErrorTrigger"} -- Only used for development and testing
},
logging = { level = domoticz.LOG_INFO,
marker = "getFailedLoging" },
data = { lastlogtime = { initial = 0 }},
execute = function(dz, trigger)
local violationMessage = "Failed authentication attempt" -- 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" ..
"¶m=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 = os.time(os.date('*t')) -- store current Time as seconds from epoch
dz.log(logURL,dz.LOG_DEBUG)
end
local function findViolation()
local violation = ""
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
if string.find(resultTable[i].message,violationMessage) and
not(string.find(resultTable[i].message,"dzVents")) then -- We don't want debug messages to interfere
violation = violation .. "\n".. resultTable[i].message
end
end
end
return violation
end
if trigger.isDevice or trigger.isTimer then
askDomoticzForLogLines() -- get the relevant loglines
elseif trigger.ok then
local violation = findViolation()
if violation == "" then
dz.log("No (new) violations found",dz.LOG_DEBUG)
else
dz.log("violation(s) found: " .. violation,dz.LOG_INFO)
dz.notify("Access violation",violation, dz.PRIORITY_NORMAL,nil,"Alans_Phone",dz.NSS_PUSHOVER)
end
else
dz.log("Access problem to log",dz.LOG_ERROR)
end
end
}
Re: Error message referring to EventHelpers.lua
Posted: Tuesday 18 February 2020 19:57
by waaren
alanlsmith wrote: ↑Tuesday 18 February 2020 18:56
The "every 5 minutes script" however still does not run at the specified intervals, it did before the last update.
I don't know why it does not execute on your system. Could it be that it does but that your setting for showing what dzVents are different then before.
At the bottom of the page you get when you go to [Setup] [Settings] [Other] you can set what dzVents shows.
PLease set that to
Errors + minimal execution info + generic info
I changed the level of some log output in the script below to show some additional info. At my system is shows.
- Spoiler: show
-
Code: Select all
2020-02-18 19:50:00.305 Status: dzVents: Info: getFailedLoging: ------ Start internal script: Script #1:, trigger: "every 5 minutes"
2020-02-18 19:50:00.305 Status: dzVents: Debug: getFailedLoging: OpenURL: url = http://127.0.0.1:8084/json.htm?type=command¶m=getlog&lastlogtime=1582051500&loglevel=4
2020-02-18 19:50:00.305 Status: dzVents: Debug: getFailedLoging: OpenURL: method = GET
2020-02-18 19:50:00.305 Status: dzVents: Debug: getFailedLoging: OpenURL: post data = nil
2020-02-18 19:50:00.305 Status: dzVents: Debug: getFailedLoging: OpenURL: headers = nil
2020-02-18 19:50:00.305 Status: dzVents: Debug: getFailedLoging: OpenURL: callback = getDomoticzErrorLog
2020-02-18 19:50:00.305 Status: dzVents: Info: getFailedLoging: ------ Finished Script #1
2020-02-18 19:50:00.368 Status: dzVents: Info: Handling httpResponse-events for: "getDomoticzErrorLog"
2020-02-18 19:50:00.369 Status: dzVents: Info: getFailedLoging: ------ Start internal script: Script #1: HTTPResponse: "getDomoticzErrorLog"
2020-02-18 19:50:00.370 Status: dzVents: Debug: getFailedLoging: No (new) violations found
2020-02-18 19:50:00.371 Status: dzVents: Info: getFailedLoging: ------ Finished Script #1
The script with some minor changes.
Code: Select all
-- getFailedLogin.lua
local myHttpResponse = 'getDomoticzErrorLog'
return
{
on =
{
httpResponses =
{
myHttpResponse,
},
timer =
{
'every 5 minutes',
},
-- devices = { 'getErrorTrigger' } -- Only used for development and testing
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_INFO when script is OK
marker = 'getFailedLoging',
},
data =
{
lastlogtime =
{
initial = 0,
},
},
execute = function(dz, trigger)
local violationMessage = 'Failed authentication attempt' -- 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' ..
'¶m=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 = os.time() -- store current Time as seconds from epoch
end
local function findViolation()
local violation = ''
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
if string.find(resultTable[i].message, violationMessage) and
not(string.find(resultTable[i].message, 'dzVents')) then -- We don't want debug messages to interfere
violation = violation .. '\n'.. resultTable[i].message
end
end
end
return violation
end
if trigger.isDevice or trigger.isTimer then
askDomoticzForLogLines() -- get the relevant loglines
elseif trigger.ok then
local violation = findViolation()
if violation == '' then
dz.log('No (new) violations found', dz.LOG_DEBUG)
else
dz.log('violation(s) found: ' .. violation, dz.LOG_FORCE)
dz.notify('Access violation', violation, dz.PRIORITY_NORMAL, nil, 'Alans_Phone', dz.NSS_PUSHOVER)
end
else
dz.log('Access problem to log', dz.LOG_ERROR)
end
end
}
Re: Error message referring to EventHelpers.lua
Posted: Wednesday 19 February 2020 14:13
by alanlsmith
@waarren Again sorry for the delay in replying.
I had the 'Intruders' script set for every 5 minutes and another script to download "Dark Sky" weather every 10 minutes. Both were working up until 10:00 on Feb 17.
At 10:09 on Feb 17 I updated Domoticz to beta 4.11896.
After that I was getting the error message related to EventHelper.lua and neither script ran at the intervals set by the timer.
At your advice I looked at the dzVents scripts in my system and found the error in one where I had omitted the 'curly brackets' around the timer statement in the script set to run ever minute.
After that the error message related to EventHelpers.lua stopped appearing in the log and both scripts ran on time as expected.
So it seems that dzVents previously tolerated my mistake in the 'every minute' script but the update in v4.11696 it didn't.
At the same time I got sidetracked by the issue with the 'uservariables_lastupdate' table as I had some scripts relying on that. So to be honest I think I got a bit confused trying to see what was and wasn't working.
But
Now problem resolved and thank you for your help.
Re: Error message referring to EventHelpers.lua [Solved]
Posted: Wednesday 19 February 2020 14:18
by waaren
alanlsmith wrote: ↑Wednesday 19 February 2020 14:13
...
At the same time I got sidetracked by the issue with the 'uservariables_lastupdate' table as I had some scripts relying on that.
Now problem resolved ...
Good to read it's working again.
btw. The issue with 'uservariables_lastupdate' table is fixed in latest Beta (V4.11706)