Created
January 23, 2014 19:51
-
-
Save KushalP/8585572 to your computer and use it in GitHub Desktop.
Example of a Heka Lua Sandbox decoder that will take JSON log lines (and some extra decoder config) and stream that information into the `Fields` variables of the Heka message.
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" | |
-- Generic decoder for JSON logs. This will extract all JSON | |
-- keys and add them to the `Fields` variable of the created | |
-- Heka message. | |
-- | |
-- Example use: | |
-- | |
-- [NginxJsonLogDecoder] | |
-- type = "SandboxDecoder" | |
-- script_type = "lua" | |
-- filename = "/location/of/json_log_decode.lua" | |
-- | |
-- [NginxJsonLogDecoder.config] | |
-- app = "some application" | |
-- | |
-- [some-nginx-json-log-file] | |
-- type = "LogfileInput" | |
-- logfile = "/some/location/of/an/nginx/log/file.json.log" | |
-- decoder = "NginxJsonLogDecoder" | |
function process_message() | |
local raw_message = read_message("Payload") | |
local app = read_config("app") | |
local json = cjson.decode(raw_message) | |
if not json then | |
-- When plain text is found, ship it in it's raw form. | |
inject_message(raw_message) | |
return 0 | |
end | |
local message = { | |
Type = "MyGenericNamespace.JsonLog" | |
} | |
if app then | |
json["app"] = app | |
end | |
message.Payload = raw_message | |
message.Fields = json | |
inject_message(message) | |
return 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment