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
|
|
|
|
import pyes
|
|
|
|
|
|
|
|
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):
|
|
|
|
date_timedelta = dict(minutes=30)
|
|
|
|
|
|
|
|
must = [
|
2015-11-24 21:02:08 +03:00
|
|
|
pyes.TermFilter('_type', 'event'),
|
2015-11-24 18:43:33 +03:00
|
|
|
pyes.TermFilter('category', 'geomodelnotice'),
|
|
|
|
]
|
|
|
|
self.filtersManual(date_timedelta, must=must, must_not=[])
|
|
|
|
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)
|