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
#11
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)
Reply


Messages In This Thread
RE: Automatic export all logs and send by mail - by admin - 16.09.2022, 10:09

Forum Jump: