<commit_before>#!/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


from lib.deadman_alerttask import DeadmanAlertTask
from mozdef_util.query_models import SearchQuery, QueryStringMatch
from mozdef_util.utilities.logger import logger


class AlertDeadmanGeneric(DeadmanAlertTask):

    def main(self):
        self._config = self.parse_json_alert_config('deadman_generic.json')
        for alert_cfg in self._config['alerts']:
            try:
                self.process_alert(alert_cfg)
            except Exception as e:
                logger.exception("Exception received when processing deadman alert ({0}):\n{1}".format(
                    e,
                    alert_cfg.__str__())
                )

    def process_alert(self, alert_config):
        self.current_alert_time_window = int(alert_config['time_window'])<commit_msg>Override event indices in generic deadman alert<commit_after>#!/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


from lib.deadman_alerttask import DeadmanAlertTask
from mozdef_util.query_models import SearchQuery, QueryStringMatch
from mozdef_util.utilities.logger import logger


class AlertDeadmanGeneric(DeadmanAlertTask):

    def main(self):
        # We override the event indices to search for
        # because our deadman alerts might look past 48 hours
        self.event_indices = ["events-*"]

        self._config = self.parse_json_alert_config('deadman_generic.json')
        for alert_cfg in self._config['alerts']:
            try:
                self.process_alert(alert_cfg)
            except Exception as e:
                logger.exception("Exception received when processing deadman alert ({0}):\n{1}".format(
                    e,
                    alert_cfg.__str__())
                )

    def process_alert(self, alert_config):
        self.current_alert_time_window = int(alert_config['time_window'])
{'fraction_non_alphanumeric': 0.0827165868524162, 'fraction_numerical': 0.00957771005659556, 'mean_word_length': 2.8686868686868685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2727132', 'n_tokens_mistral': 667, 'n_tokens_neox': 619, 'n_words': 192}