2017-05-13 00:01:35 +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
|
2019-08-02 02:41:37 +03:00
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2017-05-13 00:01:35 +03:00
|
|
|
# Copyright (c) 2017 Mozilla Corporation
|
|
|
|
|
2019-02-05 00:04:04 +03:00
|
|
|
from lib.deadman_alerttask import DeadmanAlertTask
|
2018-10-17 01:33:58 +03:00
|
|
|
from mozdef_util.query_models import SearchQuery, TermMatch
|
2017-05-13 00:01:35 +03:00
|
|
|
|
|
|
|
|
2019-02-05 00:04:04 +03:00
|
|
|
class AlertSQSQueuesDeadman(DeadmanAlertTask):
|
2017-05-13 00:01:35 +03:00
|
|
|
|
|
|
|
def main(self):
|
2017-05-27 00:05:15 +03:00
|
|
|
self.parse_config('sqs_queues_deadman.conf', ['sqs_queues'])
|
|
|
|
for queue_name in self.config.sqs_queues.split(','):
|
2017-05-13 00:01:35 +03:00
|
|
|
self.sqs_queue_name = queue_name
|
|
|
|
self.process_alert()
|
|
|
|
|
|
|
|
def process_alert(self):
|
|
|
|
search_query = SearchQuery(hours=1)
|
|
|
|
search_query.add_must(TermMatch('tags', self.sqs_queue_name))
|
|
|
|
self.filtersManual(search_query)
|
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents()
|
|
|
|
|
|
|
|
def onNoEvent(self):
|
|
|
|
category = 'deadman'
|
|
|
|
tags = [self.sqs_queue_name, 'sqs']
|
|
|
|
severity = 'ERROR'
|
|
|
|
|
|
|
|
summary = 'No events found from {} sqs queue the last hour'.format(self.sqs_queue_name)
|
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
|
|
|
return self.createAlertDict(summary, category, tags, [], severity=severity)
|