Yesterday, 20:59
I have the exact same Syslog set up in my Resident and Event Scripts - the Resident Scripts Syslog works, however the Event scripts doesnt
The syslog set up that works in Resident is
local socket = require("socket")
-------------------------------------------------
-- SYSLOG CONFIG
-------------------------------------------------
local SYSLOG_HOST = "192.168.1.51"
local SYSLOG_PORT = 1514
local HOSTNAME = "logicmachine"
local APPNAME = "solar-master"
local LOG_INTERVAL = 60 -- seconds
-------------------------------------------------
-- PERSISTENT UDP SOCKET
-------------------------------------------------
storage.syslog_socket = storage.syslog_socket or socket.udp()
local udp = storage.syslog_socket
udp:settimeout(0)
-------------------------------------------------
-- RFC5424 TIMESTAMP
-------------------------------------------------
local function rfc5424_time()
local now = os.time()
local utc = os.time(os.date("!*t", now))
local offset = os.difftime(now, utc)
local sign = "+"
if offset < 0 then sign = "-" end
offset = math.abs(offset)
local hours = math.floor(offset / 3600)
local mins = math.floor((offset % 3600) / 60)
return os.date("%Y-%m-%dT%H:%M:%S") ..
string.format("%s%02d:%02d", sign, hours, mins)
end
-------------------------------------------------
-- SYSLOG SENDER
-------------------------------------------------
local function slog(fields)
local timestamp = rfc5424_time()
local msg = "<14>1 "..timestamp.." "..HOSTNAME.." "..APPNAME.." - - - "..fields
udp:sendto(msg, SYSLOG_HOST, SYSLOG_PORT)
end
What needs to change for an Event Script to behave the same way and allow for logging to an external syslog server?
Thanks
The syslog set up that works in Resident is
local socket = require("socket")
-------------------------------------------------
-- SYSLOG CONFIG
-------------------------------------------------
local SYSLOG_HOST = "192.168.1.51"
local SYSLOG_PORT = 1514
local HOSTNAME = "logicmachine"
local APPNAME = "solar-master"
local LOG_INTERVAL = 60 -- seconds
-------------------------------------------------
-- PERSISTENT UDP SOCKET
-------------------------------------------------
storage.syslog_socket = storage.syslog_socket or socket.udp()
local udp = storage.syslog_socket
udp:settimeout(0)
-------------------------------------------------
-- RFC5424 TIMESTAMP
-------------------------------------------------
local function rfc5424_time()
local now = os.time()
local utc = os.time(os.date("!*t", now))
local offset = os.difftime(now, utc)
local sign = "+"
if offset < 0 then sign = "-" end
offset = math.abs(offset)
local hours = math.floor(offset / 3600)
local mins = math.floor((offset % 3600) / 60)
return os.date("%Y-%m-%dT%H:%M:%S") ..
string.format("%s%02d:%02d", sign, hours, mins)
end
-------------------------------------------------
-- SYSLOG SENDER
-------------------------------------------------
local function slog(fields)
local timestamp = rfc5424_time()
local msg = "<14>1 "..timestamp.." "..HOSTNAME.." "..APPNAME.." - - - "..fields
udp:sendto(msg, SYSLOG_HOST, SYSLOG_PORT)
end
What needs to change for an Event Script to behave the same way and allow for logging to an external syslog server?
Thanks