def _find_usages_in_notification_rules( self, tpname: str) -> List[TimeperiodUsage]: used_in: List[TimeperiodUsage] = [] for index, rule in enumerate(load_notification_rules()): used_in += self._find_usages_in_notification_rule( tpname, index, rule) return used_in
def _rewrite_servicenow_notification_config(self) -> None: # Management type "case" introduced with werk #13096 in 2.1.0i1 notification_rules = load_notification_rules() for index, rule in enumerate(notification_rules): plugin_name = rule["notify_plugin"][0] if plugin_name != "servicenow": continue params = rule["notify_plugin"][1] if "mgmt_types" in params: continue incident_params = { key: params.pop(key) for key in [ "caller", "host_short_desc", "svc_short_desc", "host_desc", "svc_desc", "urgency", "impact", "ack_state", "recovery_state", "dt_state", ] if key in params } params["mgmt_type"] = ("incident", incident_params) notification_rules[index]["notify_plugin"] = (plugin_name, params) save_notification_rules(notification_rules)
def rename_host_in_event_rules(oldname, newname): actions = [] def rename_in_event_rules(rules): num_changed = 0 for rule in rules: for key in ["match_hosts", "match_exclude_hosts"]: if rule.get(key): if watolib.rename_host_in_list(rule[key], oldname, newname): num_changed += 1 return num_changed users = userdb.load_users(lock=True) some_user_changed = False for user in users.values(): if user.get("notification_rules"): rules = user["notification_rules"] num_changed = rename_in_event_rules(rules) if num_changed: actions += ["notify_user"] * num_changed some_user_changed = True rules = load_notification_rules() num_changed = rename_in_event_rules(rules) if num_changed: actions += ["notify_global"] * num_changed save_notification_rules(rules) if alert_handling: rules = alert_handling.load_alert_handler_rules() if rules: num_changed = rename_in_event_rules(rules) if num_changed: actions += ["alert_rules"] * num_changed alert_handling.save_alert_handler_rules(rules) # Notification channels of flexible notifications also can have host conditions for user in users.values(): method = user.get("notification_method") if method and isinstance(method, tuple) and method[0] == "flexible": channels_changed = 0 for channel in method[1]: if channel.get("only_hosts"): num_changed = watolib.rename_host_in_list( channel["only_hosts"], oldname, newname) if num_changed: channels_changed += 1 some_user_changed = True if channels_changed: actions += ["notify_flexible"] * channels_changed if some_user_changed: userdb.save_users(users) return actions
def _find_usages_of_contact_group_in_notification_rules(name: str) -> List[Tuple[str, str]]: used_in: List[Tuple[str, str]] = [] for rule in load_notification_rules(): if _used_in_notification_rule(name, rule): title = "%s: %s" % (_("Notification rule"), rule.get("description", "")) used_in.append((title, "wato.py?mode=notifications")) for user_id, user_rules in load_user_notification_rules().items(): for rule in user_rules: if _used_in_notification_rule(name, rule): title = "%s: %s" % (_("Notification rules of user %s") % user_id, rule.get("description", "")) used_in.append((title, "wato.py?mode=user_notifications&user=%s" % user_id)) return used_in
def _find_usages_in_notification_rules(self, tpname): used_in = [] for index, rule in enumerate(load_notification_rules()): used_in += self._find_usages_in_notification_rule( tpname, index, rule) return used_in
for rule in rules: for key in ["match_hosts", "match_exclude_hosts"]: if rule.get(key): if rename_host_in_list(rule[key], oldname, newname): num_changed += 1 return num_changed users = userdb.load_users(lock=True) some_user_changed = False for user in users.values(): if unrules := user.get("notification_rules"): if num_changed := rename_in_event_rules(unrules): actions += ["notify_user"] * num_changed some_user_changed = True nrules = load_notification_rules() if num_changed := rename_in_event_rules(nrules): actions += ["notify_global"] * num_changed save_notification_rules(nrules) if alert_handling: if arules := alert_handling.load_alert_handler_rules(): if num_changed := rename_in_event_rules(arules): actions += ["alert_rules"] * num_changed alert_handling.save_alert_handler_rules(arules) # Notification channels of flexible notifications also can have host conditions for user in users.values(): method = user.get("notification_method") if method and isinstance(method, tuple) and method[0] == "flexible": channels_changed = 0