21.07.2016, 09:41 (This post was last modified: 22.07.2016, 06:51 by jetsetter.)
Hi,
Is it possible to have an event log presentation in the LM visualization?
For example, each time a door or window contact opens or a PIR is triggered a log line to be created with a time stamp like this:
- Mon 21/7/2016
12:32: Door opened
10:32: Movement detection in living room
.
. - Tue 22/7/2016
21:01: Bedroom window opened
22:12: Door opened
00:00: AC turned off
.
.
. .
This log needs to be stored in memory for a configurable max number of events (lets say up to 1000) and after that limit, any new events will delete the older one etc so anytime you can have the last 1000 events.
Is there a way to create and present in LM visualization such an event log?
Thank you in advance
You can use storage engine to create a queue, here's a function that adds an item to a list named eventlog and trims the list to contain up to 1000 entries. Date/time is added automatically, so you only need to supply event text. Create event scripts to log whichever info you need.
Code:
function eventlog(text)
local max = 1000 -- max number of entries
-- add formatted date
text = os.date('%a %d/%m/%Y %T ') .. text
storage.exec('lpush', 'eventlog', text)
storage.exec('ltrim', 'eventlog', 0, max - 1)
end
To output the list to client side you can create an .lp page and display it in the visualization via iframe. Create a file called eventlog.lp and upload it to user folder via FTP. Set iframe URL to /user/eventlog.lp
Well it works like a charm, thank you once again.
Can I ask if I should be able to see this list in the storage tab?
Also, is it possible to access this log outside the LM or export it for backup or use the information with other programs like excel etc?
Thank you
For now, item type "list" is not supported directly by storage.get, so you won't be able to see it in storage viewer. As for export you can adapt previously published scripts. This command returns all log entries as a Lua table (plain array) and converts them to plain text with each log item on a new line:
Code:
items = storage.exec('lrange', 'eventlog', 0, 999)
text = table.concat(items, '\r\n')
(21.07.2016, 10:15)admin Wrote: You can use storage engine to create a queue, here's a function that adds an item to a list named eventlog and trims the list to contain up to 1000 entries. Date/time is added automatically, so you only need to supply event text. Create event scripts to log whichever info you need.
Code:
function eventlog(text)
local max = 1000 -- max number of entries
-- add formatted date
text = os.date('%a %d/%m/%Y %T ') .. text
storage.exec('lpush', 'eventlog', text)
storage.exec('ltrim', 'eventlog', 0, max - 1)
end
To output the list to client side you can create an .lp page and display it in the visualization via iframe. Create a file called eventlog.lp and upload it to user folder via FTP. Set iframe URL to /user/eventlog.lp
07.01.2022, 11:27 (This post was last modified: 07.01.2022, 11:28 by Re-G.)
(30.12.2021, 15:01)admin Wrote: Place the function definition into Common functions. Then you can call eventlog in any script.
One more questions.
Is possible to clear some logs in eventlog? For example if error is not longer active? For now is working only by Restet/Clean Up (Utility's) and check Script storage. I've tried with Alert manager and is not working. Any ideas?
(21.07.2016, 10:15)admin Wrote: You can use storage engine to create a queue, here's a function that adds an item to a list named eventlog and trims the list to contain up to 1000 entries. Date/time is added automatically, so you only need to supply event text. Create event scripts to log whichever info you need.
Code:
function eventlog(text)
local max = 1000 -- max number of entries
-- add formatted date
text = os.date('%a %d/%m/%Y %T ') .. text
storage.exec('lpush', 'eventlog', text)
storage.exec('ltrim', 'eventlog', 0, max - 1)
end
To output the list to client side you can create an .lp page and display it in the visualization via iframe. Create a file called eventlog.lp and upload it to user folder via FTP. Set iframe URL to /user/eventlog.lp
I coudn't diplay eventlog.lp file as a frame, it will display "File not found: /www/user/eventlog.lp".
I uploaded the file via FileZilla as ou can see in the attachment