@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
}
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.