{"action":"created","comment":{"url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/comments/57643446","id":57643446,"diff_hunk":"@@ -0,0 +1,86 @@\n+require \"os\"\n+require \"string\"\n+require \"table\"\n+\n+local cjson = require(\"cjson\")\n+\n+--[=[\n+Encodes a message to JSON\n+Config fields are optional.\n+\n+Config:\n+\n+- skip_fields (string, optional, default \"\")\n+    Space delimited set of fields that should *not* be included in the\n+    json record being generated. Any fieldname values of \"Type\",\n+    \"Payload\", \"Hostname\", \"Pid\", \"Logger\", \"Severity\", or \"EnvVersion\" will\n+    be assumed to refer to the corresponding field from the base message\n+    schema, any other values will be assumed to refer to a dynamic message\n+    field.\n+- delimiter (string, optional, default \"\")\n+    Adds the specified delimiter to the end of each message\n+\n+\n+*Example Heka Configuration*\n+\n+.. code-block:: ini\n+[JSONEncoder]\n+type = \"SandboxEncoder\"\n+script_type = \"lua\"\n+filename = \"json_encoder.lua\"\n+   [JSONEncoder.config]\n+    delimiter = \"\\n\"\n+\n+[HttpOutput]\n+address = \"https://my-json-service.com/\"\n+message_matcher = \"<MESSAGE_MATCHER>\"\n+encoder = \"JSONEncoder\"\n+--]=]\n+\n+local skip_fields_str = read_config(\"skip_fields\")\n+local skip_fields = {}\n+if skip_fields_str then\n+    for field in string.gmatch(skip_fields_str, \"[%S]+\") do\n+        skip_fields[field] = true\n+    end\n+end\n+local delimiter = read_config(\"delimiter\")\n+if delimiter == nil then\n+    delimiter = \"\"\n+end\n+local base_fields = {\n+    EnvVersion = true,\n+    Hostname = true,\n+    Logger = true,\n+    Payload = true,\n+    Pid = true,\n+    Severity = true,\n+    Timestamp = true,\n+    Type = true\n+}\n+\n+\n+function process_message()\n+    local output = {}\n+\n+    -- Process heka fields\n+    for field in pairs(base_fields) do\n+        if not skip_fields[field] then\n+            output[field] = read_message(field)\n+        end\n+    end\n+\n+    -- Process dynamic fields\n+    while true do\n+        local typ, name, value, representation, count = read_next_field()\n+        if not typ then break end\n+        if typ ~= 1 then -- exclude bytes\n+            if not skip_fields[name] then\n+                output[name] = value\n+            end\n+        end\n+    end\n+\n+    inject_payload(\"json\", \"json\", cjson.encode(output) .. delimiter)","path":"lua/encoders/json_encoder.lua","position":84,"original_position":84,"commit_id":"50c15b3976321ecf8ba5538e035ce2d7bab84ea8","original_commit_id":"50c15b3976321ecf8ba5538e035ce2d7bab84ea8","user":{"login":"burnsed","id":1879094,"avatar_url":"https://avatars.githubusercontent.com/u/1879094?v=3","gravatar_id":"","url":"https://api.github.com/users/burnsed","html_url":"https://github.com/burnsed","followers_url":"https://api.github.com/users/burnsed/followers","following_url":"https://api.github.com/users/burnsed/following{/other_user}","gists_url":"https://api.github.com/users/burnsed/gists{/gist_id}","starred_url":"https://api.github.com/users/burnsed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burnsed/subscriptions","organizations_url":"https://api.github.com/users/burnsed/orgs","repos_url":"https://api.github.com/users/burnsed/repos","events_url":"https://api.github.com/users/burnsed/events{/privacy}","received_events_url":"https://api.github.com/users/burnsed/received_events","type":"User","site_admin":false},"body":"never mind. if encode() fails, it will raise an error and heka should report it and treat the encoder as having failed","created_at":"2016-03-28T22:20:11Z","updated_at":"2016-03-28T22:20:11Z","html_url":"https://github.com/Clever/heka-clever-plugins/pull/54#discussion_r57643446","pull_request_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54","_links":{"self":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/comments/57643446"},"html":{"href":"https://github.com/Clever/heka-clever-plugins/pull/54#discussion_r57643446"},"pull_request":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54"}}},"pull_request":{"url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54","id":64213438,"html_url":"https://github.com/Clever/heka-clever-plugins/pull/54","diff_url":"https://github.com/Clever/heka-clever-plugins/pull/54.diff","patch_url":"https://github.com/Clever/heka-clever-plugins/pull/54.patch","issue_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/54","number":54,"state":"open","locked":false,"title":"kayvee and debugging improvements","user":{"login":"burnsed","id":1879094,"avatar_url":"https://avatars.githubusercontent.com/u/1879094?v=3","gravatar_id":"","url":"https://api.github.com/users/burnsed","html_url":"https://github.com/burnsed","followers_url":"https://api.github.com/users/burnsed/followers","following_url":"https://api.github.com/users/burnsed/following{/other_user}","gists_url":"https://api.github.com/users/burnsed/gists{/gist_id}","starred_url":"https://api.github.com/users/burnsed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burnsed/subscriptions","organizations_url":"https://api.github.com/users/burnsed/orgs","repos_url":"https://api.github.com/users/burnsed/repos","events_url":"https://api.github.com/users/burnsed/events{/privacy}","received_events_url":"https://api.github.com/users/burnsed/received_events","type":"User","site_admin":false},"body":"* json encoder for easier unit testing\r\n* kayvee - add payload_keep option\r\n\r\nSee https://github.com/Clever/heka-testing/pull/37 for unittests\r\n","created_at":"2016-03-25T22:11:59Z","updated_at":"2016-03-28T22:20:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0892481816a741b8dd74926cdcde6fa6e2be1a29","assignee":{"login":"burnsed","id":1879094,"avatar_url":"https://avatars.githubusercontent.com/u/1879094?v=3","gravatar_id":"","url":"https://api.github.com/users/burnsed","html_url":"https://github.com/burnsed","followers_url":"https://api.github.com/users/burnsed/followers","following_url":"https://api.github.com/users/burnsed/following{/other_user}","gists_url":"https://api.github.com/users/burnsed/gists{/gist_id}","starred_url":"https://api.github.com/users/burnsed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burnsed/subscriptions","organizations_url":"https://api.github.com/users/burnsed/orgs","repos_url":"https://api.github.com/users/burnsed/repos","events_url":"https://api.github.com/users/burnsed/events{/privacy}","received_events_url":"https://api.github.com/users/burnsed/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54/commits","review_comments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54/comments","review_comment_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/54/comments","statuses_url":"https://api.github.com/repos/Clever/heka-clever-plugins/statuses/50c15b3976321ecf8ba5538e035ce2d7bab84ea8","head":{"label":"Clever:INFRA-1541-kayvee-payload","ref":"INFRA-1541-kayvee-payload","sha":"50c15b3976321ecf8ba5538e035ce2d7bab84ea8","user":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"repo":{"id":21475480,"name":"heka-clever-plugins","full_name":"Clever/heka-clever-plugins","owner":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Clever/heka-clever-plugins","description":"Open source heka plugins","fork":false,"url":"https://api.github.com/repos/Clever/heka-clever-plugins","forks_url":"https://api.github.com/repos/Clever/heka-clever-plugins/forks","keys_url":"https://api.github.com/repos/Clever/heka-clever-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Clever/heka-clever-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Clever/heka-clever-plugins/teams","hooks_url":"https://api.github.com/repos/Clever/heka-clever-plugins/hooks","issue_events_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/Clever/heka-clever-plugins/events","assignees_url":"https://api.github.com/repos/Clever/heka-clever-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/Clever/heka-clever-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/Clever/heka-clever-plugins/tags","blobs_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Clever/heka-clever-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/Clever/heka-clever-plugins/languages","stargazers_url":"https://api.github.com/repos/Clever/heka-clever-plugins/stargazers","contributors_url":"https://api.github.com/repos/Clever/heka-clever-plugins/contributors","subscribers_url":"https://api.github.com/repos/Clever/heka-clever-plugins/subscribers","subscription_url":"https://api.github.com/repos/Clever/heka-clever-plugins/subscription","commits_url":"https://api.github.com/repos/Clever/heka-clever-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/Clever/heka-clever-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/Clever/heka-clever-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Clever/heka-clever-plugins/merges","archive_url":"https://api.github.com/repos/Clever/heka-clever-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Clever/heka-clever-plugins/downloads","issues_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/Clever/heka-clever-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/Clever/heka-clever-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Clever/heka-clever-plugins/labels{/name}","releases_url":"https://api.github.com/repos/Clever/heka-clever-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/deployments","created_at":"2014-07-03T20:08:35Z","updated_at":"2016-03-18T10:12:22Z","pushed_at":"2016-03-25T23:08:00Z","git_url":"git://github.com/Clever/heka-clever-plugins.git","ssh_url":"git@github.com:Clever/heka-clever-plugins.git","clone_url":"https://github.com/Clever/heka-clever-plugins.git","svn_url":"https://github.com/Clever/heka-clever-plugins","homepage":"","size":175,"stargazers_count":17,"watchers_count":17,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":3,"forks":6,"open_issues":3,"watchers":17,"default_branch":"master"}},"base":{"label":"Clever:master","ref":"master","sha":"f49db82bf88e021bcfa7729c52cc48937a5ecc83","user":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"repo":{"id":21475480,"name":"heka-clever-plugins","full_name":"Clever/heka-clever-plugins","owner":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Clever/heka-clever-plugins","description":"Open source heka plugins","fork":false,"url":"https://api.github.com/repos/Clever/heka-clever-plugins","forks_url":"https://api.github.com/repos/Clever/heka-clever-plugins/forks","keys_url":"https://api.github.com/repos/Clever/heka-clever-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Clever/heka-clever-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Clever/heka-clever-plugins/teams","hooks_url":"https://api.github.com/repos/Clever/heka-clever-plugins/hooks","issue_events_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/Clever/heka-clever-plugins/events","assignees_url":"https://api.github.com/repos/Clever/heka-clever-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/Clever/heka-clever-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/Clever/heka-clever-plugins/tags","blobs_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Clever/heka-clever-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/Clever/heka-clever-plugins/languages","stargazers_url":"https://api.github.com/repos/Clever/heka-clever-plugins/stargazers","contributors_url":"https://api.github.com/repos/Clever/heka-clever-plugins/contributors","subscribers_url":"https://api.github.com/repos/Clever/heka-clever-plugins/subscribers","subscription_url":"https://api.github.com/repos/Clever/heka-clever-plugins/subscription","commits_url":"https://api.github.com/repos/Clever/heka-clever-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/Clever/heka-clever-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/Clever/heka-clever-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/Clever/heka-clever-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Clever/heka-clever-plugins/merges","archive_url":"https://api.github.com/repos/Clever/heka-clever-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Clever/heka-clever-plugins/downloads","issues_url":"https://api.github.com/repos/Clever/heka-clever-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/Clever/heka-clever-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/Clever/heka-clever-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Clever/heka-clever-plugins/labels{/name}","releases_url":"https://api.github.com/repos/Clever/heka-clever-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/Clever/heka-clever-plugins/deployments","created_at":"2014-07-03T20:08:35Z","updated_at":"2016-03-18T10:12:22Z","pushed_at":"2016-03-25T23:08:00Z","git_url":"git://github.com/Clever/heka-clever-plugins.git","ssh_url":"git@github.com:Clever/heka-clever-plugins.git","clone_url":"https://github.com/Clever/heka-clever-plugins.git","svn_url":"https://github.com/Clever/heka-clever-plugins","homepage":"","size":175,"stargazers_count":17,"watchers_count":17,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":3,"forks":6,"open_issues":3,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54"},"html":{"href":"https://github.com/Clever/heka-clever-plugins/pull/54"},"issue":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/54"},"comments":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/issues/54/comments"},"review_comments":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54/comments"},"review_comment":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/pulls/54/commits"},"statuses":{"href":"https://api.github.com/repos/Clever/heka-clever-plugins/statuses/50c15b3976321ecf8ba5538e035ce2d7bab84ea8"}}}}