Пример #1
0
 def test_rule_lookup(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     trigger = ReactorModelTest._create_save_trigger(triggertype)
     runnertype = ActionModelTest._create_save_runnertype()
     action = ActionModelTest._create_save_action(runnertype)
     saved = ReactorModelTest._create_save_rule(trigger, action)
     retrievedrules = Rule.query(trigger=reference.get_str_resource_ref_from_model(trigger))
     self.assertEqual(1, len(retrievedrules), 'No rules found.')
     for retrievedrule in retrievedrules:
         self.assertEqual(saved.id, retrievedrule.id, 'Incorrect rule returned.')
     ReactorModelTest._delete([saved, trigger, action, runnertype, triggertype])
Пример #2
0
 def test_rule_lookup(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     trigger = ReactorModelTest._create_save_trigger(triggertype)
     runnertype = ActionModelTest._create_save_runnertype()
     action = ActionModelTest._create_save_action(runnertype)
     saved = ReactorModelTest._create_save_rule(trigger, action)
     retrievedrules = Rule.query(trigger=reference.get_str_resource_ref_from_model(trigger))
     self.assertEqual(1, len(retrievedrules), 'No rules found.')
     for retrievedrule in retrievedrules:
         self.assertEqual(saved.id, retrievedrule.id, 'Incorrect rule returned.')
     ReactorModelTest._delete([saved, trigger, action, runnertype, triggertype])
Пример #3
0
    def get_matching_rules_for_trigger(self, trigger_instance):
        trigger = get_trigger_db(trigger=trigger_instance.trigger)
        rules = Rule.query(trigger=trigger_instance.trigger, enabled=True)
        LOG.info('Found %d rules defined for trigger %s', len(rules), trigger['name'])
        matcher = RulesMatcher(trigger_instance=trigger_instance,
                               trigger=trigger, rules=rules)

        matching_rules = matcher.get_matching_rules()
        LOG.info('Matched %s rule(s) for trigger_instance %s.', len(matching_rules),
                 trigger['name'])
        return matching_rules
Пример #4
0
    def _unregister_trigger_types(self, pack):
        deleted_trigger_types_dbs = self._delete_pack_db_objects(pack=pack, access_cls=TriggerType)

        # 2. Check if deleted trigger is used by any other rules outside this pack
        for trigger_type_db in deleted_trigger_types_dbs:
            rule_dbs = Rule.query(trigger=trigger_type_db.ref, pack__ne=trigger_type_db.pack)

            for rule_db in rule_dbs:
                self.logger.warning('Rule "%s" references deleted trigger "%s"' %
                                    (rule_db.name, trigger_type_db.ref))

        return deleted_trigger_types_dbs
Пример #5
0
    def get_matching_rules_for_trigger(self, trigger_instance):
        trigger = trigger_instance.trigger
        trigger = get_trigger_db_by_ref(trigger_instance.trigger)
        rules = Rule.query(trigger=trigger_instance.trigger, enabled=True)
        LOG.info('Found %d rules defined for trigger %s', len(rules), trigger['name'])
        matcher = RulesMatcher(trigger_instance=trigger_instance,
                               trigger=trigger, rules=rules)

        matching_rules = matcher.get_matching_rules()
        LOG.info('Matched %s rule(s) for trigger_instance %s.', len(matching_rules),
                 trigger['name'])
        return matching_rules
Пример #6
0
    def _unregister_trigger_types(self, pack):
        deleted_trigger_types_dbs = self._delete_pack_db_objects(pack=pack, access_cls=TriggerType)

        # 2. Check if deleted trigger is used by any other rules outside this pack
        for trigger_type_db in deleted_trigger_types_dbs:
            rule_dbs = Rule.query(trigger=trigger_type_db.ref, pack__ne=trigger_type_db.pack)

            for rule_db in rule_dbs:
                self.logger.warning('Rule "%s" references deleted trigger "%s"' %
                                    (rule_db.name, trigger_type_db.ref))

        return deleted_trigger_types_dbs