Logic Machine Forum
Button for exporting alarms in CSV locally - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Button for exporting alarms in CSV locally (/showthread.php?tid=5377)



Button for exporting alarms in CSV locally - Ceros2112 - 23.04.2024

Hello,

is it possible to export all the alarms by pushing a button in the visualization locally on the machine as a CSV file without being logged in as administrator?


RE: Button for exporting alarms in CSV locally - admin - 23.04.2024

Create alerts.lp file and upload it to user directory via FTP using apps login.
Code:
<?

require('apps')

setdlheader('text/csv; charset=utf-8', 'Alerts', 'csv')

rows = { '"Date/time","Script name","Message"' }
items = db:getall('SELECT * FROM alerts ORDER BY id DESC')

for _, item in ipairs(items) do
  datetime = os.date('%c', item.alerttime)
  rows[ #rows + 1 ] = string.format('%q,%q,%q',
    datetime, item.scriptname, item.alert)
end

csv = table.concat(rows, '\n')

write(csv)

Then in visualization create a link that points to /user/alerts.lp


RE: Button for exporting alarms in CSV locally - Ceros2112 - 23.04.2024

Thank you, it works perfectly