MozDef/alerts/geomodel.py

66 строки
2.2 KiB
Python
Исходник Обычный вид История

#!/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
from lib.alerttask import AlertTask
2018-10-17 01:33:58 +03:00
from mozdef_util.query_models import SearchQuery, TermMatch
class AlertGeomodel(AlertTask):
# The minimum event severity we will create an alert for
MINSEVERITY = 2
def main(self):
2017-12-06 00:41:43 +03:00
self.parse_config('geomodel.conf', ['exclusions', 'url'])
search_query = SearchQuery(minutes=30)
search_query.add_must([
TermMatch('category', 'geomodelnotice')
])
# Allow the ability to ignore certain users
for exclusion in self.config.exclusions.split(','):
search_query.add_must_not(TermMatch('summary', exclusion))
self.filtersManual(search_query)
self.searchEventsSimple()
self.walkEvents()
# Set alert properties
def onEvent(self, event):
category = 'geomodel'
tags = ['geomodel']
severity = 'NOTICE'
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
# By default we assign a MozDef severity of NOTICE, but up this if the
# geomodel alert is sev 3
if ev['details']['severity'] == 3:
severity = 'WARNING'
summary = ev['summary']
2017-12-06 00:41:43 +03:00
alert_dict = self.createAlertDict(summary, category, tags, [event], severity, self.config.url)
2017-10-05 20:12:26 +03:00
if 'category' in ev['details'] and ev['details']['category'].lower() == 'newcountry':
alert_dict['details'] = {
'previous_locality_details': ev['details']['prev_locality_details'],
'locality_details': ev['details']['locality_details'],
'category': ev['details']['category'],
'principal': ev['details']['principal'],
'source_ip': ev['details']['source_ipv4']
}
2017-10-05 20:12:26 +03:00
return alert_dict