def test5sign_type_mandatory_none_padding(self):
        """
        This testcase represents the equivalence class of all numbers with a mandatory sign in combination with no padding.
        It tests the correctness of the Path usage for all integers with a mandatory sign without padding.
        """
        match_context = MatchContext(self.negative_string)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'-25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), -25537,
                         self.match_element_unexpected_value)

        match_context = MatchContext(b'+25537 uid=2')
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'+25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), 25537,
                         self.match_element_unexpected_value)
Ejemplo n.º 2
0
    def test7positive_number_zero_padding(self):
        """In this testcase the positive Integer equivalence class in combination with the zero padding, which represents the padding
        equivalence class, is tested."""
        match_context = MatchContext(self.zero_number)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'00025537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), 25537,
                         self.match_element_unexpected_value)

        match_context = MatchContext(self.positive_string)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), 25537,
                         self.match_element_unexpected_value)
Ejemplo n.º 3
0
    def test5value_list_match_rule(self):
        """This case unit the ValueListMatchRule."""
        description = "Test5Rules"
        value_list_match_rule = ValueListMatchRule(
            'match/d1', [1, 2, 4, 8, 16, 32, 64, 128, 256, 512], None)
        self.analysis_context.register_component(value_list_match_rule,
                                                 description)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            'd1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)

        match_context = MatchContext(b'64')
        match_element = decimal_integer_value_me.get_match_element(
            'match', match_context)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           value_list_match_rule)
        self.assertTrue(value_list_match_rule.match(log_atom))

        match_context = MatchContext(b'4711')
        match_element = decimal_integer_value_me.get_match_element(
            'match', match_context)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           value_list_match_rule)
        self.assertTrue(not value_list_match_rule.match(log_atom))
    def test11mandatory_zero_padding(self):
        """In this testcase the mandatory sign equivalence class in combination with the zero padding is tested."""
        match_context = MatchContext(b'+00025537 uid=2')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY,
            DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'+00025537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), 25537,
                         self.match_element_unexpected_value)

        match_context = MatchContext(b'-00025537 uid=2')
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'-00025537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), -25537,
                         self.match_element_unexpected_value)

        match_context = MatchContext(b'+25537 uid=2')
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'+25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), 25537,
                         self.match_element_unexpected_value)
Ejemplo n.º 5
0
    def test9negative_number_blank_padding(self):
        """In this testcase the negative Integer equivalence class in combination with the blank character padding, which represents the
        padding equivalence class, is tested."""
        match_context = MatchContext(b'- 25537 uid=2')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
            DecimalIntegerValueModelElement.PAD_TYPE_BLANK)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'- 25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), -25537,
                         self.match_element_unexpected_value)

        match_context = MatchContext(self.negative_string)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertNotEqual(match_element, None,
                            self.match_element_should_exist)
        self.assertEqual(match_element.get_match_string(), b'-25537',
                         self.match_element_unexpected_result)
        self.assertEqual(match_element.get_match_object(), -25537,
                         self.match_element_unexpected_value)
Ejemplo n.º 6
0
    def test6value_range_match_rule(self):
        """This case unit the ValueRangeMatchRule."""
        description = "Test6Rules"
        value_range_match_rule = ValueRangeMatchRule('match/d1', 1, 1000, None)
        self.analysis_context.register_component(value_range_match_rule, description)
        decimal_integer_value_me = DecimalIntegerValueModelElement('d1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
                                                                   DecimalIntegerValueModelElement.PAD_TYPE_NONE)

        match_context = MatchContext(b'1')
        match_element = decimal_integer_value_me.get_match_element('match', match_context)
        log_atom = LogAtom(match_context.match_data, ParserMatch(match_element), 1, value_range_match_rule)
        self.assertTrue(value_range_match_rule.match(log_atom))

        match_context = MatchContext(b'1000')
        match_element = decimal_integer_value_me.get_match_element('match', match_context)
        log_atom = LogAtom(match_context.match_data, ParserMatch(match_element), 1, value_range_match_rule)
        self.assertTrue(value_range_match_rule.match(log_atom))

        match_context = MatchContext(b'0')
        match_element = decimal_integer_value_me.get_match_element('match', match_context)
        log_atom = LogAtom(match_context.match_data, ParserMatch(match_element), 1, value_range_match_rule)
        self.assertTrue(not value_range_match_rule.match(log_atom))

        match_context = MatchContext(b'1001')
        match_element = decimal_integer_value_me.get_match_element('match', match_context)
        log_atom = LogAtom(match_context.match_data, ParserMatch(match_element), 1, value_range_match_rule)
        self.assertTrue(not value_range_match_rule.match(log_atom))
Ejemplo n.º 7
0
    def test1event_generation_match_action(self):
        """This test case checks if events are generated and pushed to all event handlers."""
        description = "Test1Rules"
        output_stream2 = StringIO()
        message = 'This message was generated, when the unit were successful.'

        match_context = MatchContext(b'25537')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            'd1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element = decimal_integer_value_me.get_match_element(
            'match', match_context)
        stream_printer_event_handler2 = StreamPrinterEventHandler(
            self.analysis_context, output_stream2)

        t = time()
        event_generation_match_action = EventGenerationMatchAction(
            'Test.%s' % self.__class__.__name__, message,
            [self.stream_printer_event_handler, stream_printer_event_handler2])
        self.analysis_context.register_component(event_generation_match_action,
                                                 description)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), t,
                           event_generation_match_action)
        event_generation_match_action.match_action(log_atom)

        self.assertEqual(self.output_stream.getvalue(),
                         output_stream2.getvalue())
        self.assertEqual(
            self.output_stream.getvalue(), self.__expected_string %
            (datetime.fromtimestamp(t).strftime("%Y-%m-%d %H:%M:%S"),
             event_generation_match_action.__class__.__name__, description, 1,
             log_atom.parser_match.match_element.annotate_match('')))
    def test12mandatory_zero_padding_no_match(self):
        """In this testcase the mandatory sign equivalence class in combination with the zero padding is tested with no match expected."""
        match_context = MatchContext(self.zero_number)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY,
            DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertEqual(match_element, None,
                         self.match_element_should_not_exist)

        match_context = MatchContext(self.positive_string)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertEqual(match_element, None,
                         self.match_element_should_not_exist)
Ejemplo n.º 9
0
    def test6_receive_atom_list(self):
        """This test case checks, whether a missing value is created by a list without using the
        auto_include_flag. (should not be the case)"""
        description = "Test6MissingMatchPathValueDetector"
        match_context_fixed_dme = MatchContext(self.pid)
        fixed_dme = FixedDataModelElement('s1', self.pid)
        match_element_fixed_dme = fixed_dme.get_match_element(
            "match1", match_context_fixed_dme)
        match_context_decimal_integer_value_me = MatchContext(self.string)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            'd1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element_decimal_integer_value_me = decimal_integer_value_me.get_match_element(
            "match2", match_context_decimal_integer_value_me)

        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(
            self.aminer_config, [
                match_element_fixed_dme.get_path(),
                match_element_decimal_integer_value_me.get_path()
            ], [self.stream_printer_event_handler], 'Default', False,
            self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(
            missing_match_path_list_value_detector, description)
        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data,
                                     ParserMatch(match_element_fixed_dme), 1,
                                     missing_match_path_list_value_detector)
        self.assertTrue(
            missing_match_path_list_value_detector.receive_atom(
                log_atom_fixed_dme))
    def test8_receive_atom_list_no_missing_value(self):
        """This test case checks whether the class returns wrong positives on lists, when the time limit should not be passed."""
        description = "Test8MissingMatchPathValueDetector"
        t = time.time()
        match_context_fixed_dme = MatchContext(self.pid)
        fixed_dme = FixedDataModelElement('s1', self.pid)
        match_element_fixed_dme = fixed_dme.get_match_element("match1", match_context_fixed_dme)

        match_context_decimal_integer_value_me = MatchContext(self.string)
        decimal_integer_value_me = DecimalIntegerValueModelElement('d1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
                                                                   DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element_decimal_integer_value_me = decimal_integer_value_me.get_match_element(
            "match2", match_context_decimal_integer_value_me)

        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(missing_match_path_list_value_detector, description)
        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t),
                                     missing_match_path_list_value_detector)
        self.assertTrue(missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))

        past_time = 3200
        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, missing_match_path_list_value_detector.default_interval - past_time, self.__realert_interval)
        self.analysis_context.register_component(missing_match_path_list_value_detector, description + "2")
        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t) + past_time,
                                     missing_match_path_list_value_detector)
        self.assertTrue(missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))
        self.assertEqual(self.output_stream.getvalue(), '')
 def test4_receive_atom_with_no_target_value(self):
     """
     This test checks if an event is not triggered.
     The path is in the target_path_list and the value is not in the target_value_list.
     """
     description = "Test4MatchFilterTest"
     decimal_integer_me = DecimalIntegerValueModelElement('integer')
     match_filter = MatchFilter(self.aminer_config, ['/integer'],
                                [self.stream_printer_event_handler],
                                target_value_list=list(range(501)))
     self.analysis_context.register_component(match_filter, description)
     t = time.time()
     for val in range(1000):
         log_atom = LogAtom(
             val,
             ParserMatch(
                 decimal_integer_me.get_match_element(
                     '', MatchContext(str(val).encode('utf-8')))), t,
             match_filter)
         match_filter.receive_atom(log_atom)
         if val <= 500:
             self.assertEqual(
                 self.__expected_string %
                 (datetime.fromtimestamp(t).strftime("%Y-%m-%d %H:%M:%S"),
                  description, val, val), self.output_stream.getvalue())
         else:
             self.assertEqual('', self.output_stream.getvalue())
         self.reset_output_stream()
Ejemplo n.º 12
0
    def test7_receive_atom_list_without_match_element(self):
        """This test case checks if the ReceiveAtom controls the list of MatchElements and responds correctly, when a value is missing."""
        description = "Test7MissingMatchPathValueDetector"
        match_context_fixed_dme = MatchContext(self.pid)
        fixed_dme = FixedDataModelElement('s1', self.pid)
        match_element_fixed_dme = fixed_dme.get_match_element(
            "match1", match_context_fixed_dme)
        match_context_decimal_integer_value_me = MatchContext(self.string)
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            'd1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element_decimal_integer_value_me = decimal_integer_value_me.get_match_element(
            "match2", match_context_decimal_integer_value_me)

        match_context_fixed_dme = MatchContext(self.pid)
        matchElementFixedDME2 = fixed_dme.get_match_element(
            "match3", match_context_fixed_dme)
        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(
            self.aminer_config, [
                match_element_fixed_dme.get_path(),
                match_element_decimal_integer_value_me.get_path()
            ], [self.stream_printer_event_handler], 'Default', False,
            self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(
            missing_match_path_list_value_detector, description)
        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data,
                                     ParserMatch(matchElementFixedDME2), 1,
                                     missing_match_path_list_value_detector)
        self.assertFalse(
            missing_match_path_list_value_detector.receive_atom(
                log_atom_fixed_dme))
    def test14_valid_padding_no_match(self):
        """If the input is valid, but only padding characters can be found, the result should be no match."""
        match_context = MatchContext(b'    ')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
            DecimalIntegerValueModelElement.PAD_TYPE_BLANK)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertEqual(match_element, None,
                         self.match_element_should_not_exist)

        match_context = MatchContext(b'00000')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
            DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        match_element = decimal_integer_value_me.get_match_element(
            None, match_context)
        self.assertEqual(match_element, None,
                         self.match_element_should_not_exist)
 def test13_no_number_input(self):
     """This test checks whether the input is validated against the datatype."""
     match_context = MatchContext(b'This is no number')
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
         DecimalIntegerValueModelElement.PAD_TYPE_NONE)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertEqual(match_element, None,
                      self.match_element_should_not_exist)
Ejemplo n.º 15
0
    def test12get_match_element_match_context_input_validation(self):
        """Check if an exception is raised, when other classes than MatchContext are used in get_match_element."""
        model_element = DecimalIntegerValueModelElement(self.id_)
        data = b"123.22"
        model_element.get_match_element(self.path, DummyMatchContext(data))
        model_element.get_match_element(self.path, MatchContext(data))

        self.assertRaises(AttributeError, model_element.get_match_element, self.path, MatchElement(None, data, None, None))
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, data)
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, data.decode())
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, True)
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, 123)
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, 123.22)
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, None)
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, [])
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, {"key": MatchContext(data)})
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, set())
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, ())
        self.assertRaises(AttributeError, model_element.get_match_element, self.path, model_element)
 def test8positive_number_zero_padding_no_match(self):
     """In this testcase the positive Integer equivalence class in combination with the zero padding is tested with no match expected."""
     match_context = MatchContext(b' 00025537 uid=2')
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
         DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertEqual(match_element, None,
                      self.match_element_should_not_exist)
Ejemplo n.º 17
0
 def test4negative_number_none_padding_no_match(self):
     """This testcase represents the equivalence class of negative numbers in combination with no padding. It unit the correctness of
     the Path usage for all negative integers without padding, when no match is found."""
     match_context = MatchContext(b'- 25537 uid=2')
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
         DecimalIntegerValueModelElement.PAD_TYPE_NONE)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertEqual(match_element, None,
                      self.match_element_should_not_exist)
Ejemplo n.º 18
0
 def test6sign_type_mandatory_none_padding_no_match(self):
     """This testcase represents the equivalence class of all numbers with a mandatory sign in combination with no padding. It unit
     the correctness of the Path usage for all integers with a mandatory sign without padding, when no match is found."""
     match_context = MatchContext(self.positive_string)
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY,
         DecimalIntegerValueModelElement.PAD_TYPE_NONE)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertEqual(match_element, None,
                      self.match_element_should_not_exist)
    def test4atom_no_match_missing_value_string_set(self):
        """
        This test case sets up a set of values, which are all expected to be matched.
        The missing value string is set to a value, so when a string does not match this value is used instead.
        """
        description = "Test4MatchValueStreamWriter"
        output_stream = BytesIO()
        match_context = MatchContext(
            b'25537Euro 25538Euro 25539Euro 25540Pfund ')
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            'd1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
            DecimalIntegerValueModelElement.PAD_TYPE_NONE)

        fixed_dme = FixedDataModelElement('s1', self.euro)
        sequence_model_element = SequenceModelElement(
            'sequence', [decimal_integer_value_me, fixed_dme])
        match_value_stream_writer = MatchValueStreamWriter(
            output_stream, [self.match_sequence_d1, self.match_sequence_s1],
            b';', b'-')
        self.analysis_context.register_component(match_value_stream_writer,
                                                 description)

        match_element = sequence_model_element.get_match_element(
            'match', match_context)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           match_value_stream_writer)
        match_value_stream_writer.receive_atom(log_atom)

        match_element = sequence_model_element.get_match_element(
            'match', match_context)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           match_value_stream_writer)
        match_value_stream_writer.receive_atom(log_atom)

        match_element = sequence_model_element.get_match_element(
            'match', match_context)
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           match_value_stream_writer)
        match_value_stream_writer.receive_atom(log_atom)

        match_element = decimal_integer_value_me.get_match_element(
            'match', match_context)
        match_element.path = self.match_sequence_d1
        log_atom = LogAtom(match_context.match_data,
                           ParserMatch(match_element), 1,
                           match_value_stream_writer)
        match_value_stream_writer.receive_atom(log_atom)

        self.assertEqual(output_stream.getvalue().decode(),
                         '25537;Euro \n25538;Euro \n25539;Euro \n25540;-\n')
 def test10negative_number_blank_padding_no_match(self):
     """
     In this testcase the negative Integer equivalence class in combination with the blank character padding is tested.
     No match expected.
     """
     match_context = MatchContext(b' -25537 uid=2')
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
         DecimalIntegerValueModelElement.PAD_TYPE_BLANK)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertEqual(match_element, None,
                      self.match_element_should_not_exist)
Ejemplo n.º 21
0
 def test3negative_number_none_padding(self):
     """This testcase represents the equivalence class of negative numbers in combination with no padding. It unit the correctness of
     the Path usage for all negative integers without padding."""
     match_context = MatchContext(self.negative_string)
     decimal_integer_value_me = DecimalIntegerValueModelElement(
         None, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL,
         DecimalIntegerValueModelElement.PAD_TYPE_NONE)
     match_element = decimal_integer_value_me.get_match_element(
         None, match_context)
     self.assertNotEqual(match_element, None,
                         self.match_element_should_exist)
     self.assertEqual(match_element.get_match_string(), b'-25537',
                      self.match_element_unexpected_result)
     self.assertEqual(match_element.get_match_object(), -25537,
                      self.match_element_unexpected_value)
 def test2_receive_atom_trigger_no_event(self):
     """This test checks if an event is not triggered if the path is not in the target_path_list."""
     description = "Test2MatchFilterTest"
     decimal_integer_me = DecimalIntegerValueModelElement('integer')
     match_filter = MatchFilter(self.aminer_config, ['/strings'],
                                [self.stream_printer_event_handler])
     self.analysis_context.register_component(match_filter, description)
     t = time.time()
     for val in range(1000):
         log_atom = LogAtom(
             val,
             ParserMatch(
                 decimal_integer_me.get_match_element(
                     '', MatchContext(str(val).encode('utf-8')))), t,
             match_filter)
         match_filter.receive_atom(log_atom)
         self.assertEqual('', self.output_stream.getvalue())
    def test10_missing_value_on_persisted(self):
        """Persisting lists is tested in this test case."""
        description = "Test91MissingMatchPathValueDetector"
        t = time.time()
        match_context_fixed_dme = MatchContext(self.pid)
        fixed_dme = FixedDataModelElement('s2', self.pid)
        match_element_fixed_dme = fixed_dme.get_match_element("match3", match_context_fixed_dme)

        match_context_decimal_integer_value_me = MatchContext(self.string)
        decimal_integer_value_me = DecimalIntegerValueModelElement('d2', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
                                                                   DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element_decimal_integer_value_me = decimal_integer_value_me.get_match_element(
            "match4", match_context_decimal_integer_value_me)
        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(missing_match_path_list_value_detector, description)
        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t),
                                     missing_match_path_list_value_detector)
        self.assertTrue(missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))
        missing_match_path_list_value_detector.do_persist()

        past_time = 4000
        other_missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(other_missing_match_path_list_value_detector, description + "2")
        other_missing_match_path_list_value_detector.set_check_value(other_missing_match_path_list_value_detector.get_channel_key(
            log_atom_fixed_dme)[1], self.__default_interval - past_time, match_element_fixed_dme.get_path())

        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t) + past_time,
                                     other_missing_match_path_list_value_detector)
        self.assertTrue(other_missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))
        # skipcq: PYL-R1714
        self.assertTrue((self.output_stream.getvalue() == self.__expected_string % (
            datetime.fromtimestamp(t + past_time).strftime(self.datetime_format_string),
            other_missing_match_path_list_value_detector.__class__.__name__, description + "2", 1,
            "match3/s2, match4/d2: ' pid=' overdue 400s (interval -400)")) or (self.output_stream.getvalue() == self.__expected_string % (
              datetime.fromtimestamp(t + past_time + 1).strftime(self.datetime_format_string),
              other_missing_match_path_list_value_detector.__class__.__name__, description + "2", 1,
              "match3/s2, match4/d2: ' pid=' overdue 400s (interval -400)")))
    def test9_receive_atom_list_missing_value(self):
        """This test case checks if missing values are reported correctly."""
        description = "Test90MissingMatchPathValueDetector"
        t = time.time()
        match_context_fixed_dme = MatchContext(self.pid)
        fixed_dme = FixedDataModelElement('s1', self.pid)
        match_element_fixed_dme = fixed_dme.get_match_element("match1", match_context_fixed_dme)
        match_context_decimal_integer_value_me = MatchContext(self.string)
        decimal_integer_value_me = DecimalIntegerValueModelElement('d1', DecimalIntegerValueModelElement.SIGN_TYPE_NONE,
                                                                   DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        match_element_decimal_integer_value_me = decimal_integer_value_me.get_match_element(
            "match2", match_context_decimal_integer_value_me)

        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, self.__default_interval, self.__realert_interval)
        self.analysis_context.register_component(missing_match_path_list_value_detector, description)

        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t),
                                     missing_match_path_list_value_detector)
        self.assertTrue(missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))

        past_time = 4000
        missing_match_path_list_value_detector = MissingMatchPathListValueDetector(self.aminer_config, [
            match_element_fixed_dme.get_path(), match_element_decimal_integer_value_me.get_path()], [self.stream_printer_event_handler],
            'Default', True, missing_match_path_list_value_detector.default_interval - past_time, self.__realert_interval)
        self.analysis_context.register_component(missing_match_path_list_value_detector, description + "2")

        log_atom_fixed_dme = LogAtom(fixed_dme.fixed_data, ParserMatch(match_element_fixed_dme), round(t) + past_time,
                                     missing_match_path_list_value_detector)
        self.assertTrue(missing_match_path_list_value_detector.receive_atom(log_atom_fixed_dme))
        # skipcq: PYL-R1714
        self.assertTrue((self.output_stream.getvalue() == self.__expected_string % (
            datetime.fromtimestamp(t + past_time).strftime(self.datetime_format_string),
            missing_match_path_list_value_detector.__class__.__name__, description + "2", 1,
            "match1/s1, match2/d1: ' pid=' overdue 400s (interval -400)")) or (self.output_stream.getvalue() == self.__expected_string % (
              datetime.fromtimestamp(t + past_time + 1).strftime(self.datetime_format_string),
              missing_match_path_list_value_detector.__class__.__name__, description + "2", 1,
              "match1/s1, match2/d1: ' pid=' overdue 400s (interval -400)")))
Ejemplo n.º 25
0
    def test6get_match_element_optional_zero_values_no_match(self):
        """Test not matching values with default values of value_sign_type and value_pad_type."""
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            self.id_, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL, DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        data = b"+22.25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"22,25"
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b".25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b" 25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"  25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"e+10"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"no number 22 some string."
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)
Ejemplo n.º 26
0
    def test3get_match_element_default_values(self):
        """Test valid integer values with default values of value_sign_type and value_pad_type."""
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            self.id_, DecimalIntegerValueModelElement.SIGN_TYPE_NONE, DecimalIntegerValueModelElement.PAD_TYPE_NONE)
        data = b"22.25 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"0.25 some string."
        value = b"0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)

        data = b"22 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"22.12.2021 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"22. some string"
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"0 some string"
        value = b"0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)
Ejemplo n.º 27
0
    def test5get_match_element_optional_zero_values(self):
        """Test valid float values with "optional" or "zero" values of value_sign_type and value_pad_type."""
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            self.id_, DecimalIntegerValueModelElement.SIGN_TYPE_OPTIONAL, DecimalIntegerValueModelElement.PAD_TYPE_ZERO)
        data = b"22.25 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"-22.25 some string."
        value = b"-22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, -22, None)

        data = b"0.25 some string."
        value = b"0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)

        data = b"22 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"22.12.2021 some string."
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"22. some string"
        value = b"22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"025 some string"
        value = b"025"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 25, None)

        data = b"0025 some string"
        value = b"0025"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 25, None)

        data = b"0025.22 some string"
        value = b"0025"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 25, None)

        data = b"1e-5 some string"
        value = b"1"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 1, None)

        data = b"1e+0 some string"
        value = b"1"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 1, None)

        data = b"0 some string"
        value = b"0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)

        data = b"00 some string"
        value = b"00"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)
Ejemplo n.º 28
0
    def test8get_match_element_mandatory_blank_values_no_match(self):
        """Test not matching values with default values of value_sign_type and value_pad_type."""
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            self.id_, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY, DecimalIntegerValueModelElement.PAD_TYPE_BLANK)
        data = b"22.25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"+  22.25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"-  22.25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"+22,25"
        value = b"+22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"22,25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"22.12.2021 some string."
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b".25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b" +25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b" -25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"025"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"0025"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"e+10"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"00"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"no number 22 some string."
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)
Ejemplo n.º 29
0
    def test7get_match_element_mandatory_blank_values(self):
        """Test valid float values with "mandatory" or "blank" values of value_sign_type and value_pad_type."""
        decimal_integer_value_me = DecimalIntegerValueModelElement(
            self.id_, DecimalIntegerValueModelElement.SIGN_TYPE_MANDATORY, DecimalIntegerValueModelElement.PAD_TYPE_BLANK)
        data = b"+22.25 some string."
        value = b"+22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"-22.25 some string."
        value = b"-22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, -22, None)

        data = b"+0.25 some string."
        value = b"+0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)

        data = b"+22 some string."
        value = b"+22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"+22. some string"
        value = b"+22"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 22, None)

        data = b"+ 25 some string"
        value = b"+ 25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 25, None)

        data = b"- 25 some string"
        value = b"- 25"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, -25, None)

        data = b"+1e-5 some string"
        value = b"+1"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 1, None)

        data = b"+1e+0 some string"
        value = b"+1"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 1, None)

        data = b"+ 1e+0 some string"
        value = b"+ 1"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 1, None)

        data = b"+0 some string"
        value = b"+0"
        match_context = DummyMatchContext(data)
        match_element = decimal_integer_value_me.get_match_element(self.path, match_context)
        self.compare_match_results(data, match_element, match_context, self.id_, self.path, value, 0, None)