Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description field added to elastalaert events #1339

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions elastalert/create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import elasticsearch.helpers
import yaml
from auth import Auth
from envparse import Env
from elasticsearch import RequestsHttpConnection
from elasticsearch.client import Elasticsearch
from elasticsearch.client import IndicesClient
from envparse import Env


env = Env(ES_USE_SSL=bool)
Expand Down Expand Up @@ -119,21 +119,26 @@ def main():

silence_mapping = {'silence': {'properties': {'rule_name': {'index': 'not_analyzed', 'type': 'string'},
'until': {'type': 'date', 'format': 'dateOptionalTime'},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'}}}}
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'},
'description': {'index': 'not_analyzed', 'type': 'string'}}}}
ess_mapping = {'elastalert_status': {'properties': {'rule_name': {'index': 'not_analyzed', 'type': 'string'},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'}}}}
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'},
'description': {'index': 'not_analyzed', 'type': 'string'}}}}
es_mapping = {'elastalert': {'properties': {'rule_name': {'index': 'not_analyzed', 'type': 'string'},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'},
'alert_time': {'format': 'dateOptionalTime', 'type': 'date'},
'match_time': {'format': 'dateOptionalTime', 'type': 'date'},
'match_body': {'enabled': False, 'type': 'object'},
'aggregate_id': {'index': 'not_analyzed', 'type': 'string'}}}}
'aggregate_id': {'index': 'not_analyzed', 'type': 'string'},
'description': {'index': 'not_analyzed', 'type': 'string'}}}}
past_mapping = {'past_elastalert': {'properties': {'rule_name': {'index': 'not_analyzed', 'type': 'string'},
'match_body': {'enabled': False, 'type': 'object'},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'},
'aggregate_id': {'index': 'not_analyzed', 'type': 'string'}}}}
'aggregate_id': {'index': 'not_analyzed', 'type': 'string'},
'description': {'index': 'not_analyzed', 'type': 'string'}}}}
error_mapping = {'elastalert_error': {'properties': {'data': {'type': 'object', 'enabled': False},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'}}}}
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'},
'description': {'index': 'not_analyzed', 'type': 'string'}}}}

index = args.index if args.index is not None else raw_input('New index name? (Default elastalert_status) ')
if not index:
Expand Down
13 changes: 8 additions & 5 deletions elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def run_rule(self, rule, endtime, starttime=None):

if rule['realert']:
next_alert, exponent = self.next_alert_time(rule, silence_cache_key, ts_now())
self.set_realert(silence_cache_key, next_alert, exponent)
self.set_realert(silence_cache_key, next_alert, exponent, rule.get('description', ''))

if rule.get('run_enhancements_first'):
try:
Expand Down Expand Up @@ -848,7 +848,8 @@ def run_rule(self, rule, endtime, starttime=None):
'matches': num_matches,
'hits': self.num_hits,
'@timestamp': ts_now(),
'time_taken': time_taken}
'time_taken': time_taken,
'description': rule.get('description', '')}
self.writeback('elastalert_status', body)

return num_matches
Expand Down Expand Up @@ -1347,7 +1348,8 @@ def get_alert_body(self, match, rule, alert_sent, alert_time, alert_exception=No
'rule_name': rule['name'],
'alert_info': rule['alert'][0].get_info(),
'alert_sent': alert_sent,
'alert_time': alert_time
'alert_time': alert_time,
'description': rule.get('description', '')
}

match_time = lookup_es_key(match, rule['timestamp_field'])
Expand Down Expand Up @@ -1632,12 +1634,13 @@ def silence(self, silence_cache_key=None):

elastalert_logger.info('Success. %s will be silenced until %s' % (silence_cache_key, silence_ts))

def set_realert(self, silence_cache_key, timestamp, exponent):
def set_realert(self, silence_cache_key, timestamp, exponent, description=''):
""" Write a silence to Elasticsearch for silence_cache_key until timestamp. """
body = {'exponent': exponent,
'rule_name': silence_cache_key,
'@timestamp': ts_now(),
'until': timestamp}
'until': timestamp,
'description': description}

self.silence_cache[silence_cache_key] = (timestamp, exponent)
return self.writeback('silence', body)
Expand Down