def _instantiate_ruleset(ruleset_name, param_value) -> Ruleset: ruleset = Ruleset(ruleset_name, {}) rule = Rule.from_ruleset_defaults(Folder(""), ruleset) rule.value = param_value ruleset.append_rule(Folder(""), rule) assert ruleset.get_rules() return ruleset
def _update_rule_of_host(self, ruleset: Ruleset, service_patterns: HostOrServiceConditions, value: Any) -> List[CREFolder]: folder = self._host.folder() rule = self._get_rule_of_host(ruleset, value) if rule: for service_condition in service_patterns: if service_condition not in rule.conditions.service_description: rule.conditions.service_description.append( service_condition) elif service_patterns: rule = Rule.from_ruleset_defaults(folder, ruleset) conditions = RuleConditions(folder.path()) conditions.host_name = [self._host.name()] # mypy is wrong here vor some reason: # Invalid index type "str" for "Union[Dict[str, str], str]"; expected type "Union[int, slice]" [index] conditions.service_description = sorted(service_patterns, key=lambda x: x["$regex"]) rule.update_conditions(conditions) rule.value = value ruleset.prepend_rule(folder, rule) if rule: return [rule.folder] return []