Beispiel #1
0
    def _get_custom_check_origin_rule(self, ruleset: Ruleset, hostname: str,
                                      svc_desc: str) -> Optional[_Tuple[CREFolder, int, Rule]]:
        # We could use the outcome of _setting instead of the outcome of
        # the automation call in the future
        _setting, rules = ruleset.analyse_ruleset(self._hostname,
                                                  svc_desc_or_item=None,
                                                  svc_desc=None)

        for rule_folder, rule_index, rule in rules:
            if rule.is_disabled():
                continue
            if rule.value["service_description"] != self._service:
                continue

            return rule_folder, rule_index, rule

        return None
Beispiel #2
0
    def _save_service_enable_disable_rules(self, services, value):
        if not services:
            return

        rulesets = AllRulesets()
        rulesets.load()

        try:
            ruleset = rulesets.get("ignored_services")
        except KeyError:
            ruleset = Ruleset(
                "ignored_services",
                ruleset_matcher.get_tag_to_group_map(active_config.tags))

        modified_folders = []

        service_patterns: HostOrServiceConditions = [
            service_description_to_condition(s) for s in services
        ]
        modified_folders += self._remove_from_rule_of_host(ruleset,
                                                           service_patterns,
                                                           value=not value)

        # Check whether or not the service still needs a host specific setting after removing
        # the host specific setting above and remove all services from the service list
        # that are fine without an additional change.
        for service in list(services):
            value_without_host_rule = ruleset.analyse_ruleset(
                self._host.name(), service, service)[0]
            if (not value and value_without_host_rule
                    in [None, False]) or value == value_without_host_rule:
                services.remove(service)

        service_patterns = [
            service_description_to_condition(s) for s in services
        ]
        modified_folders += self._update_rule_of_host(ruleset,
                                                      service_patterns,
                                                      value=value)

        for folder in modified_folders:
            rulesets.save_folder(folder)