2015-11-24 18:43:33 +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) 2015 Mozilla Corporation
|
|
|
|
#
|
|
|
|
# Contributors:
|
|
|
|
# Aaron Meihm <ameihm@mozilla.com>
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2016-08-19 22:50:16 +03:00
|
|
|
from query_models import SearchQuery, TermMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2015-11-24 18:43:33 +03:00
|
|
|
|
|
|
|
class AlertGeomodel(AlertTask):
|
2016-06-22 22:09:58 +03:00
|
|
|
# The minimum event severity we will create an alert for
|
|
|
|
MINSEVERITY = 2
|
|
|
|
|
2015-11-24 18:43:33 +03:00
|
|
|
def main(self):
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=30)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2016-08-19 22:50:16 +03:00
|
|
|
TermMatch('_type', 'event'),
|
|
|
|
TermMatch('category', 'geomodelnotice'),
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
2015-11-24 18:43:33 +03:00
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
self.filtersManual(search_query)
|
2015-11-24 18:43:33 +03:00
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents()
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
def onEvent(self, event):
|
|
|
|
category = 'geomodel'
|
|
|
|
tags = ['geomodel']
|
2016-06-22 22:09:58 +03:00
|
|
|
severity = 'WARNING'
|
|
|
|
|
|
|
|
ev = event['_source']
|
|
|
|
|
|
|
|
# If the event severity is below what we want, just ignore
|
|
|
|
# the event.
|
|
|
|
if 'details' not in ev or 'severity' not in ev['details']:
|
|
|
|
return None
|
|
|
|
if ev['details']['severity'] < self.MINSEVERITY:
|
|
|
|
return None
|
2015-11-24 18:43:33 +03:00
|
|
|
|
2016-06-22 22:09:58 +03:00
|
|
|
summary = ev['summary']
|
2015-11-24 18:43:33 +03:00
|
|
|
return self.createAlertDict(summary, category, tags, [event], severity)
|