{"action":"created","comment":{"url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/comments/62056052","id":62056052,"diff_hunk":"@@ -0,0 +1,110 @@\n+# -*- coding: utf-8 -*-\n+# Import python libs\n+import json\n+import logging\n+import sys\n+\n+# Import third party libs\n+try:\n+    import redis\n+    HAS_REDIS = True\n+except ImportError:\n+    HAS_REDIS = False\n+\n+'''\n+Return data to a redis server\n+\n+To enable this returner the minion will need the python client for redis\n+installed and the following values configured in the minion or master\n+config, these are the defaults:\n+\n+    redis.db: '0'\n+    redis.host: 'salt'\n+    redis.port: 6379\n+\n+  To use the redis returner, append '--return logstashredis' to the salt command. ex:\n+\n+    salt '*' test.ping --return logstashredis\n+\n+Since bootstrap-salt is an opinionated layer, we've made the following\n+modifications in order to make it for purpose:\n+\n+1. the name of the list where the results are prepended is\n+configurable from the beaver.redis.namespace pillar\n+\n+2. The results along with the minion id, jid, and the actual results\n+are wrapped around in a logstash compatible message\n+\n+3. All functionality relating to the external job cache have been\n+removed as they are not needed by the core returner functionality in\n+current Salt version\n+'''\n+\n+'''\n+This file started as a copy of the redis_returner.py file present\n+in all recent versions of Saltstack.\n+'''\n+\n+\n+# Define the module's virtual name\n+__virtualname__ = 'logstashredis'\n+\n+# Create a logger\n+log = logging.getLogger(__name__)\n+\n+\n+def __virtual__():\n+    if not HAS_REDIS:\n+        return False\n+    return __virtualname__\n+\n+\n+def _get_serv():\n+    '''\n+    Return a redis server object\n+    '''\n+    host = get_salt_config_option(\"redis.host\")\n+    port = get_salt_config_option(\"redis.port\")\n+    db = get_salt_config_option(\"redis.db\")\n+    return redis.Redis(\n+        host, port, db,\n+        socket_timeout=5)\n+\n+\n+def get_pillar(pillar):\n+    try:\n+        log.info(\"Getting pillar {0}\".format(pillar))\n+        val = __salt__['pillar.get'](pillar)  # NOQA\n+        log.info(\"grain {0}:{1}\".format(pillar, val))\n+    except:\n+        log.info(\"Failure to get pillar {0}.\".format(pillar))\n+        val = None\n+\n+    return val\n+\n+\n+def get_salt_config_option(option):\n+    try:\n+        log.info(\"Getting config option {0}\".format(option))\n+        optval = __salt__['config.option'](option)  # NOQA\n+        log.info(\"option: {0}:{1}\".format(option, optval))\n+    except:\n+        log.info(\"Failure to get config option {0}\".format(option))\n+        optval = None\n+\n+    return optval\n+\n+\n+def returner(ret):\n+    '''\n+    Return data to a redis data store\n+    '''\n+    serv = _get_serv()\n+\n+    try:\n+        pillar = get_pillar('beaver:redis:namespace')\n+        print \"push {0}\".format(pillar)","path":"bootstrap_salt/contrib/srv/salt/_returners/logstashredis_return.py","position":106,"original_position":106,"commit_id":"be76557842c0823b672bd64935c4740ac4c4dbdf","original_commit_id":"be76557842c0823b672bd64935c4740ac4c4dbdf","user":{"login":"filipposc5","id":2116658,"avatar_url":"https://avatars.githubusercontent.com/u/2116658?v=3","gravatar_id":"","url":"https://api.github.com/users/filipposc5","html_url":"https://github.com/filipposc5","followers_url":"https://api.github.com/users/filipposc5/followers","following_url":"https://api.github.com/users/filipposc5/following{/other_user}","gists_url":"https://api.github.com/users/filipposc5/gists{/gist_id}","starred_url":"https://api.github.com/users/filipposc5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/filipposc5/subscriptions","organizations_url":"https://api.github.com/users/filipposc5/orgs","repos_url":"https://api.github.com/users/filipposc5/repos","events_url":"https://api.github.com/users/filipposc5/events{/privacy}","received_events_url":"https://api.github.com/users/filipposc5/received_events","type":"User","site_admin":false},"body":"use log here","created_at":"2016-05-04T15:06:32Z","updated_at":"2016-05-04T15:06:32Z","html_url":"https://github.com/ministryofjustice/bootstrap-salt/pull/64#discussion_r62056052","pull_request_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64","_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/comments/62056052"},"html":{"href":"https://github.com/ministryofjustice/bootstrap-salt/pull/64#discussion_r62056052"},"pull_request":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64"}}},"pull_request":{"url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64","id":67353395,"html_url":"https://github.com/ministryofjustice/bootstrap-salt/pull/64","diff_url":"https://github.com/ministryofjustice/bootstrap-salt/pull/64.diff","patch_url":"https://github.com/ministryofjustice/bootstrap-salt/pull/64.patch","issue_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/64","number":64,"state":"open","locked":false,"title":"Add a Logstash/Redis salt returner.","user":{"login":"ltsampros","id":7254274,"avatar_url":"https://avatars.githubusercontent.com/u/7254274?v=3","gravatar_id":"","url":"https://api.github.com/users/ltsampros","html_url":"https://github.com/ltsampros","followers_url":"https://api.github.com/users/ltsampros/followers","following_url":"https://api.github.com/users/ltsampros/following{/other_user}","gists_url":"https://api.github.com/users/ltsampros/gists{/gist_id}","starred_url":"https://api.github.com/users/ltsampros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ltsampros/subscriptions","organizations_url":"https://api.github.com/users/ltsampros/orgs","repos_url":"https://api.github.com/users/ltsampros/repos","events_url":"https://api.github.com/users/ltsampros/events{/privacy}","received_events_url":"https://api.github.com/users/ltsampros/received_events","type":"User","site_admin":false},"body":"This is a flavored Logstash/Redis salt returner which started as a\r\ndirect copy of the salt/_returners/redis_return.py as present in all\r\nrecent versions of Saltstack.","created_at":"2016-04-21T13:26:35Z","updated_at":"2016-05-04T15:06:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fdbe7433850bbb1ed17444f8331869e5187ee0a0","assignee":{"login":"ezman","id":93643,"avatar_url":"https://avatars.githubusercontent.com/u/93643?v=3","gravatar_id":"","url":"https://api.github.com/users/ezman","html_url":"https://github.com/ezman","followers_url":"https://api.github.com/users/ezman/followers","following_url":"https://api.github.com/users/ezman/following{/other_user}","gists_url":"https://api.github.com/users/ezman/gists{/gist_id}","starred_url":"https://api.github.com/users/ezman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezman/subscriptions","organizations_url":"https://api.github.com/users/ezman/orgs","repos_url":"https://api.github.com/users/ezman/repos","events_url":"https://api.github.com/users/ezman/events{/privacy}","received_events_url":"https://api.github.com/users/ezman/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64/commits","review_comments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64/comments","review_comment_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/64/comments","statuses_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/statuses/be76557842c0823b672bd64935c4740ac4c4dbdf","head":{"label":"ministryofjustice:logstashredis-returner","ref":"logstashredis-returner","sha":"be76557842c0823b672bd64935c4740ac4c4dbdf","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":33988352,"name":"bootstrap-salt","full_name":"ministryofjustice/bootstrap-salt","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/bootstrap-salt","description":"","fork":false,"url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt","forks_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/forks","keys_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/events","assignees_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/merges","archive_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/deployments","created_at":"2015-04-15T10:48:11Z","updated_at":"2016-03-31T08:30:25Z","pushed_at":"2016-04-28T14:28:09Z","git_url":"git://github.com/ministryofjustice/bootstrap-salt.git","ssh_url":"git@github.com:ministryofjustice/bootstrap-salt.git","clone_url":"https://github.com/ministryofjustice/bootstrap-salt.git","svn_url":"https://github.com/ministryofjustice/bootstrap-salt","homepage":"","size":221,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":10,"forks":1,"open_issues":10,"watchers":5,"default_branch":"master"}},"base":{"label":"ministryofjustice:master","ref":"master","sha":"ebdaa4f02841541dbc256db64f7203236dd56d3f","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":33988352,"name":"bootstrap-salt","full_name":"ministryofjustice/bootstrap-salt","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/bootstrap-salt","description":"","fork":false,"url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt","forks_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/forks","keys_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/events","assignees_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/merges","archive_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/deployments","created_at":"2015-04-15T10:48:11Z","updated_at":"2016-03-31T08:30:25Z","pushed_at":"2016-04-28T14:28:09Z","git_url":"git://github.com/ministryofjustice/bootstrap-salt.git","ssh_url":"git@github.com:ministryofjustice/bootstrap-salt.git","clone_url":"https://github.com/ministryofjustice/bootstrap-salt.git","svn_url":"https://github.com/ministryofjustice/bootstrap-salt","homepage":"","size":221,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":10,"forks":1,"open_issues":10,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64"},"html":{"href":"https://github.com/ministryofjustice/bootstrap-salt/pull/64"},"issue":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/64"},"comments":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/issues/64/comments"},"review_comments":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64/comments"},"review_comment":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/pulls/64/commits"},"statuses":{"href":"https://api.github.com/repos/ministryofjustice/bootstrap-salt/statuses/be76557842c0823b672bd64935c4740ac4c4dbdf"}}}}