Exemplo n.º 1
0
    def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
        menu = make_simple_form_page_menu(_("Setting"),
                                          breadcrumb,
                                          form_name="value_editor",
                                          button_name="_save")

        reset_possible = self._config_variable.allow_reset(
        ) and self._is_configured()
        default_values = ABCConfigDomain.get_all_default_globals()
        defvalue = default_values[self._varname]
        value = self._current_settings.get(
            self._varname, self._global_settings.get(self._varname, defvalue))
        menu.dropdowns[0].topics[0].entries.append(
            PageMenuEntry(
                title=_("Remove explicit setting")
                if value == defvalue else _("Reset to default"),
                icon_name="reset",
                item=make_confirmed_form_submit_link(
                    form_name="value_editor",
                    button_name="_reset",
                    message=_(
                        "Do you really want to reset this configuration variable "
                        "back to its default value?"),
                ),
                is_enabled=reset_possible,
                is_shortcut=True,
                is_suggested=True,
            ))

        return menu
Exemplo n.º 2
0
    def __init__(self):
        self._search = None
        self._show_only_modified = False

        super(GlobalSettingsMode, self).__init__()

        self._default_values = ABCConfigDomain.get_all_default_globals()
        self._global_settings = {}
        self._current_settings = {}
Exemplo n.º 3
0
    def __init__(self) -> None:
        self._search = None
        self._show_only_modified = False

        super().__init__()

        self._default_values = ABCConfigDomain.get_all_default_globals()
        self._global_settings: dict[str, Any] = {}
        self._current_settings: dict[str, Any] = {}
Exemplo n.º 4
0
    def page(self) -> None:
        is_configured = self._is_configured()
        is_configured_globally = self._varname in self._global_settings

        default_values = ABCConfigDomain.get_all_default_globals()

        defvalue = default_values[self._varname]
        value = self._current_settings.get(
            self._varname, self._global_settings.get(self._varname, defvalue))

        hint = self._config_variable.hint()
        if hint:
            html.show_warning(hint)

        html.begin_form("value_editor", method="POST")
        title = self._valuespec.title()
        assert isinstance(title, str)
        forms.header(title)
        if not active_config.wato_hide_varnames:
            forms.section(_("Configuration variable:"))
            html.tt(self._varname)

        forms.section(_("Current setting"))
        self._valuespec.render_input("ve", value)
        self._valuespec.set_focus("ve")
        html.help(self._valuespec.help())

        if is_configured_globally:
            self._show_global_setting()

        forms.section(_("Factory setting"))
        html.write_text(self._valuespec.value_to_html(defvalue))

        forms.section(_("Current state"))
        if is_configured_globally:
            html.write_text(
                _('This variable is configured in <a href="%s">global settings</a>.'
                  ) %
                ("wato.py?mode=edit_configvar&varname=%s" % self._varname))
        elif not is_configured:
            html.write_text(_("This variable is at factory settings."))
        else:
            curvalue = self._current_settings[self._varname]
            if is_configured_globally and curvalue == self._global_settings[
                    self._varname]:
                html.write_text(
                    _("Site setting and global setting are identical."))
            elif curvalue == defvalue:
                html.write_text(
                    _("Your setting and factory settings are identical."))
            else:
                html.write_text(self._valuespec.value_to_html(curvalue))

        forms.end()
        html.hidden_fields()
        html.end_form()
Exemplo n.º 5
0
    def _get_effective_global_setting(self, varname: str) -> Any:
        global_settings = load_configuration_settings()
        default_values = ABCConfigDomain.get_all_default_globals()

        if cmk.gui.config.is_wato_slave_site():
            current_settings = load_configuration_settings(site_specific=True)
        else:
            sites = SiteManagementFactory.factory().load_sites()
            current_settings = sites[config.omd_site()].get("globals", {})

        if varname in current_settings:
            return current_settings[varname]
        if varname in global_settings:
            return global_settings[varname]
        return default_values[varname]
Exemplo n.º 6
0
def get_effective_global_setting(site_id: SiteId, is_wato_slave_site: bool, varname: str) -> Any:
    global_settings = load_configuration_settings()
    default_values = ABCConfigDomain.get_all_default_globals()

    if is_wato_slave_site:
        current_settings = load_configuration_settings(site_specific=True)
    else:
        sites = SiteManagementFactory.factory().load_sites()
        current_settings = sites.get(site_id, {}).get("globals", {})

    if varname in current_settings:
        return current_settings[varname]

    if varname in global_settings:
        return global_settings[varname]

    return default_values[varname]
Exemplo n.º 7
0
    def execute(self) -> Iterator[ACResult]:
        local_connection = LocalConnection()
        row = local_connection.query_row(
            "GET status\nColumns: helper_usage_checker average_latency_fetcher\n"
        )

        checker_usage_perc = 100 * row[0]
        fetcher_latency = row[1]

        usage_warn, usage_crit = 85, 95
        if checker_usage_perc >= usage_crit:
            cls: Type[ACResult] = ACResultCRIT
        elif checker_usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK

        yield cls(
            _(
                "The current checker usage is %.2f%%. "
                "The checks have an average check latency of %.3fs."
            )
            % (checker_usage_perc, fetcher_latency)
        )

        # Only report this as warning in case the user increased the default helper configuration
        default_values = ABCConfigDomain.get_all_default_globals()
        if (
            self._get_effective_global_setting("cmc_checker_helpers")
            > default_values["cmc_checker_helpers"]
            and checker_usage_perc < 50
        ):
            yield ACResultWARN(
                _(
                    "The checker usage is below 50%, you may decrease the number of "
                    "checkers to reduce the memory consumption."
                )
            )