Пример #1
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]
Пример #2
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]
Пример #3
0
def find_usages_of_contact_group(name):
    """Check if a group is currently in use and cannot be deleted
    Returns a list of occurrances.
    """
    global_config = load_configuration_settings()

    used_in = _find_usages_of_group_in_rules(name, ['host_contactgroups', 'service_contactgroups'])
    used_in += _find_usages_of_contact_group_in_users(name)
    used_in += _find_usages_of_contact_group_in_default_user_profile(name, global_config)
    used_in += _find_usages_of_contact_group_in_mkeventd_notify_contactgroup(name, global_config)
    used_in += _find_usages_of_contact_group_in_hosts_and_folders(name, Folder.root_folder())

    return used_in
Пример #4
0
def find_usages_of_contact_group(name: GroupName) -> List[Tuple[str, str]]:
    """Check if a group is currently in use and cannot be deleted
    Returns a list of occurrances.
    """
    global_config = load_configuration_settings()

    used_in = _find_usages_of_group_in_rules(name, ["host_contactgroups", "service_contactgroups"])
    used_in += _find_usages_of_contact_group_in_users(name)
    used_in += _find_usages_of_contact_group_in_default_user_profile(name, global_config)
    used_in += _find_usages_of_contact_group_in_mkeventd_notify_contactgroup(name, global_config)
    used_in += _find_usages_of_contact_group_in_hosts_and_folders(name, Folder.root_folder())
    used_in += _find_usages_of_contact_group_in_notification_rules(name)
    used_in += _find_usages_of_contact_group_in_dashboards(name)

    return used_in
Пример #5
0
    def _from_vars(self):
        self._varname = request.get_ascii_input_mandatory("varname")
        try:
            self._config_variable = config_variable_registry[self._varname]()
            self._valuespec = self._config_variable.valuespec()
        except KeyError:
            raise MKUserError(
                "varname",
                _('The global setting "%s" does not exist.') % self._varname)

        if not self._may_edit_configvar(self._varname):
            raise MKAuthException(
                _("You are not permitted to edit this global setting."))

        self._current_settings = load_configuration_settings()
        self._global_settings = {}
Пример #6
0
def find_usages_of_contact_group(name):
    # Part 1: Rules
    used_in = _find_usages_of_group_in_rules(
        name, ['host_contactgroups', 'service_contactgroups'])

    # Is the contactgroup assigned to a user?
    users = userdb.load_users()
    entries = users.items()
    for userid, user in sorted(entries, key=lambda x: x[1].get("alias", x[0])):
        cgs = user.get("contactgroups", [])
        if name in cgs:
            used_in.append(('%s: %s' % (_('User'), user.get('alias', userid)),
                            folder_preserving_link([('mode', 'edit_user'),
                                                    ('edit', userid)])))

    global_config = load_configuration_settings()

    # Used in default_user_profile?
    config_variable = config_variable_registry['default_user_profile']()
    domain = config_variable.domain()
    configured = global_config.get('default_user_profile', {})
    default_value = domain().default_globals()["default_user_profile"]
    if (configured and name in configured['contactgroups']) \
       or name in  default_value['contactgroups']:
        used_in.append(
            ('%s' % (_('Default User Profile')),
             folder_preserving_link([('mode', 'edit_configvar'),
                                     ('varname', 'default_user_profile')])))

    # Is the contactgroup used in mkeventd notify (if available)?
    if 'mkeventd_notify_contactgroup' in config_variable_registry:
        config_variable = config_variable_registry[
            'mkeventd_notify_contactgroup']()
        domain = config_variable.domain()
        configured = global_config.get('mkeventd_notify_contactgroup')
        default_value = domain().default_globals(
        )["mkeventd_notify_contactgroup"]
        if (configured and name == configured) \
           or name == default_value:
            used_in.append(('%s' % (config_variable.valuespec().title()),
                            folder_preserving_link([
                                ('mode', 'edit_configvar'),
                                ('varname', 'mkeventd_notify_contactgroup')
                            ])))

    return used_in
Пример #7
0
def _validate_user_attributes(all_users, user_id, user_attrs, is_new_user=True):
    # Check user_id
    if is_new_user:
        if user_id in all_users:
            raise MKUserError("user_id", _("This username is already being used by another user."))
        vs_user_id = UserID(allow_empty=False)
        vs_user_id.validate_value(user_id, "user_id")
    else:
        if user_id not in all_users:
            raise MKUserError(None, _("The user you are trying to edit does not exist."))

    # Full name
    alias = user_attrs.get("alias")
    if not alias:
        raise MKUserError("alias",
                          _("Please specify a full name or descriptive alias for the user."))

    # Locking
    locked = user_attrs.get("locked")
    if user_id == config.user.id and locked:
        raise MKUserError("locked", _("You cannot lock your own account!"))

    # Authentication: Password or Secret
    if "automation_secret" in user_attrs:
        secret = user_attrs["automation_secret"]
        if len(secret) < 10:
            raise MKUserError('secret',
                              _("Please specify a secret of at least 10 characters length."))
    else:
        password = user_attrs.get("password")
        if password:
            verify_password_policy(password)

    # Email
    email = user_attrs.get("email")
    vs_email = EmailAddressUnicode()
    vs_email.validate_value(email, "email")

    # Idle timeout
    idle_timeout = user_attrs.get("idle_timeout")
    vs_user_idle_timeout = get_vs_user_idle_timeout()
    vs_user_idle_timeout.validate_value(idle_timeout, "idle_timeout")

    # Notification settings are only active if we do *not* have rule based notifications!
    rulebased_notifications = load_configuration_settings().get("enable_rulebased_notifications")
    if not rulebased_notifications:
        # Notifications
        notifications_enabled = user_attrs.get("notification_enabled")

        # Check if user can receive notifications
        if notifications_enabled:
            if not email:
                raise MKUserError(
                    "email",
                    _('You have enabled the notifications but missed to configure a '
                      'Email address. You need to configure your mail address in order '
                      'to be able to receive emails.'))

            contactgroups = user_attrs.get("contactgroups")
            if not contactgroups:
                raise MKUserError(
                    "notifications_enabled",
                    _('You have enabled the notifications but missed to make the '
                      'user member of at least one contact group. You need to make '
                      'the user member of a contact group which has hosts assigned '
                      'in order to be able to receive emails.'))

            roles = user_attrs.get("roles")
            if not roles:
                raise MKUserError("role_user",
                                  _("Your user has no roles. Please assign at least one role."))

        notification_method = user_attrs.get("notification_method")
        get_vs_flexible_notifications().validate_value(notification_method, "notification_method")
    else:
        fallback_contact = user_attrs.get("fallback_contact")
        if fallback_contact and not email:
            raise MKUserError(
                "email",
                _("You have enabled the fallback notifications but missed to configure an "
                  "email address. You need to configure your mail address in order "
                  "to be able to receive fallback notifications."))

    # Custom user attributes
    for name, attr in userdb.get_user_attributes():
        value = user_attrs.get(name)
        attr.valuespec().validate_value(value, "ua_" + name)
Пример #8
0
 def __init__(self) -> None:
     super().__init__()
     self._current_settings = load_configuration_settings()