コード例 #1
0
ファイル: host_rename.py プロジェクト: bsmr/tribe29-checkmk
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
コード例 #2
0
ファイル: timeperiods.py プロジェクト: tklecker/checkmk
 def _find_usages_in_alert_handler_rules(self, tpname: str) -> List[TimeperiodUsage]:
     used_in: List[TimeperiodUsage] = []
     if cmk_version.is_raw_edition():
         return used_in
     for index, rule in enumerate(alert_handling.load_alert_handler_rules()):
         if rule.get("match_timeperiod") == tpname:
             url = watolib.folder_preserving_link([
                 ("mode", "alert_handler_rule"),
                 ("edit", index),
             ])
             used_in.append((_("Alert handler rule"), url))
     return used_in
コード例 #3
0
ファイル: timeperiods.py プロジェクト: m4c3/checkMK
    def _find_usages_in_alert_handler_rules(self, tpname):
        used_in = []

        if cmk.is_raw_edition():
            return used_in

        try:
            import cmk.gui.cee.plugins.wato.alert_handling as alert_handling
        except:
            alert_handling = None

        for index, rule in enumerate(alert_handling.load_alert_handler_rules()):
            if rule.get("match_timeperiod") == tpname:
                url = watolib.folder_preserving_link([
                    ("mode", "alert_handler_rule"),
                    ("edit", index),
                ])
                used_in.append((_("Alert handler rule"), url))
        return used_in
コード例 #4
0
ファイル: host_rename.py プロジェクト: m3rlinux/checkmk
    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
            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