Beispiel #1
0
    BAKE_AGENT_PARAM_NAME:
    fields.Boolean(
        load_default=False,
        required=False,
        example=False,
        description=
        ("Tries to bake the agents for the just created hosts. This process is started in the "
         "background after configuring the host. Please note that the backing may take some "
         "time and might block subsequent API calls. "
         "This only works when using the Enterprise Editions."),
    )
}

PERMISSIONS = permissions.AllPerm([
    permissions.Perm("wato.manage_hosts"),
    permissions.Optional(permissions.Perm("wato.all_folders")),
])


@Endpoint(
    constructors.collection_href("host_config"),
    "cmk/create",
    method="post",
    etag="output",
    request_schema=request_schemas.CreateHost,
    response_schema=response_schemas.HostConfigSchema,
    query_params=[BAKE_AGENT_PARAM],
    permissions_required=PERMISSIONS,
)
def create_host(params):
    """Create a host"""
Beispiel #2
0
    path_params=[{
        "host_name":
        gui_fields.HostField(
            description="The host of the service which shall be updated.",
            example="example.com",
        ),
    }],
    status_descriptions={
        404: "Host could not be found",
    },
    request_schema=UpdateDiscoveryPhase,
    permissions_required=permissions.AnyPerm([
        permissions.Optional(
            permissions.AnyPerm([
                permissions.Perm("wato.service_discovery_to_monitored"),
                permissions.Perm("wato.service_discovery_to_ignored"),
                permissions.Perm("wato.service_discovery_to_undecided"),
                permissions.Perm("wato.service_discovery_to_removed"),
            ])),
    ]),
)
def update_service_phase(params) -> Response:
    """Update the phase of a service"""
    body = params["body"]
    host = Host.load_host(params["host_name"])
    target_phase = body["target_phase"]
    check_type = body["check_type"]
    service_item = body["service_item"]
    _update_single_service_phase(
        SERVICE_DISCOVERY_PHASES[target_phase],
        host,
Beispiel #3
0
    is_builtin,
    load_tag_config,
    load_tag_group,
    OperationRemoveTagGroup,
    RepairError,
    save_tag_group,
    tag_group_exists,
    TagCleanupMode,
    update_tag_config,
)

from cmk import fields

PERMISSIONS = permissions.AllPerm([
    permissions.Perm("wato.hosttags"),
    permissions.Optional(permissions.Perm("wato.all_folders")),
])

RW_PERMISSIONS = permissions.AllPerm([
    permissions.Perm("wato.edit"),
    permissions.Perm("wato.hosttags"),
    permissions.Optional(permissions.Perm("wato.all_folders")),
])


class HostTagGroupName(fields.String):
    """A field representing the host tag group"""

    default_error_messages = {
        "should_exist": "Host tag group missing: {name!r}",
    }
Beispiel #4
0
         "'Wait for completion' endpoint."),
        401: ("The API user may not activate another users changes, "
              "or the user may and activation was not forced explicitly."),
        409:
        "Some sites could not be activated.",
        422:
        "There are no changes to be activated.",
        423:
        "There is already an activation running.",
    },
    additional_status_codes=[302, 401, 409, 422, 423],
    request_schema=request_schemas.ActivateChanges,
    response_schema=response_schemas.DomainObject,
    permissions_required=permissions.AllPerm([
        permissions.Perm("wato.activate"),
        permissions.Optional(permissions.Perm("wato.activateforeign")),
        RO_PERMISSIONS,  # to make perm system happy
    ]),
)
def activate_changes(params):
    """Activate pending changes"""
    user.need_permission("wato.activate")
    body = params["body"]
    sites = body["sites"]
    with may_fail(MKUserError), may_fail(MKAuthException, status=401):
        activation_id = activate_changes_start(
            sites, force_foreign_changes=body["force_foreign_changes"])

    if body["redirect"]:
        wait_for = _completion_link(activation_id)
        response = Response(status=302)
Beispiel #5
0
    response_schemas,
)
from cmk.gui.plugins.openapi.restful_objects.parameters import NAME_FIELD
from cmk.gui.plugins.openapi.utils import problem
from cmk.gui.watolib.passwords import (
    load_password,
    load_password_to_modify,
    load_passwords,
    Password,
    remove_password,
    save_password,
)

PERMISSIONS = permissions.AllPerm([
    permissions.Perm("wato.passwords"),
    permissions.Optional(permissions.Perm("wato.edit_all_passwords")),
])

RW_PERMISSIONS = permissions.AllPerm([
    permissions.Perm("wato.edit"),
    permissions.Perm("wato.passwords"),
    permissions.Optional(permissions.Perm("wato.edit_all_passwords")),
])


@Endpoint(
    constructors.collection_href("password"),
    "cmk/create",
    method="post",
    request_schema=request_schemas.InputPassword,
    etag="output",
Beispiel #6
0
            serialize_user(user_id, complement_customer(user_attributes)))

    return constructors.serve_json(
        constructors.collection_object(domain_type="user_config", value=users))


@Endpoint(
    constructors.collection_href("user_config"),
    "cmk/create",
    method="post",
    etag="output",
    request_schema=request_schemas.CreateUser,
    response_schema=response_schemas.UserObject,
    permissions_required=permissions.AllPerm([
        *RW_PERMISSIONS.perms,
        permissions.Optional(permissions.Perm("wato.groups")),
    ]),
)
def create_user(params):
    """Create a user"""
    api_attrs = params["body"]
    username = api_attrs["username"]

    # The interface options must be set for a new user but we restrict the setting through the API
    internal_attrs: Dict[str, Any] = {
        "start_url": None,
        "force_authuser": False,
    }

    internal_attrs = _api_to_internal_format(internal_attrs,
                                             api_attrs,