Downtime of host with REST-API does not work

CMK version: 2.0.0p20
OS version: Centos 7

Error message: Downtime not set

If I set the downtime with this script, the status of the host says
Host in downtime no
but in the view downtimes of the host it says

Can somebody please help me?

#!/bin/bash

HOST_NAME="CHECKMKSERVER"
SITE_NAME="test"
API_URL="https://$HOST_NAME/$SITE_NAME/check_mk/api/1.0"

USERNAME="USERNAME"
PASSWORD="PASSWORD"

out=$(
  curl --insecure -v\
    --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 '{
          "comment": "Test-Downtime",
          "downtime_type": "host",
          "duration": 3600,
          "end_time": "2022-05-03T12:00:00Z",
          "host_name": "azubi-test1.interhyp-linuxdmz.de",
          "recur": "fixed",
          "start_time": "2022-05-01T11:16:00Z"
        }' \
    "$API_URL/domain-types/downtime/collections/host")

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

The output is

} [data not shown]
* upload completely sent off: 292 out of 292 bytes
< HTTP/1.1 204 NO CONTENT
< Date: Mon, 02 May 2022 12:20:24 GMT
< Server: Apache
< Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' ssh: rdp:; img-src 'self' data: https://*.tile.openstreetmap.org/ ; connect-src 'self' https://crash.checkmk.com/ https://license.checkmk.com/api/upload ; frame-ancestors 'self' ; base-uri 'self'; form-action 'self' javascript: 'unsafe-inline'; object-src 'self'; worker-src 'self' blob:
< X-Content-Type-Options: nosniff
< ETag: "da39a3ee5e6b4b0d3255bfef95601890afd80709"
< Content-Type: None
< 
100   292    0     0  100   292      0    652 --:--:-- --:--:-- --:--:--   653
* Connection #0 to host demucvm-checkmk-test1.interhyp-infralinuxdmz.de left intact
OK

The only “problem” i see is that you set a flexible downtime. This means the downtime really starts if the host goes down. If you downtime is longer than 1 hour in your defined time frame than you get an alarm.

The description for the duration from the API documentation is also clear here.

duration	integer($int32)
default: 0
example: 3600
Duration in seconds. When set, the downtime does not begin automatically at a nominated time, but when a real problem status appears for the host. Consequencely, the start_time/end_time is only the time window in which the scheduled downtime can begin.
1 Like

I do not understand where the flexible downtime comes from. In the script I use “recur”: “fixed”. And I do not see the downtime in the [Status of Host] and there is no Downtime icon.

It is a flexible downtime as you set a duration. You don’t need to set a duration if you give a start and end time.

Thank you, that was my problem.

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.