{"action":"created","comment":{"url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/comments/29198447","id":29198447,"diff_hunk":"@@ -0,0 +1,360 @@\n+package com.mulesoft.agent.common.internalhandlers;\n+\n+import com.mulesoft.agent.buffer.BufferedHandler;\n+import com.mulesoft.agent.common.builders.MapMessageBuilder;\n+import com.mulesoft.agent.common.builders.MessageBuilder;\n+import com.mulesoft.agent.configuration.Configurable;\n+import com.mulesoft.agent.configuration.PostConfigure;\n+import com.mulesoft.agent.configuration.Type;\n+import com.splunk.*;\n+import org.apache.logging.log4j.Level;\n+import org.apache.logging.log4j.core.Layout;\n+import org.apache.logging.log4j.core.LogEvent;\n+import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;\n+import org.apache.logging.log4j.core.impl.LogEventFactory;\n+import org.apache.logging.log4j.core.layout.PatternLayout;\n+import org.apache.logging.log4j.message.MapMessage;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.io.IOException;\n+import java.io.OutputStream;\n+import java.io.Serializable;\n+import java.lang.reflect.ParameterizedType;\n+import java.net.Socket;\n+import java.util.Collection;\n+import java.util.Iterator;\n+import java.util.Map;\n+\n+public abstract class AbstractSplunkInternalHandler<T> extends BufferedHandler<T>\n+{\n+    private final static Logger LOGGER = LoggerFactory.getLogger(AbstractSplunkInternalHandler.class);\n+\n+    private Service service;\n+    private Index index;\n+    private MessageBuilder<T, MapMessage> messageBuilder;\n+    private Layout<? extends Serializable> layout;\n+    private LogEventFactory factory = new DefaultLogEventFactory();\n+    private String className = this.getClass().getName();\n+\n+    /**\n+     * http://dev.splunk.com/view/java-sdk/SP-CAAAECX\n+     * By default, the token is valid for one hour, but is refreshed every time you make a call to Splunk.\n+     */\n+    private final int TOKEN_EXPIRATION_MS = 55 * 60 * 1000; // I use 55 minutes, instead of 60 as a safe net.\n+    private long lastConnection;\n+    private boolean isConfigured;\n+\n+    /**\n+     * <p>\n+     * Username to connect to Splunk.\n+     * </p>\n+     */\n+    @Configurable(type = Type.DYNAMIC)\n+    public String user;\n+\n+    /**\n+     * <p>\n+     * The password of the user to connect to Splunk.\n+     * </p>\n+     */\n+    @Configurable(type = Type.DYNAMIC)\n+    public String pass;\n+\n+    /**\n+     * <p>\n+     * IP or hostname of the server where Splunk is running.\n+     * </p>\n+     */\n+    @Configurable(type = Type.DYNAMIC)\n+    public String host;\n+\n+    /**\n+     * <p>\n+     * Splunk management port.\n+     * Default: 8089\n+     * </p>\n+     */\n+    @Configurable(value = \"8089\", type = Type.DYNAMIC)\n+    public int port;\n+\n+    /**\n+     * <p>\n+     * Scheme of connection to the Splunk management port.\n+     * Default: https\n+     * </p>\n+     */\n+    @Configurable(value = \"https\", type = Type.DYNAMIC)\n+    public String scheme;\n+\n+    /**\n+     * <p>\n+     * SSL Security Protocol to use in the https connection.\n+     * Default: TLSv1.2\n+     * </p>\n+     */\n+    @Configurable(value = \"TLSv1_2\", type = Type.DYNAMIC)\n+    public String sslSecurityProtocol;\n+\n+    /**\n+     * <p>\n+     * Splunk index name where all the events will be sent.\n+     * If the user has the rights, and the index doesn't exists, then the internal handler will create it.\n+     * Default: main\n+     * </p>\n+     */\n+    @Configurable(value = \"main\", type = Type.DYNAMIC)\n+    public String splunkIndexName;\n+\n+    /**\n+     * <p>\n+     * The source used on the events sent to Splunk.\n+     * Default: mule\n+     * </p>\n+     */\n+    @Configurable(value = \"mule\", type = Type.DYNAMIC)\n+    public String splunkSource;\n+\n+    /**\n+     * <p>\n+     * The sourcetype used on the events sent to Splunk.\n+     * Default: _json\n+     * </p>\n+     */\n+    @Configurable(value = \"_json\", type = Type.DYNAMIC)\n+    public String splunkSourceType;\n+\n+    /**\n+     * <p>\n+     * Date format used to format the timestamp.\n+     * Default: yyyy-MM-dd'T'HH:mm:ssZ\n+     * </p>\n+     */\n+    @Configurable(value = \"yyyy-MM-dd'T'HH:mm:ssZ\", type = Type.DYNAMIC)\n+    public String dateFormatPattern;\n+\n+\n+    private void initializeLayout (MapMessage message)\n+    {\n+        try\n+        {\n+            this.layout = PatternLayout.createLayout(calculatePattern(message), null, null, null, true, true, null, null);\n+        }\n+        catch (Exception e)\n+        {\n+            LOGGER.error(String.format(\"There was an error creating the pattern: %s.\", this.getPattern()), e);\n+            this.isConfigured = false;\n+        }\n+    }\n+\n+    private MapMessage createMapMessage (T message)\n+    {\n+        MapMessage mapMessage = this.messageBuilder.build(message);\n+        // Append additional properties\n+        Map<String, String> augmentation = augmentMapMessage(message);\n+        if (augmentation != null && !augmentation.isEmpty())\n+        {\n+            mapMessage.putAll(augmentation);\n+        }\n+        return mapMessage;\n+    }\n+\n+    protected Map<String, String> augmentMapMessage (T message)\n+    {\n+        return null;\n+    }\n+\n+    protected boolean isNullOrWhiteSpace (String a)","path":"mule-agent-modules-common/src/main/java/com/mulesoft/agent/common/internalhandlers/AbstractSplunkInternalHandler.java","position":167,"original_position":167,"commit_id":"6a2c44b6888b5bea33b750f0253a0e4c9e2224bc","original_commit_id":"6a2c44b6888b5bea33b750f0253a0e4c9e2224bc","user":{"login":"josesahad","id":1785740,"avatar_url":"https://avatars.githubusercontent.com/u/1785740?v=3","gravatar_id":"","url":"https://api.github.com/users/josesahad","html_url":"https://github.com/josesahad","followers_url":"https://api.github.com/users/josesahad/followers","following_url":"https://api.github.com/users/josesahad/following{/other_user}","gists_url":"https://api.github.com/users/josesahad/gists{/gist_id}","starred_url":"https://api.github.com/users/josesahad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josesahad/subscriptions","organizations_url":"https://api.github.com/users/josesahad/orgs","repos_url":"https://api.github.com/users/josesahad/repos","events_url":"https://api.github.com/users/josesahad/events{/privacy}","received_events_url":"https://api.github.com/users/josesahad/received_events","type":"User","site_admin":false},"body":"Let's replace this for StringUtils, could be added as a provided dependency.","created_at":"2015-04-27T22:30:17Z","updated_at":"2015-04-27T22:30:17Z","html_url":"https://github.com/mulesoft/mule-agent-modules/pull/3#discussion_r29198447","pull_request_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/comments/29198447"},"html":{"href":"https://github.com/mulesoft/mule-agent-modules/pull/3#discussion_r29198447"},"pull_request":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3","id":34197066,"html_url":"https://github.com/mulesoft/mule-agent-modules/pull/3","diff_url":"https://github.com/mulesoft/mule-agent-modules/pull/3.diff","patch_url":"https://github.com/mulesoft/mule-agent-modules/pull/3.patch","issue_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/3","number":3,"state":"open","locked":false,"title":"Added the Log Internal Handler.","user":{"login":"wpoch","id":308915,"avatar_url":"https://avatars.githubusercontent.com/u/308915?v=3","gravatar_id":"","url":"https://api.github.com/users/wpoch","html_url":"https://github.com/wpoch","followers_url":"https://api.github.com/users/wpoch/followers","following_url":"https://api.github.com/users/wpoch/following{/other_user}","gists_url":"https://api.github.com/users/wpoch/gists{/gist_id}","starred_url":"https://api.github.com/users/wpoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpoch/subscriptions","organizations_url":"https://api.github.com/users/wpoch/orgs","repos_url":"https://api.github.com/users/wpoch/repos","events_url":"https://api.github.com/users/wpoch/events{/privacy}","received_events_url":"https://api.github.com/users/wpoch/received_events","type":"User","site_admin":false},"body":"Implemented the new Splunk Java SDK 1.4.0, using the TLS v1.2 protocol avoiding SSLv3.\r\nNew common abstract classes for the 3 different Internal Handlers (DB, Log, Splunk).","created_at":"2015-04-27T18:37:40Z","updated_at":"2015-04-27T22:30:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab1dd8df94eee1d277ba74a19d19ce2fa82a4341","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3/commits","review_comments_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3/comments","review_comment_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/3/comments","statuses_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/statuses/6a2c44b6888b5bea33b750f0253a0e4c9e2224bc","head":{"label":"wpoch:master","ref":"master","sha":"6a2c44b6888b5bea33b750f0253a0e4c9e2224bc","user":{"login":"wpoch","id":308915,"avatar_url":"https://avatars.githubusercontent.com/u/308915?v=3","gravatar_id":"","url":"https://api.github.com/users/wpoch","html_url":"https://github.com/wpoch","followers_url":"https://api.github.com/users/wpoch/followers","following_url":"https://api.github.com/users/wpoch/following{/other_user}","gists_url":"https://api.github.com/users/wpoch/gists{/gist_id}","starred_url":"https://api.github.com/users/wpoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpoch/subscriptions","organizations_url":"https://api.github.com/users/wpoch/orgs","repos_url":"https://api.github.com/users/wpoch/repos","events_url":"https://api.github.com/users/wpoch/events{/privacy}","received_events_url":"https://api.github.com/users/wpoch/received_events","type":"User","site_admin":false},"repo":{"id":31912229,"name":"mule-agent-modules","full_name":"wpoch/mule-agent-modules","owner":{"login":"wpoch","id":308915,"avatar_url":"https://avatars.githubusercontent.com/u/308915?v=3","gravatar_id":"","url":"https://api.github.com/users/wpoch","html_url":"https://github.com/wpoch","followers_url":"https://api.github.com/users/wpoch/followers","following_url":"https://api.github.com/users/wpoch/following{/other_user}","gists_url":"https://api.github.com/users/wpoch/gists{/gist_id}","starred_url":"https://api.github.com/users/wpoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpoch/subscriptions","organizations_url":"https://api.github.com/users/wpoch/orgs","repos_url":"https://api.github.com/users/wpoch/repos","events_url":"https://api.github.com/users/wpoch/events{/privacy}","received_events_url":"https://api.github.com/users/wpoch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wpoch/mule-agent-modules","description":"Mule Agent modules. Please check latest Mule Agent documentation available here http://mulesoft.github.io/mule-agent/","fork":true,"url":"https://api.github.com/repos/wpoch/mule-agent-modules","forks_url":"https://api.github.com/repos/wpoch/mule-agent-modules/forks","keys_url":"https://api.github.com/repos/wpoch/mule-agent-modules/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wpoch/mule-agent-modules/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wpoch/mule-agent-modules/teams","hooks_url":"https://api.github.com/repos/wpoch/mule-agent-modules/hooks","issue_events_url":"https://api.github.com/repos/wpoch/mule-agent-modules/issues/events{/number}","events_url":"https://api.github.com/repos/wpoch/mule-agent-modules/events","assignees_url":"https://api.github.com/repos/wpoch/mule-agent-modules/assignees{/user}","branches_url":"https://api.github.com/repos/wpoch/mule-agent-modules/branches{/branch}","tags_url":"https://api.github.com/repos/wpoch/mule-agent-modules/tags","blobs_url":"https://api.github.com/repos/wpoch/mule-agent-modules/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wpoch/mule-agent-modules/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wpoch/mule-agent-modules/git/refs{/sha}","trees_url":"https://api.github.com/repos/wpoch/mule-agent-modules/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wpoch/mule-agent-modules/statuses/{sha}","languages_url":"https://api.github.com/repos/wpoch/mule-agent-modules/languages","stargazers_url":"https://api.github.com/repos/wpoch/mule-agent-modules/stargazers","contributors_url":"https://api.github.com/repos/wpoch/mule-agent-modules/contributors","subscribers_url":"https://api.github.com/repos/wpoch/mule-agent-modules/subscribers","subscription_url":"https://api.github.com/repos/wpoch/mule-agent-modules/subscription","commits_url":"https://api.github.com/repos/wpoch/mule-agent-modules/commits{/sha}","git_commits_url":"https://api.github.com/repos/wpoch/mule-agent-modules/git/commits{/sha}","comments_url":"https://api.github.com/repos/wpoch/mule-agent-modules/comments{/number}","issue_comment_url":"https://api.github.com/repos/wpoch/mule-agent-modules/issues/comments{/number}","contents_url":"https://api.github.com/repos/wpoch/mule-agent-modules/contents/{+path}","compare_url":"https://api.github.com/repos/wpoch/mule-agent-modules/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wpoch/mule-agent-modules/merges","archive_url":"https://api.github.com/repos/wpoch/mule-agent-modules/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wpoch/mule-agent-modules/downloads","issues_url":"https://api.github.com/repos/wpoch/mule-agent-modules/issues{/number}","pulls_url":"https://api.github.com/repos/wpoch/mule-agent-modules/pulls{/number}","milestones_url":"https://api.github.com/repos/wpoch/mule-agent-modules/milestones{/number}","notifications_url":"https://api.github.com/repos/wpoch/mule-agent-modules/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wpoch/mule-agent-modules/labels{/name}","releases_url":"https://api.github.com/repos/wpoch/mule-agent-modules/releases{/id}","created_at":"2015-03-09T17:21:43Z","updated_at":"2015-04-27T18:36:08Z","pushed_at":"2015-04-27T18:36:08Z","git_url":"git://github.com/wpoch/mule-agent-modules.git","ssh_url":"git@github.com:wpoch/mule-agent-modules.git","clone_url":"https://github.com/wpoch/mule-agent-modules.git","svn_url":"https://github.com/wpoch/mule-agent-modules","homepage":"","size":253,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mulesoft:master","ref":"master","sha":"4d3ba228e51f74a1830afb14776c5b77354b5ebd","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":28194950,"name":"mule-agent-modules","full_name":"mulesoft/mule-agent-modules","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule-agent-modules","description":"Mule Agent modules. Please check latest Mule Agent documentation available here http://mulesoft.github.io/mule-agent/","fork":false,"url":"https://api.github.com/repos/mulesoft/mule-agent-modules","forks_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/forks","keys_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/events","assignees_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/merges","archive_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule-agent-modules/releases{/id}","created_at":"2014-12-18T17:59:04Z","updated_at":"2015-03-31T17:34:21Z","pushed_at":"2015-04-27T18:37:41Z","git_url":"git://github.com/mulesoft/mule-agent-modules.git","ssh_url":"git@github.com:mulesoft/mule-agent-modules.git","clone_url":"https://github.com/mulesoft/mule-agent-modules.git","svn_url":"https://github.com/mulesoft/mule-agent-modules","homepage":"","size":295,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3"},"html":{"href":"https://github.com/mulesoft/mule-agent-modules/pull/3"},"issue":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/3"},"comments":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/mulesoft/mule-agent-modules/statuses/6a2c44b6888b5bea33b750f0253a0e4c9e2224bc"}}}}