Пример #1
0
    def _replicates_mkps(self):
        replicates_mkps = False
        for site in wato_slave_sites().values():
            if site.get("replicate_mkps"):
                replicates_mkps = True
                break

        if not replicates_mkps:
            return
Пример #2
0
    def _execute_remote_automation(self, request):
        if request["site_id"] not in sitenames():
            raise MKUserError("site_id", _("This site does not exist."))

        if request["site_id"] not in wato_slave_sites():
            raise MKUserError("site_id", _("This site is not a distributed WATO site."))

        return cmk.gui.watolib.automations.do_remote_automation(
            get_site_config(request["site_id"]), request["command"], request["command_args"]
        )
Пример #3
0
    def _execute_sync(self) -> None:
        newest_host_labels = self._load_newest_host_labels_per_site()

        with ThreadPool(20) as pool:
            results = pool.map(
                self._execute_site_sync_bg,
                [(site_id, site_spec, SiteRequest(newest_host_labels.get(site_id, 0.0), None))
                 for site_id, site_spec in wato_slave_sites().items()])

        self._process_site_sync_results(newest_host_labels, results)
Пример #4
0
class DiscoveredHostLabelSyncJob(gui_background_job.GUIBackgroundJob):
    """This job synchronizes the discovered host labels from remote sites to the central site

    Currently they are only needed for the agent bakery, but may be used in other places in the
    future.
    """

    job_prefix = "discovered_host_label_sync"

    @classmethod
    def gui_title(cls) -> str:
        return _("Discovered host label synchronization")

    def __init__(self) -> None:
        super().__init__(
            job_id=self.job_prefix,
            title=self.gui_title(),
            stoppable=False,
        )

    def do_sync(self, job_interface: background_job.BackgroundProcessInterface) -> None:
        job_interface.send_progress_update(_("Synchronization started..."))
        self._execute_sync()
        job_interface.send_result_message(_("The synchronization finished."))

    def _execute_sync(self) -> None:
        newest_host_labels = self._load_newest_host_labels_per_site()

        with (request_context := make_request_context()):  # pylint: disable=superfluous-parens
            load_config()

        with ThreadPool(20) as pool:
            results = pool.map(
                self._execute_site_sync_bg,
                [
                    (
                        request_context,
                        site_id,
                        site_spec,
                        SiteRequest(newest_host_labels.get(site_id, 0.0), None),
                    )
                    for site_id, site_spec in wato_slave_sites().items()
                ],
            )

        self._process_site_sync_results(newest_host_labels, results)