def matches_item(self, item): match_object = ruleset_matcher.RulesetMatchObject( host_name=None, host_folder="/", service_description=item, ) return any(self._get_mismatch_reasons_of_match_object(match_object, host_tags=[]))
def get_mismatch_reasons(self, host_folder, hostname, svc_desc_or_item, svc_desc): """A generator that provides the reasons why a given folder/host/item not matches this rule""" host = host_folder.host(hostname) if host is None: raise MKGeneralException("Failed to get host from folder %r." % host_folder.path()) # BE AWARE: Depending on the service ruleset the service_description of # the rules is only a check item or a full service description. For # example the check parameters rulesets only use the item, and other # service rulesets like disabled services ruleset use full service # descriptions. # # The service_description attribute of the match_object must be set to # either the item or the full service description, depending on the # ruleset, but the labels of a service need to be gathered using the # real service description. if self.ruleset.item_type() == "service": match_object = cmk_base.export.ruleset_match_object_of_service( hostname, svc_desc_or_item) elif self.ruleset.item_type() == "item": match_object = cmk_base.export.ruleset_match_object_for_checkgroup_parameters( hostname, svc_desc_or_item, svc_desc) elif not self.ruleset.item_type(): match_object = ruleset_matcher.RulesetMatchObject(hostname) else: raise NotImplementedError() for reason in self._get_mismatch_reasons_of_match_object(match_object): yield reason
def get_mismatch_reasons(self, host_folder, hostname, service_description): """A generator that provides the reasons why a given folder/host/item not matches this rule""" host = host_folder.host(hostname) if host is None: raise MKGeneralException("Failed to get host from folder %r." % host_folder.path()) match_object = ruleset_matcher.RulesetMatchObject( host_name=hostname, host_folder=host_folder.path_for_rule_matching(), host_tags=host.tag_groups(), host_labels=host.labels(), service_description=service_description, ) for reason in self._get_mismatch_reasons_of_match_object(match_object, host.tags()): yield reason