REST-API: Problem with service discovery

CMK version:

Checkmk Raw Edition 2.1.0

OS version:

Debian 10 and RockyLinux 8

Description:

I am trying to automate my hosts creation with the new REST API.
I copy paste the example that we can find on this link : Configuration via the Checkmk REST API
Everything works fine but when it comes to Service Discovery it didn’t work, I mean it doesn’t show me an error i have got a return code 200 but it did nothing.
I tried to do it with bash and python but the result is the same. Here an example of what i am trying to do:

#!/bin/bash
HOST_NAME="example.com"
SITE_NAME="cmk"
API_URL="https://$HOST_NAME/$SITE_NAME/check_mk/api/1.0"

USERNAME="automation"
PASSWORD="GdqssfqfzaadAO"

out=$(
  curl \
    --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 '{
          "mode": "refresh"
        }' \
    "$API_URL/objects/host/myhost/actions/discover_services/invoke")
echo $out
resp=$( echo "${out}" | grep -v "xxx-status_code" )
code=$( echo "${out}" | awk -F"=" '/^xxx-status_code/ {print $2}')

# For indentation, please install 'jq' (JSON query tool)
echo "$resp" | jq
# echo "$resp"

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

Here the result :

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   371  100   332  100    39    410     48 --:--:-- --:--:-- --:--:--   458
{"links": [{"domainType": "link", "rel": "self", "href": "https://example.com/cmk/check_mk/api/1.0/objects/service_discovery/myhost-services-wato", "method": "GET", "type": "application/json"}], "domainType": "service_discovery", "id": "myhost-services-wato", "title": "Services discovery", "members": {}, "extensions": {}} xxx-status_code=200
{
  "links": [
    {
      "domainType": "link",
      "rel": "self",
      "href": "https://example.com/cmk/check_mk/api/1.0/objects/service_discovery/myhost-services-wato",
      "method": "GET",
      "type": "application/json"
    }
  ],
  "domainType": "service_discovery",
  "id": "myhost-services-wato",
  "title": "Services discovery",
  "members": {},
  "extensions": {}
}
OK

I had to re-activate the legacy web API to do what i want but it is not a solution…
Thank you for your answer !

Regards

EDIT : with 2.0.X version it’s working not with 2.1.X version

1 Like

Hey, i have the same problem since i upgraded in 2.1.x but worked 2.0.x

Have you resolved this problem?