Add host API chokes on any folder value other than "/"

I’m using the instructions here to create hosts in CheckMK Enterprise edition. Configuration via the Checkmk REST API

If I use any value other than “/” then I get the following error.
{
“title”: “Bad Request”,
“status”: 400,
“detail”: “These fields have problems: folder”,
“fields”: {
“folder”: [
“‘Windows/other’ does not match pattern ‘(?:(?:[~\\\\\\/]|(?:[~\\\\\\/][-_ a-zA-Z0-9.]+)+[~\\\\\\/]?)|[0-9a-fA-F]{32})’.”
]
}
}

Is it possible to include a folder that is not the root folder?

What happens if you use “/Windows/other/”?
The regex should match this value.

2 Likes

here a little working sample. Testet with 2.1.0p21:

import json
import requests

_api_url = f'https://your.cmk.host:443/your_site/check_mk/api/1.0'
_base_header = {
    'Authorization': f'Bearer your_automation_user your_automation_secret',
    'Accept': 'application/json',
    'Content-Type': 'application/json',
}

url = f'{_api_url}/domain-types/host_config/collections/all'

data = {
    'folder': '/subfolder1/subfolder2',
    'host_name': 'your_new_host',
}

data = json.dumps(data)
response = requests.post(
    url=url,
    headers=_base_header,
    data=data,
)

I get this error–

{
“title”: “Bad Request”,
“status”: 400,
“detail”: “These fields have problems: folder”,
“fields”: {
“folder”: [
“The folder ‘/Windows’ could not be found.”
]
}
}

This is the code I’m trying to use–

#!/bin/bash

HOST_NAME=“mycheckmkserver.mtnam.org
SITE_NAME=“mysite”
API_URL=“https://$HOST_NAME/$SITE_NAME/check_mk/api/1.0”

USERNAME=“automation”
PASSWORD=“mysecret”

out=$(
curl
–insecure
–request POST
–write-out “\nxxx-status_code=%{http_code}\n”
–header “Authorization: Bearer $USERNAME $PASSWORD”
–header “Accept: application/json”
–header “Content-Type: application/json”
–data ‘{
“attributes”: {
“ipaddress”: “10.10.1.2”
},
“folder”: “/Windows”,
“host_name”: “agentserver.mtnam.org
}’
“$API_URL/domain-types/host_config/collections/all”)

resp=$( echo “${out}” | grep -v “xxx-status_code” )
code=$( echo “${out}” | awk -F"=" ‘/^xxx-status_code/ {print $2}’)
echo “$resp” | jq

if [[ $code -lt 400 ]]; then
echo “OK”
exit 0
else
echo “Request error”
exit 1
fi

Could it be that the automation user doesn’t have access to that folder? Maybe I have that configuration wrong?

Sorry in my example i had a wrong capital W.
All the folder names are only in lower case.
The names are the same as inside the filesystem you see it.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.