Last active
August 29, 2015 14:06
-
-
Save rafrombrc/8d7b5713a694b7f8ca11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cjson" | |
local fields = { | |
values = {}, | |
interval = 0, | |
plugin = "", | |
plugin_instance = "", | |
["type"] = "", | |
type_instance = "" | |
} | |
local msg = { | |
Fields = fields, | |
Timestamp = nil, | |
Hostname = nil, | |
Type = "metric_message_type" | |
} | |
function process_message() | |
local payload = read_message("Payload") | |
local ok, metrics = pcall(cjson.decode, payload) | |
if not ok then return -1 end | |
for i, metric in ipairs(metrics) do | |
fields.values = metric.values | |
fields.interval = metric.interval | |
fields.plugin = metric.plugin | |
fields.plugin_instance = metric.plugin_instance | |
fields.type = metric.type | |
fields.type_instance = metric.type_instance | |
local time = tonumber(metric.time) | |
msg.Timestamp = time | |
msg.Hostname = metric.host | |
inject_message(msg) | |
end | |
return 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment