Allow alerttask to exclude mozdefbot from severity

This commit is contained in:
Brandon Myers 2017-06-21 18:31:16 -05:00
Родитель 43aebfd492
Коммит 95b4b28a08
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 8AA79AD83045BBC7
2 изменённых файлов: 21 добавлений и 9 удалений

Просмотреть файл

@ -196,6 +196,15 @@ class AlertTask(Task):
except Exception as e: except Exception as e:
self.log.error('Exception while pushing alert to ES: {0}'.format(e)) self.log.error('Exception while pushing alert to ES: {0}'.format(e))
def tagBotNotify(self, alert):
"""
Tag alert to be excluded based on severity
"""
alert['notify_mozdefbot'] = True
if alert['severity'] == 'NOTICE' or alert['severity'] == 'INFO':
alert['notify_mozdefbot'] = False
return alert
def saveAlertID(self, saved_alert): def saveAlertID(self, saved_alert):
""" """
Save alert to self so we can analyze it later Save alert to self so we can analyze it later
@ -285,6 +294,7 @@ class AlertTask(Task):
for i in self.events: for i in self.events:
alert = self.onEvent(i, **kwargs) alert = self.onEvent(i, **kwargs)
if alert: if alert:
alert = self.tagBotNotify(alert)
self.log.debug(alert) self.log.debug(alert)
alertResultES = self.alertToES(alert) alertResultES = self.alertToES(alert)
self.tagEventsAlert([i], alertResultES) self.tagEventsAlert([i], alertResultES)
@ -296,6 +306,7 @@ class AlertTask(Task):
if len(self.events) == 0: if len(self.events) == 0:
alert = self.onNoEvent(**kwargs) alert = self.onNoEvent(**kwargs)
if alert: if alert:
alert = self.tagBotNotify(alert)
self.log.debug(alert) self.log.debug(alert)
alertResultES = self.alertToES(alert) alertResultES = self.alertToES(alert)
self.alertToMessageQueue(alert) self.alertToMessageQueue(alert)
@ -312,8 +323,9 @@ class AlertTask(Task):
if aggregation['count'] >= threshold: if aggregation['count'] >= threshold:
aggregation['config']=config aggregation['config']=config
alert = self.onAggregation(aggregation) alert = self.onAggregation(aggregation)
self.log.debug(alert)
if alert: if alert:
alert = self.tagBotNotify(alert)
self.log.debug(alert)
alertResultES = self.alertToES(alert) alertResultES = self.alertToES(alert)
# even though we only sample events in the alert # even though we only sample events in the alert
# tag all events as alerted to avoid re-alerting # tag all events as alerted to avoid re-alerting

Просмотреть файл

@ -308,6 +308,12 @@ class alertConsumer(ConsumerMixin):
logger.exception( logger.exception(
"alertworker exception: unknown body type received %r" % body) "alertworker exception: unknown body type received %r" % body)
return return
if bodyDict['notify_mozdefbot'] is False:
# If the alert tells us to not notify, then don't post to IRC
message.ack()
return
# process valid message # process valid message
# see where we send this alert # see where we send this alert
ircchannel = options.alertircchannel ircchannel = options.alertircchannel
@ -327,14 +333,8 @@ class alertConsumer(ConsumerMixin):
if len(bodyDict['summary']) > 450: if len(bodyDict['summary']) > 450:
sys.stdout.write('alert is more than 450 bytes, truncating\n') sys.stdout.write('alert is more than 450 bytes, truncating\n')
bodyDict['summary'] = bodyDict['summary'][:450] + ' truncated...' bodyDict['summary'] = bodyDict['summary'][:450] + ' truncated...'
#if the alert has a 'severity', only publish the alert if the severity is not NOTICE or INFO self.ircBot.client.msg(ircchannel, formatAlert(bodyDict))
if 'severity' in bodyDict.keys():
if not ((bodyDict['severity'] == 'NOTICE') or (bodyDict['severity'] == 'INFO')):
self.ircBot.client.msg(ircchannel, formatAlert(bodyDict))
#if the alert does not have a severity for some reason, go ahead and publish it
else:
self.ircBot.client.msg(ircchannel, formatAlert(bodyDict))
message.ack() message.ack()
except ValueError as e: except ValueError as e: