Ejemplo n.º 1
0
 def _from_vars(self) -> None:
     self._checkmk_config_files_map = get_checkmk_config_files_map()
     self._checkmk_log_files_map = get_checkmk_log_files_map()
     self._collect_dump = bool(
         html.request.get_ascii_input("_collect_dump"))
     self._diagnostics_parameters = self._get_diagnostics_parameters()
     self._job = DiagnosticsDumpBackgroundJob()
Ejemplo n.º 2
0
    def add_or_get_files(
            self, tmp_dump_folder: Path,
            collectors: Collectors) -> DiagnosticsElementFilepaths:
        checkmk_config_files_map = get_checkmk_config_files_map()
        unknown_files = []

        for rel_filepath in self.rel_checkmk_config_filepaths:
            filepath = checkmk_config_files_map.get(rel_filepath)
            if filepath is None or not filepath.exists():
                unknown_files.append(rel_filepath)
                continue

            # Respect file path (2), otherwise the paths of same named files are forgotten (1).
            # Moreover we do not want to pack a folder hierarchy.
            # Example:
            # - apache.d/wato/global.mk
            # - conf.d/wato/global.mk
            # => tar.gz (1):
            #    - global.mk
            #    - global.mk
            # We give these files a new name:
            # => tar.gz (2):
            #    - apache.d-wato-global.mk
            #    - conf.d-wato-global.mk
            new_filename = "-".join(Path(rel_filepath).parts)
            tmp_filepath = shutil.copy(
                str(filepath), str(tmp_dump_folder.joinpath(new_filename)))
            yield Path(tmp_filepath)

        if unknown_files:
            raise DiagnosticsElementError("No such files: %s" %
                                          ", ".join(unknown_files))
Ejemplo n.º 3
0
    def _get_checkmk_config_files_choices(
            self) -> List[CascadingDropdownChoice]:
        sorted_checkmk_config_files = sorted(get_checkmk_config_files_map())
        checkmk_config_files = []
        global_settings = []
        host_and_folders = []

        for rel_config_file in sorted_checkmk_config_files:
            checkmk_config_files.append(rel_config_file)

            rel_config_file_path = Path(rel_config_file)
            rel_config_file_name = rel_config_file_path.name
            rel_config_file_parts = rel_config_file_path.parts

            if (rel_config_file_name == "sites.mk" or
                (rel_config_file_name == "global.mk" and rel_config_file_parts
                 and rel_config_file_parts[0] == "conf.d")):
                global_settings.append(rel_config_file)

            if rel_config_file_name in [
                    "hosts.mk", "tags.mk", "rules.mk", ".wato"
            ]:
                host_and_folders.append(rel_config_file)

        return [
            ("all", _("Pack all files"),
             FixedValue(
                 checkmk_config_files,
                 totext=self._list_of_files_to_text(checkmk_config_files),
             )),
            ("global_settings", _("Only global settings"),
             FixedValue(
                 global_settings,
                 totext=self._list_of_files_to_text(global_settings),
             )),
            ("hosts_and_folders", _("Only hosts and folders"),
             FixedValue(
                 host_and_folders,
                 totext=self._list_of_files_to_text(host_and_folders),
             )),
            ("explicit_list_of_files", _("Explicit list of files"),
             DualListChoice(
                 choices=[(rel_filepath, rel_filepath)
                          for rel_filepath in sorted_checkmk_config_files],
                 size=80,
                 rows=20,
             )),
        ]
Ejemplo n.º 4
0
 def _checkmk_files_map(self) -> CheckmkFilesMap:
     return get_checkmk_config_files_map()