This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Automatic export all logs and send by mail
#18
(16.09.2022, 10:09)admin Wrote: Use this for a single group address. CSV is rather pointless in this case. This script simply shows dates and values in the message body.
Code:
id = buslib.encodega('0/0/1')
to = { 'to1@example.com', 'to2@example.com' }
subject = 'Alarm logs'

logtime = os.time() - 24 * 60 * 60 -- last 24 hours

buffer = {}

query = [[
  SELECT o.datatype, ol.datahex, ol.logtime, ol.eventtype
  FROM objectlog ol
  JOIN objects o ON ol.address=o.id
  WHERE o.id=? AND ol.logtime >= ?
  ORDER BY ol.id DESC
]]

for _, row in ipairs(db:getall(query, id, logtime)) do
  if row.datatype and row.eventtype == 'write' then
    data = grp.decodevalue(row.datahex, row.datatype)
    logdate = os.date('%Y.%m.%d %H:%M:%S', row.logtime)
    buffer[ #buffer + 1 ] = logdate .. ' ' .. tostring(data)
  end
end

message = table.concat(buffer, '\r\n')
mail(to, subject, message)

I will use this script to notify me, when something happened.
Is it possible to use this script not by a adress but with a tag?
Reply


Messages In This Thread
RE: Automatic export all logs and send by mail - by Dré - 26.05.2023, 07:33

Forum Jump: