-
-
Save ivanproskuryakov/49a55796b577b4c56952 to your computer and use it in GitHub Desktop.
This file contains hidden or 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