{"action":"created","comment":{"url":"https://api.github.com/repos/edx/api-manager/pulls/comments/66247029","id":66247029,"diff_hunk":"@@ -0,0 +1,206 @@\n+#!/usr/bin/python\n+#\n+# Run this script from the directory its in\n+# This script requires following arguments\n+# --aws-profile (name of the profile to use for aws credentials)\n+# --api-gw (name of the api_gateway)\n+# --splunk-host (splunk host IP and port)\n+# --splunk-token (splunk access token)\n+# e.g.\n+# python monitor.py --aws-profile test --api-gw api --splunk-host 10.2.1.2:99 --splunk-token xxx\n+#\n+\n+import logging\n+import os\n+import time\n+import argparse\n+from zipfile import ZipFile\n+import botocore.session\n+import botocore.exceptions\n+\n+\n+def create_api_alarm(cw_session, alarm_name, metric,\n+                     namespace, stat, comparison, description,\n+                     threshold, period, eval_period, dimensions, topic):\n+    \"\"\"Create the alarm for appropriate metric in API Gateway\"\"\"\n+    response = cw_session.put_metric_alarm(\n+        AlarmName=alarm_name,\n+        AlarmDescription=description,\n+        ActionsEnabled=True,\n+        Namespace=namespace,\n+        Dimensions=dimensions,\n+        MetricName=metric,\n+        Statistic=stat,\n+        Period=period,\n+        EvaluationPeriods=eval_period,\n+        Threshold=threshold,\n+        ComparisonOperator=comparison,\n+        AlarmActions=[topic])\n+\n+    logging.info('response for creating api alarm = \"%s\"',\n+                 response['ResponseMetadata'])\n+\n+\n+def create_firehose_stream(firehose, stream_name, arn, bucket_arn):\n+    \"\"\"Setup a stream(if required) to export cloudwatch logs to s3\"\"\"\n+    response = firehose.create_delivery_stream(\n+        DeliveryStreamName=stream_name,\n+        S3DestinationConfiguration={\n+            'RoleARN': arn,\n+            'BucketARN': bucket_arn,\n+            'Prefix': '',\n+            'BufferingHints': {\n+                'SizeInMBs': 5,\n+                'IntervalInSeconds': 300\n+            },\n+            'CompressionFormat': 'UNCOMPRESSED',\n+            'EncryptionConfiguration': {\n+                'NoEncryptionConfig': 'NoEncryption',\n+            },\n+            'CloudWatchLoggingOptions': {\n+                'Enabled': False,\n+            }\n+        })\n+\n+    logging.info('response for creating firehose stream = \"%s\"',\n+                 response)\n+\n+\n+def create_lambda_function_zip(splunk_host, splunk_token):\n+    \"\"\"Updates and Zips the lambda function file\"\"\"\n+\n+    with open('index.js', \"wt\") as lambda_function_file:\n+        with open('index.js.template', 'rt') as lambda_function_template:\n+            for line in lambda_function_template:\n+                lambda_function_file.write(line.replace('<splunk host:port>',\n+                                                        splunk_host).replace('<token>',\n+                                                                             splunk_token))\n+    zip_file = 'lambda.zip'\n+\n+    with ZipFile(zip_file, 'w') as lambda_zip:\n+        lambda_zip.write('index.js')\n+\n+    return zip_file\n+\n+\n+def role_exists(iam, role_name):\n+    \"\"\"Checks if the role exists already\"\"\"\n+    try:\n+        iam.get_role(RoleName=role_name)\n+    except botocore.exceptions.ClientError:","path":"scripts/aws/monitor.py","position":90,"original_position":90,"commit_id":"3ade8bde4d47b0151cb9035ac3e7a4aa46efe06f","original_commit_id":"3ade8bde4d47b0151cb9035ac3e7a4aa46efe06f","user":{"login":"e0d","id":1270274,"avatar_url":"https://avatars.githubusercontent.com/u/1270274?v=3","gravatar_id":"","url":"https://api.github.com/users/e0d","html_url":"https://github.com/e0d","followers_url":"https://api.github.com/users/e0d/followers","following_url":"https://api.github.com/users/e0d/following{/other_user}","gists_url":"https://api.github.com/users/e0d/gists{/gist_id}","starred_url":"https://api.github.com/users/e0d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e0d/subscriptions","organizations_url":"https://api.github.com/users/e0d/orgs","repos_url":"https://api.github.com/users/e0d/repos","events_url":"https://api.github.com/users/e0d/events{/privacy}","received_events_url":"https://api.github.com/users/e0d/received_events","type":"User","site_admin":false},"body":"Is there a more specific exception that could be checked here?","created_at":"2016-06-08T12:40:37Z","updated_at":"2016-06-08T12:40:37Z","html_url":"https://github.com/edx/api-manager/pull/22#discussion_r66247029","pull_request_url":"https://api.github.com/repos/edx/api-manager/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/edx/api-manager/pulls/comments/66247029"},"html":{"href":"https://github.com/edx/api-manager/pull/22#discussion_r66247029"},"pull_request":{"href":"https://api.github.com/repos/edx/api-manager/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/edx/api-manager/pulls/22","id":72896526,"html_url":"https://github.com/edx/api-manager/pull/22","diff_url":"https://github.com/edx/api-manager/pull/22.diff","patch_url":"https://github.com/edx/api-manager/pull/22.patch","issue_url":"https://api.github.com/repos/edx/api-manager/issues/22","number":22,"state":"open","locked":false,"title":"API Gateway monitoring [OPS-1575]","user":{"login":"bilalahmad99","id":7087225,"avatar_url":"https://avatars.githubusercontent.com/u/7087225?v=3","gravatar_id":"","url":"https://api.github.com/users/bilalahmad99","html_url":"https://github.com/bilalahmad99","followers_url":"https://api.github.com/users/bilalahmad99/followers","following_url":"https://api.github.com/users/bilalahmad99/following{/other_user}","gists_url":"https://api.github.com/users/bilalahmad99/gists{/gist_id}","starred_url":"https://api.github.com/users/bilalahmad99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilalahmad99/subscriptions","organizations_url":"https://api.github.com/users/bilalahmad99/orgs","repos_url":"https://api.github.com/users/bilalahmad99/repos","events_url":"https://api.github.com/users/bilalahmad99/events{/privacy}","received_events_url":"https://api.github.com/users/bilalahmad99/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-07T15:27:34Z","updated_at":"2016-06-08T12:40:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5021be27743be00dcb772513b42fb26301a2b72b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/api-manager/pulls/22/commits","review_comments_url":"https://api.github.com/repos/edx/api-manager/pulls/22/comments","review_comment_url":"https://api.github.com/repos/edx/api-manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/api-manager/issues/22/comments","statuses_url":"https://api.github.com/repos/edx/api-manager/statuses/3ade8bde4d47b0151cb9035ac3e7a4aa46efe06f","head":{"label":"edx:bilalahmad99/api-monitoring","ref":"bilalahmad99/api-monitoring","sha":"3ade8bde4d47b0151cb9035ac3e7a4aa46efe06f","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":55979621,"name":"api-manager","full_name":"edx/api-manager","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/api-manager","description":"A set of configuration files, documentation, and sample code for the edX API Manager.","fork":false,"url":"https://api.github.com/repos/edx/api-manager","forks_url":"https://api.github.com/repos/edx/api-manager/forks","keys_url":"https://api.github.com/repos/edx/api-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/api-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/api-manager/teams","hooks_url":"https://api.github.com/repos/edx/api-manager/hooks","issue_events_url":"https://api.github.com/repos/edx/api-manager/issues/events{/number}","events_url":"https://api.github.com/repos/edx/api-manager/events","assignees_url":"https://api.github.com/repos/edx/api-manager/assignees{/user}","branches_url":"https://api.github.com/repos/edx/api-manager/branches{/branch}","tags_url":"https://api.github.com/repos/edx/api-manager/tags","blobs_url":"https://api.github.com/repos/edx/api-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/api-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/api-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/api-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/api-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/api-manager/languages","stargazers_url":"https://api.github.com/repos/edx/api-manager/stargazers","contributors_url":"https://api.github.com/repos/edx/api-manager/contributors","subscribers_url":"https://api.github.com/repos/edx/api-manager/subscribers","subscription_url":"https://api.github.com/repos/edx/api-manager/subscription","commits_url":"https://api.github.com/repos/edx/api-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/api-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/api-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/api-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/api-manager/contents/{+path}","compare_url":"https://api.github.com/repos/edx/api-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/api-manager/merges","archive_url":"https://api.github.com/repos/edx/api-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/api-manager/downloads","issues_url":"https://api.github.com/repos/edx/api-manager/issues{/number}","pulls_url":"https://api.github.com/repos/edx/api-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/api-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/api-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/api-manager/labels{/name}","releases_url":"https://api.github.com/repos/edx/api-manager/releases{/id}","deployments_url":"https://api.github.com/repos/edx/api-manager/deployments","created_at":"2016-04-11T14:31:36Z","updated_at":"2016-05-04T23:55:57Z","pushed_at":"2016-06-08T09:30:48Z","git_url":"git://github.com/edx/api-manager.git","ssh_url":"git@github.com:edx/api-manager.git","clone_url":"https://github.com/edx/api-manager.git","svn_url":"https://github.com/edx/api-manager","homepage":null,"size":67,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"e99d95c0815b3c87ff2a2eacd06c9a8247af6d7b","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":55979621,"name":"api-manager","full_name":"edx/api-manager","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/api-manager","description":"A set of configuration files, documentation, and sample code for the edX API Manager.","fork":false,"url":"https://api.github.com/repos/edx/api-manager","forks_url":"https://api.github.com/repos/edx/api-manager/forks","keys_url":"https://api.github.com/repos/edx/api-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/api-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/api-manager/teams","hooks_url":"https://api.github.com/repos/edx/api-manager/hooks","issue_events_url":"https://api.github.com/repos/edx/api-manager/issues/events{/number}","events_url":"https://api.github.com/repos/edx/api-manager/events","assignees_url":"https://api.github.com/repos/edx/api-manager/assignees{/user}","branches_url":"https://api.github.com/repos/edx/api-manager/branches{/branch}","tags_url":"https://api.github.com/repos/edx/api-manager/tags","blobs_url":"https://api.github.com/repos/edx/api-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/api-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/api-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/api-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/api-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/api-manager/languages","stargazers_url":"https://api.github.com/repos/edx/api-manager/stargazers","contributors_url":"https://api.github.com/repos/edx/api-manager/contributors","subscribers_url":"https://api.github.com/repos/edx/api-manager/subscribers","subscription_url":"https://api.github.com/repos/edx/api-manager/subscription","commits_url":"https://api.github.com/repos/edx/api-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/api-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/api-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/api-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/api-manager/contents/{+path}","compare_url":"https://api.github.com/repos/edx/api-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/api-manager/merges","archive_url":"https://api.github.com/repos/edx/api-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/api-manager/downloads","issues_url":"https://api.github.com/repos/edx/api-manager/issues{/number}","pulls_url":"https://api.github.com/repos/edx/api-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/api-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/api-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/api-manager/labels{/name}","releases_url":"https://api.github.com/repos/edx/api-manager/releases{/id}","deployments_url":"https://api.github.com/repos/edx/api-manager/deployments","created_at":"2016-04-11T14:31:36Z","updated_at":"2016-05-04T23:55:57Z","pushed_at":"2016-06-08T09:30:48Z","git_url":"git://github.com/edx/api-manager.git","ssh_url":"git@github.com:edx/api-manager.git","clone_url":"https://github.com/edx/api-manager.git","svn_url":"https://github.com/edx/api-manager","homepage":null,"size":67,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/api-manager/pulls/22"},"html":{"href":"https://github.com/edx/api-manager/pull/22"},"issue":{"href":"https://api.github.com/repos/edx/api-manager/issues/22"},"comments":{"href":"https://api.github.com/repos/edx/api-manager/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/api-manager/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/api-manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/api-manager/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/edx/api-manager/statuses/3ade8bde4d47b0151cb9035ac3e7a4aa46efe06f"}}}}
{"actor":{"display_login":"e0d"}}