Example #1
0
def save_custom_attrs_to_mk_file(attrs):
    output = wato_fileheader()
    for what in ["user", "host"]:
        if what in attrs and len(attrs[what]) > 0:
            output += "if type(wato_%s_attrs) != list:\n    wato_%s_attrs = []\n" % (
                what, what)
            output += "wato_%s_attrs += %s\n\n" % (what,
                                                   pprint.pformat(attrs[what]))

    store.mkdir(multisite_dir())
    store.save_text_to_file(multisite_dir() + "custom_attrs.mk", output)
Example #2
0
    def _save_roles(self):
        # Reflect the data in the roles dict kept in the config module Needed
        # for instant changes in current page while saving modified roles.
        # Otherwise the hooks would work with old data when using helper
        # functions from the config module
        active_config.roles.update(self._roles)

        store.mkdir(multisite_dir())
        store.save_to_mk_file(
            multisite_dir() + "roles.mk",
            "roles",
            self._roles,
            pprint_value=active_config.wato_pprint_config,
        )

        hooks.call("roles-saved", self._roles)
Example #3
0
 def _cleanup_pre_16_config(self) -> None:
     # Cleanup pre 1.6 config files (tags were just saved with new path)
     try:
         Path(multisite_dir(), "hosttags.mk").unlink()
     except OSError as e:
         if e.errno != errno.ENOENT:
             raise
Example #4
0
 def _save(self):
     store.save_to_mk_file(
         multisite_dir() + "read_only.mk",
         "wato_read_only",
         self._settings,
         pprint_value=active_config.wato_pprint_config,
     )
Example #5
0
class BILayoutManagement:
    _config_file = Path(multisite_dir()) / "bi_layouts.mk"

    @classmethod
    def save_layouts(cls) -> None:
        store.save_to_mk_file(
            str(BILayoutManagement._config_file),
            "bi_layouts",
            active_config.bi_layouts,
            pprint_value=True,
        )

    @classmethod
    def load_bi_template_layout(cls, template_id: Optional[str]) -> Any:
        return active_config.bi_layouts["templates"].get(template_id)

    @classmethod
    def load_bi_aggregation_layout(cls,
                                   aggregation_name: Optional[str]) -> Any:
        return active_config.bi_layouts["aggregations"].get(aggregation_name)

    @classmethod
    def get_all_bi_template_layouts(cls) -> Any:
        return active_config.bi_layouts["templates"]

    @classmethod
    def get_all_bi_aggregation_layouts(cls) -> Any:
        return active_config.bi_layouts["aggregations"]
Example #6
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
Example #7
0
    def _load_pre_16_config(self, lock):
        file_path = Path(multisite_dir()) / "hosttags.mk"
        legacy_cfg = store.load_mk_file(str(file_path), {
            "wato_host_tags": [],
            "wato_aux_tags": []
        },
                                        lock=lock)

        return cmk.utils.tags.transform_pre_16_tags(
            legacy_cfg["wato_host_tags"], legacy_cfg["wato_aux_tags"])
Example #8
0
    def save(self, cfg):
        super().save(cfg)
        self._save_base_config(cfg)

        # Cleanup pre 1.6 config files (tags were just saved with new path)
        try:
            Path(multisite_dir(), "hosttags.mk").unlink()
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise

        _export_hosttags_to_php(cfg)
Example #9
0
    def save_sites(cls, sites, activate=True):
        # TODO: Clean this up
        from cmk.gui.watolib.hosts_and_folders import Folder
        store.mkdir(multisite_dir())
        store.save_to_mk_file(cls._sites_mk(), "sites", sites)

        # Do not activate when just the site's global settings have
        # been edited
        if activate:
            config.load_config()  # make new site configuration active
            _update_distributed_wato_file(sites)
            Folder.invalidate_caches()
            cmk.gui.watolib.sidebar_reload.need_sidebar_reload()

            _create_nagvis_backends(sites)

            # Call the sites saved hook
            hooks.call("sites-saved", sites)
Example #10
0
def load_custom_attrs_from_mk_file(lock):
    filename = os.path.join(multisite_dir(), "custom_attrs.mk")
    vars_ = store.load_mk_file(
        filename,
        {
            "wato_user_attrs": [],
            "wato_host_attrs": [],
        },
        lock=lock,
    )

    attrs = {}
    for what in ["user", "host"]:
        attributes = vars_.get("wato_%s_attrs" % what, [])
        if what == "host":
            attributes = transform_pre_16_host_topics(attributes)
        attrs[what] = attributes
    return attrs
Example #11
0
 def _pre_16_hosttags_path(self):
     return Path(multisite_dir()).joinpath("hosttags.mk")
Example #12
0
 def __init__(self):
     file_path = Path(multisite_dir()) / "tags.mk"
     super(TagConfigFile, self).__init__(config_file_path=file_path,
                                         config_variable="wato_tags")
Example #13
0
 def config_dir(self):
     return multisite_dir()
Example #14
0
 def __init__(self) -> None:
     self._config_file_path: Final = Path(multisite_dir()) / "tags.mk"
     self._config_variable: Final = "wato_tags"
Example #15
0
 def bi_configuration_file(cls) -> str:
     return str(Path(watolib_utils.multisite_dir()) / "bi_config.bi")