2017-06-15 22:56:47 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
# Copyright (c) 2014 Mozilla Corporation
|
|
|
|
#
|
|
|
|
# Contributors:
|
|
|
|
# Jeff Bryner jbryner@mozilla.com
|
|
|
|
#
|
|
|
|
# a collection of alerts looking for the lack of events
|
|
|
|
# to alert on a dead input source.
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2016-08-19 23:40:51 +03:00
|
|
|
from query_models import SearchQuery, TermMatch, PhraseMatch
|
|
|
|
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
class broNSM(AlertTask):
|
|
|
|
def main(self, *args, **kwargs):
|
|
|
|
# call with hostlist=['host1','host2','host3']
|
|
|
|
# to search for missing events
|
|
|
|
if kwargs and 'hostlist' in kwargs.keys():
|
|
|
|
for host in kwargs['hostlist']:
|
|
|
|
self.log.debug('checking deadman for host: {0}'.format(host))
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=20)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2016-08-19 23:40:51 +03:00
|
|
|
PhraseMatch("details.note", "MozillaAlive::Bro_Is_Watching_You"),
|
|
|
|
PhraseMatch("details.peer_descr", host),
|
2016-08-19 22:50:16 +03:00
|
|
|
TermMatch('category', 'bronotice'),
|
|
|
|
TermMatch('_type', 'bro')
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
# Search events
|
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents(hostname=host)
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
# if no events found
|
|
|
|
def onNoEvent(self, hostname):
|
|
|
|
category = 'deadman'
|
|
|
|
tags = ['bro']
|
|
|
|
severity = 'ERROR'
|
|
|
|
|
2017-03-25 00:42:51 +03:00
|
|
|
summary = ('No {0} bro healthcheck events found the past 20 minutes'.format(hostname))
|
2017-06-15 22:56:47 +03:00
|
|
|
url = "https://mana.mozilla.org/wiki/display/SECURITY/NSM+IR+procedures"
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2017-06-15 22:56:47 +03:00
|
|
|
# Create the alert object based on these properties
|
2017-03-27 23:22:47 +03:00
|
|
|
return self.createAlertDict(summary, category, tags, [], severity=severity, url=url)
|