Skip to content

Commit

Permalink
Merge pull request Yelp#754 from Yelp/dpopes_add_aggregate_counts_and…
Browse files Browse the repository at this point in the history
…_uniqueness_in_summary_table

Include a count aggregation in the summary table
  • Loading branch information
Qmando authored Oct 5, 2016
2 parents 2b843b8 + bea3d16 commit 57a3d35
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions elastalert/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,22 @@ def get_aggregation_summary_text(self, matches):
summary_table_fields = self.rule['summary_table_fields']
if not isinstance(summary_table_fields, list):
summary_table_fields = [summary_table_fields]
text += u"Aggregation resulted in the following data for summary_table_fields ==> {0}:\n\n".format(summary_table_fields)
# Include a count aggregation so that we can see at a glance how many of each aggregation_key were encountered
summary_table_fields_with_count = summary_table_fields + ['count']
text += "Aggregation resulted in the following data for summary_table_fields ==> {0}:\n\n".format(summary_table_fields_with_count)
text_table = Texttable()
text_table.header(summary_table_fields)
text_table.header(summary_table_fields_with_count)
match_aggregation = {}

# Maintain an aggregate count for each unique key encountered in the aggregation period
for match in matches:
text_table.add_row([unicode(lookup_es_key(match, key)) for key in summary_table_fields])
key_tuple = tuple([unicode(lookup_es_key(match, key)) for key in summary_table_fields])
if key_tuple not in match_aggregation:
match_aggregation[key_tuple] = 1
else:
match_aggregation[key_tuple] = match_aggregation[key_tuple] + 1
for keys, count in match_aggregation.iteritems():
text_table.add_row([key for key in keys] + [count])
text += text_table.draw() + '\n\n'

return unicode(text)
Expand Down

0 comments on commit 57a3d35

Please sign in to comment.