aboutsummaryrefslogtreecommitdiff
path: root/docker/heka/plugins/modules/os_utils.lua
diff options
context:
space:
mode:
authorÉric Lemoine <elemoine@mirantis.com>2016-02-05 10:52:07 +0100
committerSam Yaple <sam@yaple.net>2016-02-19 20:28:12 +0000
commit9ef1be1c389658cb57c44bd5a351ad94ac3df61c (patch)
treee053b758fe3b370233ceddc979f573933a52a0e5 /docker/heka/plugins/modules/os_utils.lua
parentd1ddd8687e7e0d924c748c9aebdafed40f232556 (diff)
downloadkolla-9ef1be1c389658cb57c44bd5a351ad94ac3df61c.tar.gz
kolla-9ef1be1c389658cb57c44bd5a351ad94ac3df61c.zip
Add Heka log decoder infrastructure
In the future the Heka Lua sandboxes will be moved out of Kolla, and installed in the Heka container using a deb or rpm package. Partially implements: blueprint heka Change-Id: I34cc80f62ddbca8ee330c971f58fee8686e245e6
Diffstat (limited to 'docker/heka/plugins/modules/os_utils.lua')
-rw-r--r--docker/heka/plugins/modules/os_utils.lua89
1 files changed, 89 insertions, 0 deletions
diff --git a/docker/heka/plugins/modules/os_utils.lua b/docker/heka/plugins/modules/os_utils.lua
new file mode 100644
index 000000000..c5b71c72a
--- /dev/null
+++ b/docker/heka/plugins/modules/os_utils.lua
@@ -0,0 +1,89 @@
+-- Copyright 2015-2016 Mirantis, Inc.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+local cjson = require 'cjson'
+local string = require 'string'
+
+local patt = require 'os_patterns'
+
+local pairs = pairs
+local inject_message = inject_message
+local inject_payload = inject_payload
+local read_message = read_message
+local pcall = pcall
+
+local M = {}
+setfenv(1, M) -- Remove external access to contain everything in the module
+
+severity_to_label_map = {
+ [0] = 'EMERGENCY',
+ [1] = 'ALERT',
+ [2] = 'CRITICAL',
+ [3] = 'ERROR',
+ [4] = 'WARNING',
+ [5] = 'NOTICE',
+ [6] = 'INFO',
+ [7] = 'DEBUG',
+}
+
+label_to_severity_map = {
+ EMERGENCY = 0,
+ ALERT = 1,
+ CRITICAL = 2,
+ ERROR = 3,
+ WARNING = 4,
+ NOTICE = 5,
+ INFO= 6,
+ DEBUG = 7,
+}
+
+function chomp(s)
+ return string.gsub(s, "\n$", "")
+end
+
+-- Call inject_message() wrapped by pcall()
+function safe_inject_message(msg)
+ local ok, err_msg = pcall(inject_message, msg)
+ if not ok then
+ return -1, err_msg
+ else
+ return 0
+ end
+end
+
+-- Call inject_payload() wrapped by pcall()
+function safe_inject_payload(payload_type, payload_name, data)
+ local ok, err_msg = pcall(inject_payload, payload_type, payload_name, data)
+ if not ok then
+ return -1, err_msg
+ else
+ return 0
+ end
+end
+
+-- Shallow comparison between two tables.
+-- Return true if the two tables have the same keys with identical
+-- values, otherwise false.
+function table_equal(t1, t2)
+ -- all key-value pairs in t1 must be in t2
+ for k, v in pairs(t1) do
+ if t2[k] ~= v then return false end
+ end
+ -- there must not be other keys in t2
+ for k, v in pairs(t2) do
+ if t1[k] == nil then return false end
+ end
+ return true
+end
+
+return M