{"action":"created","comment":{"url":"https://api.github.com/repos/Yelp/elastalert/pulls/comments/30378129","id":30378129,"diff_hunk":"@@ -466,3 +469,72 @@ def garbage_collect(self, ts):\n         for key in self.occurrences.keys():\n             self.occurrences.setdefault(key, EventWindow(self.rules['timeframe'], getTimestamp=self.get_ts)).append(({self.ts_field: ts}, 0))\n             self.check_for_match(key)\n+\n+\n+class NewTermsRule(RuleType):\n+    \"\"\" Alerts on a new value in a list of fields. \"\"\"\n+\n+    def __init__(self, *args):\n+        super(NewTermsRule, self).__init__(*args)\n+        self.seen_values = {}\n+        # Allow the use of query_key or fields\n+        if 'fields' not in self.rules:\n+            if 'query_key' not in self.rules:\n+                raise EAException(\"fields or query_key must be specified\")\n+            self.fields = self.rules['query_key']\n+        else:\n+            self.fields = self.rules['fields']\n+        if type(self.fields) != list:\n+            self.fields = [self.fields]\n+        if self.rules.get('use_terms_query') and len(self.fields) != 1:\n+            raise EAException(\"use_terms_query can only be used with one field at a time\")\n+        self.get_all_terms()\n+\n+    def get_all_terms(self):\n+        \"\"\" Performs a terms aggregation for each field to get every existing term. \"\"\"\n+        self.es = Elasticsearch(host=self.rules['es_host'], port=self.rules['es_port'])\n+        window_size = datetime.timedelta(**self.rules.get('terms_window_size', {'days': 30}))\n+\n+        field_name = {\"field\": \"\", \"size\": 999999}","path":"elastalert/ruletypes.py","position":45,"original_position":45,"commit_id":"1561d28b58e8661b01e4dbcdf00bd03c2c5c1421","original_commit_id":"1561d28b58e8661b01e4dbcdf00bd03c2c5c1421","user":{"login":"y-trobinso","id":2644744,"avatar_url":"https://avatars.githubusercontent.com/u/2644744?v=3","gravatar_id":"","url":"https://api.github.com/users/y-trobinso","html_url":"https://github.com/y-trobinso","followers_url":"https://api.github.com/users/y-trobinso/followers","following_url":"https://api.github.com/users/y-trobinso/following{/other_user}","gists_url":"https://api.github.com/users/y-trobinso/gists{/gist_id}","starred_url":"https://api.github.com/users/y-trobinso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/y-trobinso/subscriptions","organizations_url":"https://api.github.com/users/y-trobinso/orgs","repos_url":"https://api.github.com/users/y-trobinso/repos","events_url":"https://api.github.com/users/y-trobinso/events{/privacy}","received_events_url":"https://api.github.com/users/y-trobinso/received_events","type":"User","site_admin":false},"body":"I think we should actually use python's version of maxint here, instead of an arbitrary number we might surpass.","created_at":"2015-05-15T00:55:38Z","updated_at":"2015-05-15T00:55:38Z","html_url":"https://github.com/Yelp/elastalert/pull/90#discussion_r30378129","pull_request_url":"https://api.github.com/repos/Yelp/elastalert/pulls/90","_links":{"self":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/comments/30378129"},"html":{"href":"https://github.com/Yelp/elastalert/pull/90#discussion_r30378129"},"pull_request":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/Yelp/elastalert/pulls/90","id":35476559,"html_url":"https://github.com/Yelp/elastalert/pull/90","diff_url":"https://github.com/Yelp/elastalert/pull/90.diff","patch_url":"https://github.com/Yelp/elastalert/pull/90.patch","issue_url":"https://api.github.com/repos/Yelp/elastalert/issues/90","number":90,"state":"open","locked":false,"title":"Add new term rule","user":{"login":"Qmando","id":3246990,"avatar_url":"https://avatars.githubusercontent.com/u/3246990?v=3","gravatar_id":"","url":"https://api.github.com/users/Qmando","html_url":"https://github.com/Qmando","followers_url":"https://api.github.com/users/Qmando/followers","following_url":"https://api.github.com/users/Qmando/following{/other_user}","gists_url":"https://api.github.com/users/Qmando/gists{/gist_id}","starred_url":"https://api.github.com/users/Qmando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qmando/subscriptions","organizations_url":"https://api.github.com/users/Qmando/orgs","repos_url":"https://api.github.com/users/Qmando/repos","events_url":"https://api.github.com/users/Qmando/events{/privacy}","received_events_url":"https://api.github.com/users/Qmando/received_events","type":"User","site_admin":false},"body":"A new rule type which will search for a list of existing terms when it starts, and then alert on new values. It can take a number of different fields, and can use_terms_query.","created_at":"2015-05-15T00:50:35Z","updated_at":"2015-05-15T00:55:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"338f7de00ecabfa5d1a165019338c94b94183bc5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Yelp/elastalert/pulls/90/commits","review_comments_url":"https://api.github.com/repos/Yelp/elastalert/pulls/90/comments","review_comment_url":"https://api.github.com/repos/Yelp/elastalert/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yelp/elastalert/issues/90/comments","statuses_url":"https://api.github.com/repos/Yelp/elastalert/statuses/1561d28b58e8661b01e4dbcdf00bd03c2c5c1421","head":{"label":"Yelp:add_new_key_alert","ref":"add_new_key_alert","sha":"1561d28b58e8661b01e4dbcdf00bd03c2c5c1421","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":27091760,"name":"elastalert","full_name":"Yelp/elastalert","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/elastalert","description":"Easy & Flexible Alerting With ElasticSearch","fork":false,"url":"https://api.github.com/repos/Yelp/elastalert","forks_url":"https://api.github.com/repos/Yelp/elastalert/forks","keys_url":"https://api.github.com/repos/Yelp/elastalert/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/elastalert/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/elastalert/teams","hooks_url":"https://api.github.com/repos/Yelp/elastalert/hooks","issue_events_url":"https://api.github.com/repos/Yelp/elastalert/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/elastalert/events","assignees_url":"https://api.github.com/repos/Yelp/elastalert/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/elastalert/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/elastalert/tags","blobs_url":"https://api.github.com/repos/Yelp/elastalert/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/elastalert/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/elastalert/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/elastalert/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/elastalert/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/elastalert/languages","stargazers_url":"https://api.github.com/repos/Yelp/elastalert/stargazers","contributors_url":"https://api.github.com/repos/Yelp/elastalert/contributors","subscribers_url":"https://api.github.com/repos/Yelp/elastalert/subscribers","subscription_url":"https://api.github.com/repos/Yelp/elastalert/subscription","commits_url":"https://api.github.com/repos/Yelp/elastalert/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/elastalert/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/elastalert/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/elastalert/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yelp/elastalert/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/elastalert/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/elastalert/merges","archive_url":"https://api.github.com/repos/Yelp/elastalert/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/elastalert/downloads","issues_url":"https://api.github.com/repos/Yelp/elastalert/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/elastalert/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/elastalert/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/elastalert/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/elastalert/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/elastalert/releases{/id}","created_at":"2014-11-24T19:39:19Z","updated_at":"2015-05-14T08:39:19Z","pushed_at":"2015-05-15T00:50:35Z","git_url":"git://github.com/Yelp/elastalert.git","ssh_url":"git@github.com:Yelp/elastalert.git","clone_url":"https://github.com/Yelp/elastalert.git","svn_url":"https://github.com/Yelp/elastalert","homepage":"https://elastalert.readthedocs.org","size":1491,"stargazers_count":103,"watchers_count":103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":34,"forks":16,"open_issues":34,"watchers":103,"default_branch":"master"}},"base":{"label":"Yelp:master","ref":"master","sha":"a92cd9dfeec77f44b1f3489a8480c19f13d88c99","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":27091760,"name":"elastalert","full_name":"Yelp/elastalert","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/elastalert","description":"Easy & Flexible Alerting With ElasticSearch","fork":false,"url":"https://api.github.com/repos/Yelp/elastalert","forks_url":"https://api.github.com/repos/Yelp/elastalert/forks","keys_url":"https://api.github.com/repos/Yelp/elastalert/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/elastalert/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/elastalert/teams","hooks_url":"https://api.github.com/repos/Yelp/elastalert/hooks","issue_events_url":"https://api.github.com/repos/Yelp/elastalert/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/elastalert/events","assignees_url":"https://api.github.com/repos/Yelp/elastalert/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/elastalert/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/elastalert/tags","blobs_url":"https://api.github.com/repos/Yelp/elastalert/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/elastalert/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/elastalert/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/elastalert/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/elastalert/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/elastalert/languages","stargazers_url":"https://api.github.com/repos/Yelp/elastalert/stargazers","contributors_url":"https://api.github.com/repos/Yelp/elastalert/contributors","subscribers_url":"https://api.github.com/repos/Yelp/elastalert/subscribers","subscription_url":"https://api.github.com/repos/Yelp/elastalert/subscription","commits_url":"https://api.github.com/repos/Yelp/elastalert/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/elastalert/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/elastalert/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/elastalert/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yelp/elastalert/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/elastalert/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/elastalert/merges","archive_url":"https://api.github.com/repos/Yelp/elastalert/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/elastalert/downloads","issues_url":"https://api.github.com/repos/Yelp/elastalert/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/elastalert/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/elastalert/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/elastalert/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/elastalert/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/elastalert/releases{/id}","created_at":"2014-11-24T19:39:19Z","updated_at":"2015-05-14T08:39:19Z","pushed_at":"2015-05-15T00:50:35Z","git_url":"git://github.com/Yelp/elastalert.git","ssh_url":"git@github.com:Yelp/elastalert.git","clone_url":"https://github.com/Yelp/elastalert.git","svn_url":"https://github.com/Yelp/elastalert","homepage":"https://elastalert.readthedocs.org","size":1491,"stargazers_count":103,"watchers_count":103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":34,"forks":16,"open_issues":34,"watchers":103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/90"},"html":{"href":"https://github.com/Yelp/elastalert/pull/90"},"issue":{"href":"https://api.github.com/repos/Yelp/elastalert/issues/90"},"comments":{"href":"https://api.github.com/repos/Yelp/elastalert/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yelp/elastalert/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/Yelp/elastalert/statuses/1561d28b58e8661b01e4dbcdf00bd03c2c5c1421"}}}}