107
6.3.1. Export logs
Example
Once an hour, make CSV file with all objects logs and send to external FTP server with IP
In Scripting -> Scheduled add the script which will run once an hour
Add the following code in Script editor for this particular script.
1.
require('socket.ftp')
2.
3.
-- ftp file
4.
ftpfile=string.format('ftp://ftplogin:ftppassword@192.168.1.11/%s.csv', os.date('%Y-%m-
%d_%H-%M'))
5.
-- get past hour data (3600 seconds)
6.
logtime=os.time() - 60*60
7.
8.
-- list of objects by id
9.
objects ={}
10.
11.
-- objects with logging enabled
12.
query ='SELECT address, datatype, name FROM objects WHERE disablelog=0'
13.
for _, object in ipairs(db:getall(query)) do
14.
objects[tonumber(object.address)]={
15.
datatype=tonumber(object.datatype),
16.
name =tostring(object.name or''),
17.
}
18.
end
19.