{"action":"created","comment":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/26439299","id":26439299,"diff_hunk":"@@ -0,0 +1,313 @@\n+import atexit\n+import glob\n+import logging\n+import os.path\n+import re\n+import simplejson as json\n+import subprocess\n+import sys\n+import tarfile\n+import tempfile\n+from time import strftime\n+\n+# DD imports\n+from checks.check_status import CollectorStatus, DogstatsdStatus, ForwarderStatus\n+from config import (\n+    check_yaml,\n+    get_confd_path,\n+    get_config,\n+    get_config_path,\n+    get_logging_config,\n+    get_os,\n+)\n+from util import (\n+    get_hostname,\n+    Platform,\n+)\n+\n+# 3p\n+import requests\n+\n+\n+# Globals\n+log = logging.getLogger('flare')\n+\n+def configcheck():\n+    osname = get_os()\n+    all_valid = True\n+    for conf_path in glob.glob(os.path.join(get_confd_path(osname), \"*.yaml\")):\n+        basename = os.path.basename(conf_path)\n+        try:\n+            check_yaml(conf_path)\n+        except Exception, e:\n+            all_valid = False\n+            print \"%s contains errors:\\n    %s\" % (basename, e)\n+        else:\n+            print \"%s is valid\" % basename\n+    if all_valid:\n+        print \"All yaml files passed. You can now run the Datadog agent.\"\n+        return 0\n+    else:\n+        print(\"Fix the invalid yaml files above in order to start the Datadog agent. \"\n+                \"A useful external tool for yaml parsing can be found at \"\n+                \"http://yaml-online-parser.appspot.com/\")\n+        return 1\n+\n+class Flare(object):\n+    \"\"\"\n+    Compress all important logs and configuration files for debug,\n+    and then send them to Datadog (which transfers them to Support)\n+    \"\"\"\n+\n+    DATADOG_SUPPORT_URL = '/zendesk/flare'\n+    PASSWORD_REGEX = re.compile('( *(\\w|_)*pass(word)?:).+')\n+    COMMENT_REGEX = re.compile('^ *#.*')\n+    APIKEY_REGEX = re.compile('^api_key: *\\w+(\\w{5})$')\n+    REPLACE_APIKEY = r'api_key: *************************\\1'\n+    COMPRESSED_FILE = 'datadog-agent-{0}.tar.bz2'\n+    # We limit to 10MB arbitrary\n+    MAX_UPLOAD_SIZE = 10485000\n+\n+\n+    def __init__(self, cmdline=False, case_id=None):\n+        self._case_id = case_id\n+        self._cmdline = cmdline\n+        self._init_tarfile()\n+        self._save_logs_path()\n+        config = get_config()\n+        self._api_key = config.get('api_key')\n+        self._url = \"{0}{1}\".format(config.get('dd_url'), self.DATADOG_SUPPORT_URL)\n+        self._hostname = get_hostname(config)\n+        self._prefix = \"datadog-{0}\".format(self._hostname)\n+\n+    # Collect all conf and logs files and compress them\n+    def collect(self):\n+        if not self._api_key:\n+            raise Exception('No api_key found')\n+        log.info(\"Collecting logs and configuration files:\")\n+\n+        self._add_logs_tar()\n+        self._add_conf_tar()\n+        log.info(\"  * datadog-agent configcheck output\")\n+        self._add_command_output_tar('configcheck.log', configcheck)\n+        log.info(\"  * datadog-agent status output\")\n+        self._add_command_output_tar('status.log', self._supervisor_status)\n+        log.info(\"  * datadog-agent info output\")\n+        self._add_command_output_tar('info.log', self._info_all)\n+        log.info(\"  * pip freeze\")\n+        self._add_command_output_tar('freeze.log', self._pip_freeze)\n+\n+        log.info(\"Saving all files to {0}\".format(self._tar_path))\n+        self._tar.close()\n+\n+    # Upload the tar file\n+    def upload(self, confirmation=True):\n+        self._check_size()\n+\n+        if confirmation:\n+            self._ask_for_confirmation()\n+\n+        email = self._ask_for_email()\n+\n+        log.info(\"Uploading {0} to Datadog Support\".format(self._tar_path))\n+        url = self._url\n+        if self._case_id:\n+            url = '{0}/{1}'.format(self._url, str(self._case_id))\n+        files = {'flare_file': open(self._tar_path, 'rb')}\n+        data = {\n+            'api_key': self._api_key,\n+            'case_id': self._case_id,\n+            'hostname': self._hostname,\n+            'email': email\n+        }\n+        r = requests.post(url, files=files, data=data)","path":"utils/flare.py","position":123,"original_position":123,"commit_id":"f08a494dbe3ed51abe66cc7fb3abcf01651af3a8","original_commit_id":"f08a494dbe3ed51abe66cc7fb3abcf01651af3a8","user":{"login":"remh","id":1311477,"avatar_url":"https://avatars.githubusercontent.com/u/1311477?v=3","gravatar_id":"","url":"https://api.github.com/users/remh","html_url":"https://github.com/remh","followers_url":"https://api.github.com/users/remh/followers","following_url":"https://api.github.com/users/remh/following{/other_user}","gists_url":"https://api.github.com/users/remh/gists{/gist_id}","starred_url":"https://api.github.com/users/remh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remh/subscriptions","organizations_url":"https://api.github.com/users/remh/orgs","repos_url":"https://api.github.com/users/remh/repos","events_url":"https://api.github.com/users/remh/events{/privacy}","received_events_url":"https://api.github.com/users/remh/received_events","type":"User","site_admin":false},"body":"Could we pass the apikey as a query string parameter ?","created_at":"2015-03-14T16:42:02Z","updated_at":"2015-03-14T16:42:02Z","html_url":"https://github.com/DataDog/dd-agent/pull/1422#discussion_r26439299","pull_request_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422","_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/26439299"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/1422#discussion_r26439299"},"pull_request":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422"}}},"pull_request":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422","id":31070378,"html_url":"https://github.com/DataDog/dd-agent/pull/1422","diff_url":"https://github.com/DataDog/dd-agent/pull/1422.diff","patch_url":"https://github.com/DataDog/dd-agent/pull/1422.patch","issue_url":"https://api.github.com/repos/DataDog/dd-agent/issues/1422","number":1422,"state":"open","locked":false,"title":"[core] add flare feature (contact support)","user":{"login":"degemer","id":4912048,"avatar_url":"https://avatars.githubusercontent.com/u/4912048?v=3","gravatar_id":"","url":"https://api.github.com/users/degemer","html_url":"https://github.com/degemer","followers_url":"https://api.github.com/users/degemer/followers","following_url":"https://api.github.com/users/degemer/following{/other_user}","gists_url":"https://api.github.com/users/degemer/gists{/gist_id}","starred_url":"https://api.github.com/users/degemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/degemer/subscriptions","organizations_url":"https://api.github.com/users/degemer/orgs","repos_url":"https://api.github.com/users/degemer/repos","events_url":"https://api.github.com/users/degemer/events{/privacy}","received_events_url":"https://api.github.com/users/degemer/received_events","type":"User","site_admin":false},"body":"- Create a Flare class to collect all relevant files (logs &\r\n  configuration files), and then upload them to datadog, which will\r\n  transfer them to support\r\n- Put all code relative to the configcheck in a function for reusability\r\n- add the flare option to init.d script\r\n\r\nAs I said, it adds some imports and probably belongs somewhere else. (at least to be easily accessible from the GUI for Windows/Mac)","created_at":"2015-03-12T19:39:58Z","updated_at":"2015-03-14T16:42:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"646bc381deebefc3f076800e1a364b561eea7758","assignee":null,"milestone":{"url":"https://api.github.com/repos/DataDog/dd-agent/milestones/39","html_url":"https://github.com/DataDog/dd-agent/milestones/5.3.0","labels_url":"https://api.github.com/repos/DataDog/dd-agent/milestones/39/labels","id":804852,"number":39,"title":"5.3.0","description":null,"creator":{"login":"remh","id":1311477,"avatar_url":"https://avatars.githubusercontent.com/u/1311477?v=3","gravatar_id":"","url":"https://api.github.com/users/remh","html_url":"https://github.com/remh","followers_url":"https://api.github.com/users/remh/followers","following_url":"https://api.github.com/users/remh/following{/other_user}","gists_url":"https://api.github.com/users/remh/gists{/gist_id}","starred_url":"https://api.github.com/users/remh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remh/subscriptions","organizations_url":"https://api.github.com/users/remh/orgs","repos_url":"https://api.github.com/users/remh/repos","events_url":"https://api.github.com/users/remh/events{/privacy}","received_events_url":"https://api.github.com/users/remh/received_events","type":"User","site_admin":false},"open_issues":50,"closed_issues":45,"state":"open","created_at":"2014-09-26T22:24:37Z","updated_at":"2015-03-13T23:01:25Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422/commits","review_comments_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422/comments","review_comment_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/issues/1422/comments","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/f08a494dbe3ed51abe66cc7fb3abcf01651af3a8","head":{"label":"DataDog:quentin/flare","ref":"quentin/flare","sha":"f08a494dbe3ed51abe66cc7fb3abcf01651af3a8","user":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":1210071,"name":"dd-agent","full_name":"DataDog/dd-agent","owner":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/dd-agent","description":"Datadog Agent","fork":false,"url":"https://api.github.com/repos/DataDog/dd-agent","forks_url":"https://api.github.com/repos/DataDog/dd-agent/forks","keys_url":"https://api.github.com/repos/DataDog/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-agent/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-agent/events","assignees_url":"https://api.github.com/repos/DataDog/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-agent/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-agent/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-agent/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-agent/merges","archive_url":"https://api.github.com/repos/DataDog/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-agent/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-agent/releases{/id}","created_at":"2010-12-31T03:02:47Z","updated_at":"2015-03-13T23:01:25Z","pushed_at":"2015-03-14T16:41:32Z","git_url":"git://github.com/DataDog/dd-agent.git","ssh_url":"git@github.com:DataDog/dd-agent.git","clone_url":"https://github.com/DataDog/dd-agent.git","svn_url":"https://github.com/DataDog/dd-agent","homepage":"http://docs.datadoghq.com/","size":44479,"stargazers_count":259,"watchers_count":259,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":182,"mirror_url":null,"open_issues_count":161,"forks":182,"open_issues":161,"watchers":259,"default_branch":"master"}},"base":{"label":"DataDog:master","ref":"master","sha":"f5115a49619f308fe16eaad3bba7490fae32ca1b","user":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":1210071,"name":"dd-agent","full_name":"DataDog/dd-agent","owner":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/dd-agent","description":"Datadog Agent","fork":false,"url":"https://api.github.com/repos/DataDog/dd-agent","forks_url":"https://api.github.com/repos/DataDog/dd-agent/forks","keys_url":"https://api.github.com/repos/DataDog/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-agent/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-agent/events","assignees_url":"https://api.github.com/repos/DataDog/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-agent/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-agent/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-agent/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-agent/merges","archive_url":"https://api.github.com/repos/DataDog/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-agent/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-agent/releases{/id}","created_at":"2010-12-31T03:02:47Z","updated_at":"2015-03-13T23:01:25Z","pushed_at":"2015-03-14T16:41:32Z","git_url":"git://github.com/DataDog/dd-agent.git","ssh_url":"git@github.com:DataDog/dd-agent.git","clone_url":"https://github.com/DataDog/dd-agent.git","svn_url":"https://github.com/DataDog/dd-agent","homepage":"http://docs.datadoghq.com/","size":44479,"stargazers_count":259,"watchers_count":259,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":182,"mirror_url":null,"open_issues_count":161,"forks":182,"open_issues":161,"watchers":259,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/1422"},"issue":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/1422"},"comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/1422/comments"},"review_comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422/comments"},"review_comment":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1422/commits"},"statuses":{"href":"https://api.github.com/repos/DataDog/dd-agent/statuses/f08a494dbe3ed51abe66cc7fb3abcf01651af3a8"}}}}