def _find_usages_in_time_specific_parameters( self, tpname: str) -> List[TimeperiodUsage]: used_in: List[TimeperiodUsage] = [] rulesets = AllRulesets() rulesets.load() for ruleset in rulesets.get_rulesets().values(): vs = ruleset.valuespec() if not isinstance(vs, cmk.gui.plugins.wato.utils.TimeperiodValuespec): continue for rule_folder, rule_index, rule in ruleset.get_rules(): if not vs.is_active(rule.value): continue for index, (rule_tp_name, _value) in enumerate(rule.value["tp_values"]): if rule_tp_name != tpname: continue edit_url = folder_preserving_link([ ("mode", "edit_rule"), ("back_mode", "timeperiods"), ("varname", ruleset.name), ("rulenr", rule_index), ("rule_folder", rule_folder.path()), ]) used_in.append( (_("Time specific check parameter #%d") % (index + 1), edit_url)) return used_in
def _find_usages_in_host_and_service_rules( self, tpname: str) -> List[TimeperiodUsage]: used_in: List[TimeperiodUsage] = [] rulesets = AllRulesets() rulesets.load() for varname, ruleset in rulesets.get_rulesets().items(): if not isinstance(ruleset.valuespec(), watolib.timeperiods.TimeperiodSelection): continue for _folder, _rulenr, rule in ruleset.get_rules(): if rule.value == tpname: used_in.append(( "%s: %s" % (_("Ruleset"), ruleset.title()), folder_preserving_link([("mode", "edit_ruleset"), ("varname", varname)]), )) break return used_in
def delete_rule(param): """Delete a rule""" user.need_permission("wato.edit") user.need_permission("wato.rulesets") rule_id = param["rule_id"] rule: Rule all_rulesets = AllRulesets() all_rulesets.load() found = False for ruleset in all_rulesets.get_rulesets().values(): for _folder, _index, rule in ruleset.get_rules(): if rule.id == rule_id: ruleset.delete_rule(rule) all_rulesets.save() found = True if found: return http.Response(status=204) return problem( status=404, title="Rule not found.", detail=f"The rule with ID {rule_id!r} could not be found.", )
def _get_rule_by_id(rule_uuid: str, all_rulesets=None) -> RuleEntry: if all_rulesets is None: all_rulesets = AllRulesets() all_rulesets.load() for ruleset in all_rulesets.get_rulesets().values(): folder: CREFolder index: int rule: Rule for folder, index, rule in ruleset.get_rules(): if rule.id == rule_uuid: return RuleEntry( index_nr=index, rule=rule, folder=folder, ruleset=ruleset, all_rulesets=all_rulesets, ) raise ProblemException( status=400, title="Unknown rule.", detail=f"Rule with UUID {rule_uuid} was not found.", )