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 rename_host_in_list(rule[key], oldname, newname): num_changed += 1 return num_changed
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 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 = 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
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 for channel in method[1]: if channel.get("only_hosts"): num_changed = 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 _rename_host_in_multisite(oldname, newname): # State of Multisite --------------------------------------- # Favorites of users and maybe other settings. We simply walk through