Logic Machine Forum
Event log creation and presentation - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Event log creation and presentation (/showthread.php?tid=350)

Pages: 1 2


Event log creation and presentation - jetsetter - 21.07.2016

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


RE: Even log creation and presentation - admin - 21.07.2016

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
Code:
<?
require('apps')
items = storage.exec('lrange', 'eventlog', 0, 999)
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Event log</title>
  <script src="/apps/js/jquery.js.gz"></script>
  <link rel="stylesheet" href="/apps/css/bootstrap.css">
</head>
<body>
<script>
$(function() {
  var items = <? json.write(items) ?>
    , container = $('.container')
    , header;

  $.each(items, function(index, item) {
    var chunks = item.split(' ')
      , newheader = chunks.shift() + ' ' + chunks.shift();

    // output data header each time it changes
    if (newheader != header) {
      header = newheader;
      $('<h3></h3>').text(header).appendTo(container);
    }

    // output log entry
    $('<p></p>').text(chunks.join(' ')).appendTo(container);
  });
});
</script>
<div class="container"></div>
</body>
</html>

Note that newest items come on top of the list.
FTP upload docs: http://forum.logicmachine.net/showthread.php?tid=85


RE: Event log creation and presentation - jetsetter - 22.07.2016

Wow, thank you very much for this fast and delicate solution...
I will try it this weekend... Smile


RE: Event log creation and presentation - jetsetter - 25.07.2016

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


RE: Event log creation and presentation - admin - 25.07.2016

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')



RE: Event log creation and presentation - toujour - 03.05.2019

Is it possible show the list with more color ?

For example:
- green for alert finished
- red for alert started


RE: Event log creation and presentation - Daniel - 03.05.2019

(03.05.2019, 09:16)toujour Wrote: Is it possible show the list with more color ?

For example:
- green for alert finished
- red for alert started

Try Alert Manager app.


RE: Event log creation and presentation - toujour - 27.01.2020

I prerfer eventlog (thanks).

How Can I delete old alerts in eventlog ?


RE: Event log creation and presentation - Erwin van der Zwart - 27.01.2020

Hi,

You can only delete them all by the delete button or use the alert manager to delete them by line.

Another option is to reduce the alert log size (default 200) so FIFO will take care of it.

Last option is a SQL query to drop them from the DB, in this case you can make a query to drop entry’s older then x period.

Run this as scheduled script once a day / week
Code:
old = 30 -- days
timestamp = os.time() - (old * 86400)
db:query('delete from alerts where alerttime < ?', timestamp)
BR,

Erwin


RE: Even log creation and presentation - Re-G - 30.12.2021

(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
Code:
<?
require('apps')
items = storage.exec('lrange', 'eventlog', 0, 999)
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Event log</title>
  <script src="/apps/js/jquery.js.gz"></script>
  <link rel="stylesheet" href="/apps/css/bootstrap.css">
</head>
<body>
<script>
$(function() {
  var items = <? json.write(items) ?>
    , container = $('.container')
    , header;

  $.each(items, function(index, item) {
    var chunks = item.split(' ')
      , newheader = chunks.shift() + ' ' + chunks.shift();

    // output data header each time it changes
    if (newheader != header) {
      header = newheader;
      $('<h3></h3>').text(header).appendTo(container);
    }

    // output log entry
    $('<p></p>').text(chunks.join(' ')).appendTo(container);
  });
});
</script>
<div class="container"></div>
</body>
</html>

Note that newest items come on top of the list.
FTP upload docs: http://forum.logicmachine.net/showthread.php?tid=85

Hi. I would like to use this code, but i don't know where i should put this code:
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
event script? resident? sorry im not god coder, please help.


RE: Event log creation and presentation - admin - 30.12.2021

Place the function definition into Common functions. Then you can call eventlog in any script.


RE: Event log creation and presentation - Re-G - 30.12.2021

(30.12.2021, 15:01)admin Wrote: Place the function definition into Common functions. Then you can call eventlog in any script.

Thanks, working like a charm.


RE: Event log creation and presentation - Re-G - 07.01.2022

(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?


Thanks.


RE: Event log creation and presentation - admin - 07.01.2022

If you want to clear the list completely you can simply delete the storage entry:
Code:
storage.delete('eventlog')

You can remove a certain event from the list like this:
Code:
text = 'Fri 07/01/2022 14:13:51 example event'
storage.exec('lrem', 'eventlog', 0, text)

If you want to do this from the UI then it's more complicated. You need an additional .lp to handle delete requests.


RE: Event log creation and presentation - Re-G - 07.01.2022

(07.01.2022, 12:20)admin Wrote: If you want to clear the list completely you can simply delete the storage entry:
Code:
storage.delete('eventlog')

You can remove a certain event from the list like this:
Code:
text = 'Fri 07/01/2022 14:13:51 example event'
storage.exec('lrem', 'eventlog', 0, text)

If you want to do this from the UI then it's more complicated. You need an additional .lp to handle delete requests.
Thanks. This is what's a meant.


RE: Even log creation and presentation - Fahd - 14.09.2022

(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
Code:
<?
require('apps')
items = storage.exec('lrange', 'eventlog', 0, 999)
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Event log</title>
  <script src="/apps/js/jquery.js.gz"></script>
  <link rel="stylesheet" href="/apps/css/bootstrap.css">
</head>
<body>
<script>
$(function() {
  var items = <? json.write(items) ?>
    , container = $('.container')
    , header;

  $.each(items, function(index, item) {
    var chunks = item.split(' ')
      , newheader = chunks.shift() + ' ' + chunks.shift();

    // output data header each time it changes
    if (newheader != header) {
      header = newheader;
      $('<h3></h3>').text(header).appendTo(container);
    }

    // output log entry
    $('<p></p>').text(chunks.join(' ')).appendTo(container);
  });
});
</script>
<div class="container"></div>
</body>
</html>

Note that newest items come on top of the list.
FTP upload docs: http://forum.logicmachine.net/showthread.php?tid=85

Hi,

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


RE: Event log creation and presentation - admin - 14.09.2022

Path should be without www, just "/user/eventlog.lp"


RE: Event log creation and presentation - Fahd - 14.09.2022

(14.09.2022, 11:43)admin Wrote: Path should be without www, just "/user/eventlog.lp"

(14.09.2022, 11:44)Fahd Wrote:
(14.09.2022, 11:43)admin Wrote: Path should be without www, just "/user/eventlog.lp"

It's already without www


RE: Event log creation and presentation - admin - 14.09.2022

Run this once and post what you get in Logs tab:
Code:
log(io.ls('/data/apps/store'))
log(io.ls('/data/apps/store/user'))



RE: Event log creation and presentation - Fahd - 15.09.2022

(14.09.2022, 13:09)admin Wrote: Run this once and post what you get in Logs tab:
Code:
log(io.ls('/data/apps/store'))
log(io.ls('/data/apps/store/user'))
Code:
* table:
[1]
  * string: cron
[2]
  * string: public
[3]
  * string: user
[4]
  * string: libs
[5]
  * string: data
[6]
  * string: cloud
[7]
  * string: daemon

Code:
* table:
[1]
  * string: eventlog.Ip