{"action":"created","comment":{"url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/comments/72242731","id":72242731,"diff_hunk":"@@ -0,0 +1,106 @@\n+#!/usr/bin/env python\n+# -*- coding: utf-8 -*-\n+\n+import logging\n+import requests\n+import sys\n+import urllib\n+import urlparse\n+import json\n+from collections import defaultdict\n+\n+from zmon_worker_monitor.zmon_worker.errors import HttpError, CheckError, ConfigurationError\n+from zmon_worker_monitor.zmon_worker.common.http import get_user_agent\n+from requests.adapters import HTTPAdapter\n+\n+from zmon_worker_monitor.adapters.ifunctionfactory_plugin import IFunctionFactoryPlugin, propartial\n+\n+import tokens\n+\n+# will use OAUTH2_ACCESS_TOKEN_URL environment variable by default\n+# will try to read application credentials from CREDENTIALS_DIR\n+tokens.configure()\n+tokens.manage('uid', ['uid'])\n+tokens.start()\n+\n+logger = logging.getLogger('zmon-worker.entity-wrapper')\n+\n+\n+class EntitiesWrapperFactory(IFunctionFactoryPlugin):\n+    def __init__(self):\n+        super(EntitiesWrapperFactory, self).__init__()\n+\n+\n+    def configure(self, conf):\n+        \"\"\"\n+        Called after plugin is loaded to pass the [configuration] section in their plugin info file\n+        :param conf: configuration dictionary\n+        \"\"\"\n+\n+        self.service_url = conf.get('entityservice.url', conf.get('dataservice.url', 'https://localhost:443'))\n+        self.oauth2 = conf.get('entityservice.oauth2', conf.get('dataservice.oauth2', False))\n+\n+        return\n+\n+\n+    def create(self, factory_ctx):\n+        \"\"\"\n+        Automatically called to create the check function's object\n+        :param factory_ctx: (dict) names available for Function instantiation\n+        :return: an object that implements a check function\n+        \"\"\"\n+\n+        return propartial(EntitiesWrapper, infrastructure_account=factory_ctx.get('entity', {}).get('infrastructure_account', None), service_url=self.service_url, oauth2=self.oauth2)\n+\n+\n+class EntitiesWrapper(object):\n+    def __init__(self, service_url, infrastructure_account, verify=True, oauth2=False, token=None):\n+\n+        if not service_url:\n+            raise ConfigurationError('EntitiesWrapper improperly configured. URL is missing!')\n+\n+        self.__service_url = service_url\n+        self.__session = requests.Session()\n+\n+        if oauth2:\n+            self.__session.headers.update({'Authorization': 'Bearer {}'.format(tokens.get('uid'))})\n+\n+\n+    def _request(self, q):\n+        try:\n+            response = self.__session.get(self.__service_url + \"/api/v1/entities\", params={\"query\": json.dumps(q)})\n+            if response.ok:\n+                return response.json()\n+            else:\n+                raise Exception(\n+                    'EntitiesWrapper query failed: {} with status {}:{}'.format(q, response.status_code, response.text))\n+        except requests.Timeout:\n+            raise HttpError('timeout', self.url), None, sys.exc_info()[2]\n+        except requests.ConnectionError:\n+            raise HttpError('connection failed', self.url), None, sys.exc_info()[2]\n+\n+\n+    def search_local(self, **kwargs):\n+        ia = infrastructure_account if infrastructure_account else self.infrastructure_account","path":"zmon_worker_monitor/builtins/plugins/entities_wrapper.py","position":84,"original_position":84,"commit_id":"6203d6efb67cf7262ae7e7418ede79527cc89d63","original_commit_id":"6203d6efb67cf7262ae7e7418ede79527cc89d63","user":{"login":"mohabusama","id":488406,"avatar_url":"https://avatars.githubusercontent.com/u/488406?v=3","gravatar_id":"","url":"https://api.github.com/users/mohabusama","html_url":"https://github.com/mohabusama","followers_url":"https://api.github.com/users/mohabusama/followers","following_url":"https://api.github.com/users/mohabusama/following{/other_user}","gists_url":"https://api.github.com/users/mohabusama/gists{/gist_id}","starred_url":"https://api.github.com/users/mohabusama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohabusama/subscriptions","organizations_url":"https://api.github.com/users/mohabusama/orgs","repos_url":"https://api.github.com/users/mohabusama/repos","events_url":"https://api.github.com/users/mohabusama/events{/privacy}","received_events_url":"https://api.github.com/users/mohabusama/received_events","type":"User","site_admin":false},"body":"`infrastructure_account` is undefined. `kwargs.get('infrastructure_account')` ?","created_at":"2016-07-26T12:55:09Z","updated_at":"2016-07-26T12:55:09Z","html_url":"https://github.com/zalando-zmon/zmon-worker/pull/108#discussion_r72242731","pull_request_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108","_links":{"self":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/comments/72242731"},"html":{"href":"https://github.com/zalando-zmon/zmon-worker/pull/108#discussion_r72242731"},"pull_request":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108"}}},"pull_request":{"url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108","id":77957768,"html_url":"https://github.com/zalando-zmon/zmon-worker/pull/108","diff_url":"https://github.com/zalando-zmon/zmon-worker/pull/108.diff","patch_url":"https://github.com/zalando-zmon/zmon-worker/pull/108.patch","issue_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/108","number":108,"state":"open","locked":false,"title":"Add entity wrapper","user":{"login":"Jan-M","id":1443395,"avatar_url":"https://avatars.githubusercontent.com/u/1443395?v=3","gravatar_id":"","url":"https://api.github.com/users/Jan-M","html_url":"https://github.com/Jan-M","followers_url":"https://api.github.com/users/Jan-M/followers","following_url":"https://api.github.com/users/Jan-M/following{/other_user}","gists_url":"https://api.github.com/users/Jan-M/gists{/gist_id}","starred_url":"https://api.github.com/users/Jan-M/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jan-M/subscriptions","organizations_url":"https://api.github.com/users/Jan-M/orgs","repos_url":"https://api.github.com/users/Jan-M/repos","events_url":"https://api.github.com/users/Jan-M/events{/privacy}","received_events_url":"https://api.github.com/users/Jan-M/received_events","type":"User","site_admin":false},"body":"Allows easy querying of entity service from zmon worker for more dynamic checks.","created_at":"2016-07-19T11:11:58Z","updated_at":"2016-07-26T12:55:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"809873140ee9c1be4e62982b6ce311ea023eb9a3","assignee":{"login":"mohabusama","id":488406,"avatar_url":"https://avatars.githubusercontent.com/u/488406?v=3","gravatar_id":"","url":"https://api.github.com/users/mohabusama","html_url":"https://github.com/mohabusama","followers_url":"https://api.github.com/users/mohabusama/followers","following_url":"https://api.github.com/users/mohabusama/following{/other_user}","gists_url":"https://api.github.com/users/mohabusama/gists{/gist_id}","starred_url":"https://api.github.com/users/mohabusama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohabusama/subscriptions","organizations_url":"https://api.github.com/users/mohabusama/orgs","repos_url":"https://api.github.com/users/mohabusama/repos","events_url":"https://api.github.com/users/mohabusama/events{/privacy}","received_events_url":"https://api.github.com/users/mohabusama/received_events","type":"User","site_admin":false},"assignees":[{"login":"mohabusama","id":488406,"avatar_url":"https://avatars.githubusercontent.com/u/488406?v=3","gravatar_id":"","url":"https://api.github.com/users/mohabusama","html_url":"https://github.com/mohabusama","followers_url":"https://api.github.com/users/mohabusama/followers","following_url":"https://api.github.com/users/mohabusama/following{/other_user}","gists_url":"https://api.github.com/users/mohabusama/gists{/gist_id}","starred_url":"https://api.github.com/users/mohabusama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohabusama/subscriptions","organizations_url":"https://api.github.com/users/mohabusama/orgs","repos_url":"https://api.github.com/users/mohabusama/repos","events_url":"https://api.github.com/users/mohabusama/events{/privacy}","received_events_url":"https://api.github.com/users/mohabusama/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108/commits","review_comments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108/comments","review_comment_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/108/comments","statuses_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/statuses/6203d6efb67cf7262ae7e7418ede79527cc89d63","head":{"label":"zalando-zmon:feature-entity-wrapper","ref":"feature-entity-wrapper","sha":"6203d6efb67cf7262ae7e7418ede79527cc89d63","user":{"login":"zalando-zmon","id":19532842,"avatar_url":"https://avatars.githubusercontent.com/u/19532842?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-zmon","html_url":"https://github.com/zalando-zmon","followers_url":"https://api.github.com/users/zalando-zmon/followers","following_url":"https://api.github.com/users/zalando-zmon/following{/other_user}","gists_url":"https://api.github.com/users/zalando-zmon/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-zmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-zmon/subscriptions","organizations_url":"https://api.github.com/users/zalando-zmon/orgs","repos_url":"https://api.github.com/users/zalando-zmon/repos","events_url":"https://api.github.com/users/zalando-zmon/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-zmon/received_events","type":"Organization","site_admin":false},"repo":{"id":28918578,"name":"zmon-worker","full_name":"zalando-zmon/zmon-worker","owner":{"login":"zalando-zmon","id":19532842,"avatar_url":"https://avatars.githubusercontent.com/u/19532842?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-zmon","html_url":"https://github.com/zalando-zmon","followers_url":"https://api.github.com/users/zalando-zmon/followers","following_url":"https://api.github.com/users/zalando-zmon/following{/other_user}","gists_url":"https://api.github.com/users/zalando-zmon/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-zmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-zmon/subscriptions","organizations_url":"https://api.github.com/users/zalando-zmon/orgs","repos_url":"https://api.github.com/users/zalando-zmon/repos","events_url":"https://api.github.com/users/zalando-zmon/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-zmon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando-zmon/zmon-worker","description":"ZMON Python Worker","fork":false,"url":"https://api.github.com/repos/zalando-zmon/zmon-worker","forks_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/forks","keys_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/teams","hooks_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/hooks","issue_events_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/events{/number}","events_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/events","assignees_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/assignees{/user}","branches_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/branches{/branch}","tags_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/tags","blobs_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/languages","stargazers_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/stargazers","contributors_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/contributors","subscribers_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/subscribers","subscription_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/subscription","commits_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/contents/{+path}","compare_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/merges","archive_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/downloads","issues_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues{/number}","pulls_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/labels{/name}","releases_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/releases{/id}","deployments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/deployments","created_at":"2015-01-07T14:47:02Z","updated_at":"2016-06-03T14:59:21Z","pushed_at":"2016-07-26T12:45:28Z","git_url":"git://github.com/zalando-zmon/zmon-worker.git","ssh_url":"git@github.com:zalando-zmon/zmon-worker.git","clone_url":"https://github.com/zalando-zmon/zmon-worker.git","svn_url":"https://github.com/zalando-zmon/zmon-worker","homepage":"https://zmon.io/","size":729,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":9,"forks":6,"open_issues":9,"watchers":9,"default_branch":"master"}},"base":{"label":"zalando-zmon:master","ref":"master","sha":"d3d40af038a15afe91f968e555c64176ae36c396","user":{"login":"zalando-zmon","id":19532842,"avatar_url":"https://avatars.githubusercontent.com/u/19532842?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-zmon","html_url":"https://github.com/zalando-zmon","followers_url":"https://api.github.com/users/zalando-zmon/followers","following_url":"https://api.github.com/users/zalando-zmon/following{/other_user}","gists_url":"https://api.github.com/users/zalando-zmon/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-zmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-zmon/subscriptions","organizations_url":"https://api.github.com/users/zalando-zmon/orgs","repos_url":"https://api.github.com/users/zalando-zmon/repos","events_url":"https://api.github.com/users/zalando-zmon/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-zmon/received_events","type":"Organization","site_admin":false},"repo":{"id":28918578,"name":"zmon-worker","full_name":"zalando-zmon/zmon-worker","owner":{"login":"zalando-zmon","id":19532842,"avatar_url":"https://avatars.githubusercontent.com/u/19532842?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-zmon","html_url":"https://github.com/zalando-zmon","followers_url":"https://api.github.com/users/zalando-zmon/followers","following_url":"https://api.github.com/users/zalando-zmon/following{/other_user}","gists_url":"https://api.github.com/users/zalando-zmon/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-zmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-zmon/subscriptions","organizations_url":"https://api.github.com/users/zalando-zmon/orgs","repos_url":"https://api.github.com/users/zalando-zmon/repos","events_url":"https://api.github.com/users/zalando-zmon/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-zmon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando-zmon/zmon-worker","description":"ZMON Python Worker","fork":false,"url":"https://api.github.com/repos/zalando-zmon/zmon-worker","forks_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/forks","keys_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/teams","hooks_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/hooks","issue_events_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/events{/number}","events_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/events","assignees_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/assignees{/user}","branches_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/branches{/branch}","tags_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/tags","blobs_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/languages","stargazers_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/stargazers","contributors_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/contributors","subscribers_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/subscribers","subscription_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/subscription","commits_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/contents/{+path}","compare_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/merges","archive_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/downloads","issues_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues{/number}","pulls_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/labels{/name}","releases_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/releases{/id}","deployments_url":"https://api.github.com/repos/zalando-zmon/zmon-worker/deployments","created_at":"2015-01-07T14:47:02Z","updated_at":"2016-06-03T14:59:21Z","pushed_at":"2016-07-26T12:45:28Z","git_url":"git://github.com/zalando-zmon/zmon-worker.git","ssh_url":"git@github.com:zalando-zmon/zmon-worker.git","clone_url":"https://github.com/zalando-zmon/zmon-worker.git","svn_url":"https://github.com/zalando-zmon/zmon-worker","homepage":"https://zmon.io/","size":729,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":9,"forks":6,"open_issues":9,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108"},"html":{"href":"https://github.com/zalando-zmon/zmon-worker/pull/108"},"issue":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/108"},"comments":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/issues/108/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/pulls/108/commits"},"statuses":{"href":"https://api.github.com/repos/zalando-zmon/zmon-worker/statuses/6203d6efb67cf7262ae7e7418ede79527cc89d63"}}}}
{"actor":{"display_login":"mohabusama"}}