Esempio n. 1
0
def test_run_executes_plugins(capsys, test_registry, mocker):
    handler_mock = mocker.MagicMock()
    test_registry.register(
        RenameAction(name="test", title="Test Title", sort_index=0, handler=handler_mock)
    )

    assert main.main(["-v", "old"]) == 0

    output = capsys.readouterr()
    assert output.err == ""
    assert "1/1 Test Title..." in output.out
    assert output.out.endswith("Done\n")

    assert handler_mock.called_once_with(SiteId("old"), SiteId("NO_SITE"))
Esempio n. 2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2021 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

import subprocess

from livestatus import SiteId

from cmk.utils.i18n import _

from cmk.post_rename_site.registry import rename_action_registry, RenameAction


def update_core_config(old_site_id: SiteId, new_site_id: SiteId) -> None:
    """After all the changes to the configuration finally trigger a core config update"""
    subprocess.check_call(["cmk", "-U"])


rename_action_registry.register(
    RenameAction(
        name="update_core_config",
        title=_("Update core config"),
        sort_index=900,
        handler=update_core_config,
    ))
from cmk.utils.log.console import warning

from cmk.post_rename_site.main import logger
from cmk.post_rename_site.registry import rename_action_registry, RenameAction


def warn_about_configs_to_review(old_site_id: SiteId,
                                 new_site_id: SiteId) -> None:
    logger.info("")
    warning(
        "Some configs may need to be reviewed\n\n"
        "Parts of the site configuration cannot be migrated automatically. The following\n"
        "parts of the configuration may have to be reviewed and adjusted manually:\n\n"
        "- Custom bookmarks (in users bookmark lists)\n"
        "- Hard coded site filters in custom dashboards, views, reports\n"
        "- Path in rrdcached journal files\n"
        "- NagVis maps or custom NagVis backend settings\n"
        "- Notification rule \"site\" conditions\n"
        "- Event Console rule \"site\" conditions\n"
        "- \"site\" field in \"Agent updater (Linux, Windows, Solaris)\" rules (CEE/CME only)\n"
        "- Alert handler rule \"site\" conditions (CEE/CME only)\n")


rename_action_registry.register(
    RenameAction(
        name="warn_about_configs_to_review",
        title=_("Warn about configurations to review"),
        sort_index=960,
        handler=warn_about_configs_to_review,
    ))
Esempio n. 4
0
    - `site` host_tags entries in the hosts.mk files are updated
    """
    for folder in Folder.all_folders().values():
        # 1. Update explicitly set site in folders
        if folder.attribute("site") == old_site_id:
            logger.debug("Folder %s: Update explicitly set site", folder.alias_path())
            folder.set_attribute("site", new_site_id)

        # 2. Update explicitly set site in hosts
        for host in folder.hosts().values():
            if host.attribute("site") == old_site_id:
                logger.debug("Host %s: Update explicitly set site", host.name())
                host.set_attribute("site", new_site_id)

        # Always rewrite the host config: The host_tags need to be updated, even in case there is no
        # site_id explicitly set. Just to be sure everything is fine we also rewrite the folder
        # config
        logger.debug("Folder %s: Saving config", folder.alias_path())
        folder.save()
        folder.save_hosts()


rename_action_registry.register(
    RenameAction(
        name="hosts_and_folders",
        title=_("Hosts and folders"),
        sort_index=15,
        handler=update_hosts_and_folders,
    )
)
Esempio n. 5
0
from cmk.utils.i18n import _
from cmk.utils.log.console import warning

from cmk.post_rename_site.main import logger
from cmk.post_rename_site.registry import rename_action_registry, RenameAction


def warn_about_network_ports(old_site_id: SiteId, new_site_id: SiteId) -> None:
    if not Path("/omd/sites", old_site_id).exists():
        return  # Site was not copied

    logger.info("")
    warning(
        "Network port configuration may need your attention\n\n"
        "It seems like you copied an existing site. In case you plan to use both on the same "
        "system, you may have to review the network port configuration of your sites. Two sites"
        "with the same configuration may cause network port conflicts."
        "For example if you enabled livestatus to listen via TCP or enabled the Event Console "
        "to listen for incoming Syslog messages or SNMP traps, you may have to update the "
        "configuration in one of the sites to resolve the conflicts.\n")


rename_action_registry.register(
    RenameAction(
        name="warn_about_network_ports",
        title=_("Warn about new network ports"),
        sort_index=955,
        handler=warn_about_network_ports,
    ))
Esempio n. 6
0
from cmk.utils.log.console import warning

from cmk.gui.sites import is_wato_slave_site

from cmk.post_rename_site.main import logger
from cmk.post_rename_site.registry import rename_action_registry, RenameAction


def warn_about_renamed_remote_site(old_site_id: SiteId,
                                   new_site_id: SiteId) -> None:
    """Warn user about central site that needs to be updated manually

    Detect whether or not this is a remote site and issue a warning to let the user known"""
    if not is_wato_slave_site():
        return

    logger.info("")
    warning(
        "You renamed a distributed remote site.\n\nTo make your distributed "
        "setup work again, you will have to update the \"Distributed Monitoring\" "
        "configuration in your central site.\n")


rename_action_registry.register(
    RenameAction(
        name="warn_remote_site",
        title=_("Warn about renamed remote site"),
        sort_index=950,
        handler=warn_about_renamed_remote_site,
    ))
Esempio n. 7
0
        logger.debug("Rename site configuration")
        site_spec = all_sites[new_site_id] = all_sites.pop(old_site_id)

        # 2. Update the sites URL prefix
        site_spec["url_prefix"] = site_spec["url_prefix"].replace(f"/{old_site_id}/",
                                                                  f"/{new_site_id}/")

        # 3. Update the configuration connection
        site_spec["multisiteurl"] = site_spec["multisiteurl"].replace(f"/{old_site_id}/",
                                                                      f"/{new_site_id}/")

    # Iterate all sites and check for status host entries refering to the renamed site
    for this_site_id, site_cfg in all_sites.items():
        status_host = site_cfg.get("status_host")
        if status_host and status_host[0] == old_site_id:
            logger.debug("Update status host of site %s", this_site_id)
            changed = True
            site_cfg["status_host"] = (new_site_id, site_cfg["status_host"][1])

    if changed:
        site_mgmt.save_sites(all_sites, activate=True)


rename_action_registry.register(
    RenameAction(
        name="sites",
        title=_("Distributed monitoring configuration"),
        sort_index=10,
        handler=update_site_config,
    ))