From 331042858f239d30ea23047491ee44e6b98f6821 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 3 Mar 2016 16:13:08 -0800 Subject: [PATCH] Initial version of outputs.lua --- userspace/digwatch/lua/output.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 userspace/digwatch/lua/output.lua diff --git a/userspace/digwatch/lua/output.lua b/userspace/digwatch/lua/output.lua new file mode 100644 index 00000000..86448b22 --- /dev/null +++ b/userspace/digwatch/lua/output.lua @@ -0,0 +1,30 @@ +local mod = {} + +function mod.syslog(evt, level, format) + nixio = require("nixio") + formatter = digwatch.formatter(format) + msg = digwatch.format_event(evt, formatter) + nixio.syslog(level, msg) +end + + +local first_sequence_state = {} + +function mod.first_sequence(evt, fieldname, key, format) + local field_value = digwatch.field(evt, fieldname) + local now = os.time() + + if first_sequence_state[key] == nil then + first_sequence_state[key] = {} + end + + if first_sequence_state[key][field_value] == nil or + now - first_sequence_state[key][field_value] > 5 then + formatter = digwatch.formatter(format) + msg = digwatch.format_event(evt, formatter) + print (msg) + end + first_sequence_state[key][field_value] = now +end + +return mod