예제 #1
0
def save_custom_attrs_to_mk_file(attrs):
    output = watolib.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(watolib.multisite_dir())
    store.save_text_to_file(watolib.multisite_dir() + "custom_attrs.mk", output)
예제 #2
0
파일: roles.py 프로젝트: maxmalysh/checkmk
    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
        config.roles.update(self._roles)

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

        hooks.call("roles-saved", self._roles)
예제 #3
0
class BILayoutManagement(object):
    _config_file = Path(watolib.multisite_dir()) / "bi_layouts.mk"

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

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

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

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

    @classmethod
    def get_all_bi_aggregation_layouts(cls):
        # type: () -> Any
        return config.bi_layouts["aggregations"]
예제 #4
0
 def _save(self):
     store.save_to_mk_file(
         watolib.multisite_dir() + "read_only.mk",
         "wato_read_only",
         self._settings,
         pprint_value=config.wato_pprint_config,
     )
 def convert_config(self):
     if Path(self._bi_configuration_file).exists():
         # Already converted bi.mk -> bi_config.mk
         return
     if not Path(watolib.multisite_dir(), "bi.mk").exists():
         # No legacy bi.mk available
         return
     packs_data = BILegacyConfigConverter().get_schema_for_packs()
     self._instantiate_packs(packs_data)
     self.save_config()
예제 #6
0
def load_custom_attrs_from_mk_file(lock):
    filename = os.path.join(watolib.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
    def convert_config(self):
        old_bi_config = Path(watolib.multisite_dir(), "bi.mk")
        if not old_bi_config.exists():
            self._logger.info("Skipping conversion of bi.mk (already done)")
            return

        try:
            if Path(self._bi_configuration_file).exists():
                # Already converted bi.mk -> bi_config.bi
                return
            packs_data = BILegacyConfigConverter(self._logger).get_schema_for_packs()
            self._instantiate_packs(packs_data)
            self.save_config()
        finally:
            # Delete superfluous bi.mk, otherwise it would be read on every web request
            old_bi_config.unlink(missing_ok=True)
예제 #8
0
 def bi_configuration_file(cls) -> str:
     return str(Path(watolib.multisite_dir()) / "bi_config.bi")