예제 #1
0
    if _update_config_based_host_attributes_config_hash == _compute_config_hash(
    ):
        return  # No re-register needed :-)

    _clear_config_based_host_attributes()
    _declare_host_tag_attributes()
    declare_custom_host_attrs()

    from cmk.gui.watolib.hosts_and_folders import Folder  # pylint: disable=import-outside-toplevel
    Folder.invalidate_caches()

    _update_config_based_host_attributes_config_hash = _compute_config_hash()


# Make the config module initialize the host attributes after loading the config
config.register_post_config_load_hook(_update_config_based_host_attributes)


def _clear_config_based_host_attributes():
    for attr in host_attribute_registry.attributes():
        if attr.from_config():
            undeclare_host_attribute(attr.name())


def _declare_host_tag_attributes():
    for topic_spec, tag_groups in config.tags.get_tag_groups_by_topic():
        for tag_group in tag_groups:
            # Try to translate the title to a builtin topic ID. In case this is not possible mangle the given
            # custom topic to an internal ID and create the topic on demand.
            # TODO: We need to adapt the tag data structure to contain topic IDs
            topic_id = _transform_attribute_topic_title_to_id(topic_spec)
예제 #2
0
from cmk.gui import utils
from cmk.gui.config import register_post_config_load_hook
from cmk.gui.exceptions import MKGeneralException
from cmk.gui.globals import config, html
from cmk.gui.i18n import _
from cmk.gui.log import logger
from cmk.gui.utils.html import HTML
from cmk.gui.valuespec import ValueSpec
from cmk.gui.watolib.changes import add_change, make_diff_text, ObjectRef, ObjectRefType
from cmk.gui.watolib.hosts_and_folders import CREFolder, CREHost, Folder, Host
from cmk.gui.watolib.rulespecs import rulespec_group_registry, rulespec_registry
from cmk.gui.watolib.utils import ALL_HOSTS, ALL_SERVICES, has_agent_bakery, NEGATE

# Make the GUI config module reset the base config to always get the latest state of the config
register_post_config_load_hook(cmk.base.export.reset_config)

FolderPath = str
SearchOptions = Dict[str, Any]

# This macro is needed to make the to_config() methods be able to use native
# pprint/repr for the ruleset data structures. Have a look at
# to_config_with_folder_macro() for further information.
_FOLDER_PATH_MACRO = "%#%FOLDER_PATH%#%"


class RuleConditions:
    def __init__(
        self,
        host_folder: str,
        host_tags: Optional[TaggroupIDToTagCondition] = None,
예제 #3
0
    def registration_hook(self, plugin_class):
        ident = self.plugin_name(plugin_class)
        declare_permission("icons_and_actions.%s" % ident, ident,
                           _("Allow to see the icon %s in the host and service views") % ident,
                           config.builtin_role_ids)


icon_and_action_registry = IconRegistry()


def update_icons_from_configuration():
    _update_builtin_icons(config.builtin_icon_visibility)
    _register_custom_user_icons_and_actions(config.user_icons_and_actions)


config.register_post_config_load_hook(update_icons_from_configuration)


def _update_builtin_icons(builtin_icon_visibility):
    # Now apply the global settings customized options
    for icon_id, cfg in builtin_icon_visibility.items():
        icon = icon_and_action_registry.get(icon_id)
        if icon is None:
            continue

        if 'toplevel' in cfg:
            icon.override_toplevel(cfg['toplevel'])
        if 'sort_index' in cfg:
            icon.override_sort_index(cfg['sort_index'])

예제 #4
0
                ),
            ))
        return choices


pagetypes.declare(CustomSnapins)


def _register_custom_snapins():
    """First remove all previously registered custom snapins, then register
    the currently configured ones"""
    CustomSnapins.load()
    snapin_registry.register_custom_snapins(CustomSnapins.instances_sorted())


register_post_config_load_hook(_register_custom_snapins)

# .
#   .--Add Snapin----------------------------------------------------------.
#   |           _       _     _   ____                    _                |
#   |          / \   __| | __| | / ___| _ __   __ _ _ __ (_)_ __           |
#   |         / _ \ / _` |/ _` | \___ \| '_ \ / _` | '_ \| | '_ \          |
#   |        / ___ \ (_| | (_| |  ___) | | | | (_| | |_) | | | | |         |
#   |       /_/   \_\__,_|\__,_| |____/|_| |_|\__,_| .__/|_|_| |_|         |
#   |                                              |_|                     |
#   '----------------------------------------------------------------------'


@cmk.gui.pages.register("sidebar_add_snapin")
def page_add_snapin() -> None:
    if not user.may("general.configure_sidebar"):
예제 #5
0
파일: userdb.py 프로젝트: tboerger/checkmk
    loaded_with_language = cmk.gui.i18n.get_current_language()


# The saved configuration for user connections is a bit inconsistent, let's fix
# this here once and for all.
def _fix_user_connections() -> None:
    for cfg in config.user_connections:
        # Although our current configuration always seems to have a 'disabled'
        # entry, this might not have always been the case.
        cfg.setdefault('disabled', False)
        # Only migrated configurations have a 'type' entry, all others are
        # implictly LDAP connections.
        cfg.setdefault('type', 'ldap')


config.register_post_config_load_hook(_fix_user_connections)


# When at least one LDAP connection is defined and active a sync is possible
def sync_possible() -> bool:
    return any(connection.type() == "ldap"
               for _connection_id, connection in active_connections())


def locked_attributes(connection_id: Optional[str]) -> List[str]:
    """Returns a list of connection specific locked attributes"""
    return _get_attributes(connection_id, lambda c: c.locked_attributes())


def multisite_attributes(connection_id: Optional[str]) -> List[str]:
    """Returns a list of connection specific multisite attributes"""
예제 #6
0
def register():
    # Make the config module initialize the host attributes after loading the config
    register_post_config_load_hook(_update_config_based_host_attributes)