Skip to content

Instantly share code, notes, and snippets.

@nathwill
Created June 5, 2015 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathwill/8172590b672188a7e03d to your computer and use it in GitHub Desktop.
Save nathwill/8172590b672188a7e03d to your computer and use it in GitHub Desktop.
sensu event encoder for heka
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
--[[
Encodes a heka message as a sensu event
Config:
- status_field (string, optional, default: status)
the message field to use for the event status
*Example Heka Configuration*
.. code-block:: ini
[sensu_event_encoder]
type = "SandboxEncoder"
filename = "lua_encoders/sensu_event.lua"
[sensu_event_encoder.config]
status_field = "exit_code"
[SensuEventOutput]
type = "TcpOutput"
address = "127.0.0.1:3030"
encoder = "sensu_event_encoder"
message_matcher = "Type == 'mytype'"
*Example Output*
.. code-block:: json
{"name":"my_event","output":"payload","status":0}
--]]
local cjson = require "cjson"
local status_field = read_config("status_field") or "status"
function process_message()
local event = {}
event["name"] = read_message("type")
event["output"] = read_message("Payload")
event["status"] = read_message(status_field)
inject_payload("json", "SensuEvent", cjson.encode(event))
return 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment