コード例 #1
0
    def _parseCommand(self, command):
        python_statement = toPython(command.genMeta(), command.where)

        # if the parser failed to parse the where clause, the python statement
        # will be empty.
        if not python_statement:
            raise TriggerRuleSourceError(command.where)

        log.debug('Parsing From: "%s"' % command.where)
        log.debug('        To  : "%s"' % python_statement)
        return python_statement
    def _parseCommand(self, command):
        python_statement = toPython(command.genMeta(), command.where)

        # if the parser failed to parse the where clause, the python statement
        # will be empty.
        if not python_statement:
            raise TriggerRuleSourceError(command.where)

        log.debug('Parsing From: "%s"' % command.where)
        log.debug('        To  : "%s"' % python_statement)
        return python_statement
コード例 #3
0
    def testRuleWhereClauseToPython(self):
        class MockEvent(object):
            summary = 'Event foobaz summary'
            current_user_name = 'admin'
            event_class = '/App/Info'
            event_class_key = 'EventClassKey'
            event_key = '/Status/Heartbeat'
            status = STATUS_NEW
            severity = SEVERITY_ERROR
            syslog_facility = 11
            syslog_priority = 0
            agent = 'zenhub'
            monitor = 'my_manager_ends_with'
            message = 'message does contain'
            nt_event_code = '1000'

        class MockDevice(object):
            device_class = '/Discovered'
            priority = 2
            production_state = 500
            groups = '|/Group1|/Group2'
            systems = '|/System1|/System2'
            location = 'loc_contains'
            ip_address = '192.168.1.2'

        class MockElem(object):
            pass

        class MockSubElem(object):
            pass

        evt = MockEvent()
        dev = MockDevice()
        elem = MockElem()
        sub_elem = MockSubElem()

        for where_clause, python_statement in self.test_rules:
            converted_python = toPython(self.generated_meta, where_clause)
            # TODO: Change strings above to include double quotes instead of single quotes to match rule builder
            self.assertEquals(converted_python,
                              python_statement.replace("'", '"'))
            fn = eval('lambda evt, dev, elem, sub_elem: ' + converted_python)
            # TODO: Validate the boolean logic of before/after migration! We can't just validate the string - we need
            # to verify that it evaluates the same before/after.
            fn(evt, dev, elem, sub_elem)

        for where_clause in self.exception_rules:
            self.assertRaises(PythonConversionException, toPython,
                              self.generated_meta, where_clause)
コード例 #4
0
    def testRuleWhereClauseToPython(self):
        class MockEvent(object):
            summary = "Event foobaz summary"
            current_user_name = "admin"
            event_class = "/App/Info"
            event_class_key = "EventClassKey"
            event_key = "/Status/Heartbeat"
            status = STATUS_NEW
            severity = SEVERITY_ERROR
            syslog_facility = 11
            syslog_priority = 0
            agent = "zenhub"
            monitor = "my_manager_ends_with"
            message = "message does contain"
            nt_event_code = "1000"

        class MockDevice(object):
            device_class = "/Discovered"
            priority = 2
            production_state = 500
            groups = "|/Group1|/Group2"
            systems = "|/System1|/System2"
            location = "loc_contains"
            ip_address = "192.168.1.2"

        class MockElem(object):
            pass

        class MockSubElem(object):
            pass

        evt = MockEvent()
        dev = MockDevice()
        elem = MockElem()
        sub_elem = MockSubElem()

        for where_clause, python_statement in self.test_rules:
            converted_python = toPython(self.generated_meta, where_clause)
            # TODO: Change strings above to include double quotes instead of single quotes to match rule builder
            self.assertEquals(converted_python, python_statement.replace("'", '"'))
            fn = eval("lambda evt, dev, elem, sub_elem: " + converted_python)
            # TODO: Validate the boolean logic of before/after migration! We can't just validate the string - we need
            # to verify that it evaluates the same before/after.
            fn(evt, dev, elem, sub_elem)

        for where_clause in self.exception_rules:
            self.assertRaises(PythonConversionException, toPython, self.generated_meta, where_clause)