[BUG] Create host using REST API with custom tags

Hi all

Here is my understanding thus far:

_must_be_in_contactgroups (lien 2715) is used to determine whether the current (API) user has permission to edit the host (i.e.: they are in the correct contact groups, if any).

The actual issue stems from _get_cgconf_from_attributes (line 2133) which tries getting the key contactgroups from its parameter attributes. The latter seems to be None for some reason.

The attributes themselves are given to the function verify_host_details by cmk.gui.plugins.openapi.endpoints.host_config.create_host by extracting them from the POST data body["attributes"].

Now for the body: This gets parsed in cmk.gui.plugins.openapi.restful_objects.decorators.Endpoint.wrap_with_validation by calling request_schema().load(json_data) (around line 517).

The request_schema is set in the Endpoint decorator of create_host and resolves to cmk.gui.plugins.openapi.restful_objects.request_schemas.CreateHost (this class inherits from marshmallow.Schema).

The relevant part of this schema would probably be the line attributes = fields.attributes_fields..., which resolves to cmk.gui.fields.definitions.attributes_field. This returns an object of type Nested, if I am not mistaken.

This is about where my reverse engineering ends, though. Currently, I am at a loss what happens inside the returnal of this Nested object…
Maybe someone else is better able to assist.

1 Like