<commit_before># (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP

import logging
import os
import re

from datetime import datetime

import monasca_agent.collector.checks as checks

log = logging.getLogger(__name__)


class Crash(checks.AgentCheck):

    def __init__(self, name, init_config, agent_config):
        super(Crash, self).__init__(name, init_config, agent_config)
        self.crash_dir = self.init_config.get('crash_dir', '/var/crash')
        log.debug('crash dir: %s', self.crash_dir)

    def _create_datetime_for_rhel71(self, dir_name):
        date_parts = dir_name.split('-')
        parts_len = len(date_parts)
        if parts_len > 2:
            try:
                # Use last two parts, because the front part(IP address part) is not checked.
                date_part = date_parts[parts_len - 2] + '-' + date_parts[parts_len - 1]
                return datetime.strptime(date_part, '%Y.%m.%d-%H:%M:%S')
            except ValueError:
                pass

    def _check_dir_name(self, dir_name):
        dt = None
        if dir_name is None:
            return None
        # Check for CentOS 7.1 and RHEL 7.1. <IP-address>-YYYY.MM.dd-HH:mm:ss (e.g. 127.0.0.1-2015.10.02-16:07:51)
        elif re.match(r".*-\d{4}[.]\d{2}[.]\d{2}-\d{2}:\d{2}:\d{2}$", dir_name):
            dt = self._create_datetime_for_rhel71(dir_name)
        else:
            try:
                dt = datetime.strptime(dir_name, '%Y%m%d%H%M')
            except ValueError:
                pass
        return dt

    def check(self, instance):
        """Capture crash dump statistics
        """
        dimensions = self._set_dimensions(None, instance)
        dump_count = 0
        value_meta = {'latest': None}

        # Parse the crash directory<commit_msg>fix crash.py plugin, because of invalid value<commit_after># (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP

import logging
import os
import re

from datetime import datetime

import monasca_agent.collector.checks as checks

log = logging.getLogger(__name__)


class Crash(checks.AgentCheck):

    def __init__(self, name, init_config, agent_config):
        super(Crash, self).__init__(name, init_config, agent_config)
        self.crash_dir = self.init_config.get('crash_dir', '/var/crash')
        log.debug('crash dir: %s', self.crash_dir)

    def _create_datetime_for_rhel71(self, dir_name):
        date_parts = dir_name.split('-')
        parts_len = len(date_parts)
        if parts_len > 2:
            try:
                # Use last two parts, because the front part(IP address part) is not checked.
                date_part = date_parts[parts_len - 2] + '-' + date_parts[parts_len - 1]
                return datetime.strptime(date_part, '%Y.%m.%d-%H:%M:%S')
            except ValueError:
                pass

    def _check_dir_name(self, dir_name):
        dt = None
        if dir_name is None:
            return None
        # Check for CentOS 7.1 and RHEL 7.1. <IP-address>-YYYY.MM.dd-HH:mm:ss (e.g. 127.0.0.1-2015.10.02-16:07:51)
        elif re.match(r".*-\d{4}[.]\d{2}[.]\d{2}-\d{2}:\d{2}:\d{2}$", dir_name):
            dt = self._create_datetime_for_rhel71(dir_name)
        else:
            try:
                dt = datetime.strptime(dir_name, '%Y%m%d%H%M')
            except ValueError:
                pass
        return dt

    def check(self, instance):
        """Capture crash dump statistics
        """
        dimensions = self._set_dimensions(None, instance)
        dump_count = 0
        value_meta = None

        # Parse the crash directory
{'fraction_non_alphanumeric': 0.1192992213570634, 'fraction_numerical': 0.02335928809788654, 'mean_word_length': 2.2670299727520438, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3941702', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1151, 'n_words': 272}