Exemple #1
0
def save_notification_rules(rules):
    # type: (List[Dict]) -> None
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(wato_root_dir() + "notifications.mk",
                          "notification_rules",
                          rules,
                          pprint_value=config.wato_pprint_config)
Exemple #2
0
def save_timeperiods(timeperiods):
    # type: (TimeperiodSpecs) -> None
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(wato_root_dir() + "timeperiods.mk",
                          "timeperiods",
                          _filter_builtin_timeperiods(timeperiods),
                          pprint_value=config.wato_pprint_config)
Exemple #3
0
def save_notification_rules(rules):
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(
        wato_root_dir() + "notifications.mk",
        "notification_rules",
        rules,
        pprint_value=config.wato_pprint_config)
Exemple #4
0
def save_timeperiods(timeperiods: TimeperiodSpecs) -> None:
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(wato_root_dir() + "timeperiods.mk",
                          "timeperiods",
                          _filter_builtin_timeperiods(timeperiods),
                          pprint_value=config.wato_pprint_config)
    g.timeperiod_information = timeperiods
Exemple #5
0
def _need_to_create_sample_config():
    if os.path.exists(multisite_dir() + "tags.mk") \
        or os.path.exists(wato_root_dir() + "rules.mk") \
        or os.path.exists(wato_root_dir() + "groups.mk") \
        or os.path.exists(wato_root_dir() + "notifications.mk") \
        or os.path.exists(wato_root_dir() + "global.mk"):
        return False
    return True
Exemple #6
0
def save_notification_rules(rules: list[EventRule]) -> None:
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(
        wato_root_dir() + "notifications.mk",
        "notification_rules",
        rules,
        pprint_value=active_config.wato_pprint_config,
    )
Exemple #7
0
def save_timeperiods(timeperiods: TimeperiodSpecs) -> None:
    store.mkdir(wato_root_dir())
    store.save_to_mk_file(
        wato_root_dir() + "timeperiods.mk",
        "timeperiods",
        _filter_builtin_timeperiods(timeperiods),
        pprint_value=active_config.wato_pprint_config,
    )
    load_timeperiods.cache_clear()
Exemple #8
0
def load_timeperiods() -> TimeperiodSpecs:
    if "timeperiod_information" in g:
        return g.timeperiod_information
    timeperiods = store.load_from_mk_file(wato_root_dir() + "timeperiods.mk",
                                          "timeperiods", {})
    timeperiods.update(builtin_timeperiods())

    g.timeperiod_information = timeperiods
    return timeperiods
Exemple #9
0
def load_notification_rules(lock=False):
    filename = wato_root_dir() + "notifications.mk"
    notification_rules = store.load_from_mk_file(filename, "notification_rules", [], lock=lock)

    # Convert to new plugin configuration format
    for rule in notification_rules:
        if "notify_method" in rule:
            method = rule["notify_method"]
            plugin = rule["notify_plugin"]
            del rule["notify_method"]
            rule["notify_plugin"] = (plugin, method)

    return notification_rules
Exemple #10
0
    def _load_rulesets_via_redis(
        self, folder: CREFolder, only_varname: Optional[RulesetName] = None
    ) -> None:
        # Search relevant folders with rules.mk files
        # Note: The sort order of the folders does not matter here
        #       self._load_folder_rulesets ultimately puts each folder into a dict
        #       and groups/sorts them later on with a different mechanism
        all_folders = get_wato_redis_client().recursive_subfolders_for_path(
            f"{folder.path()}/".lstrip("/")
        )

        root_dir = wato_root_dir()[:-1]
        relevant_folders = []
        for folder_path in all_folders:
            if os.path.exists(f"{root_dir}/{folder_path}rules.mk"):
                relevant_folders.append(folder_path)

        for folder_path_with_slash in relevant_folders:
            stripped_folder = folder_path_with_slash.strip("/")
            self._load_folder_rulesets(Folder.folder(stripped_folder), only_varname)
Exemple #11
0
 def __init__(self):
     super().__init__(
         config_file_path=Path(wato_root_dir()) /
         "predefined_conditions.mk",
         config_variable="predefined_conditions",
     )
Exemple #12
0
 def __init__(self):
     super().__init__(config_file_path=Path(wato_root_dir()) / "passwords.mk",
                      config_variable="stored_passwords")
Exemple #13
0
 def _save_base_config(self, cfg):
     base_config_file = WatoSimpleConfigFile(
         config_file_path=Path(wato_root_dir()) / "tags.mk",
         config_variable="tag_config")
     base_config_file.save(cfg)
Exemple #14
0
 def config_dir(self):
     return wato_root_dir()
Exemple #15
0
def load_timeperiods() -> TimeperiodSpecs:
    timeperiods = store.load_from_mk_file(wato_root_dir() + "timeperiods.mk",
                                          "timeperiods", {})
    timeperiods.update(builtin_timeperiods())
    return timeperiods
Exemple #16
0
 def _save_base_config(self, cfg: TagConfigSpec) -> None:
     self._config_file_path.parent.mkdir(mode=0o770,
                                         exist_ok=True,
                                         parents=True)
     store.save_to_mk_file(
         Path(wato_root_dir()) / "tags.mk", "tag_config", cfg)