Downtime per API

Hallo zusammen,

wir haben bei uns eine CheckMK 2.3.0p30 CEE im Einsatz und ein Linux Kollege von mir würde gerne seinen Ihm zugewiesenen Hosts per API in die Downtime setzen können.

Was für Rechte muss ich seinem oder einem dedizierten Benutzer zuweisen und wie kann Er das am besten umsetzen.

MfG Paul

Entschuldigung fur kein Deutsch.

Check https://[server]/[site]/check_mk/api/1.0/ui/ on your server.
It has interactive examples to test things.

For an other example: I used it to create recurring downtime for RAW some years ago with the use of bash and cron.

Ich habe dafür eine “downtime-only” Rolle angelegt, um von Hosts beim Neustart automatisiert Downtimes zu setzen. Diese Rolle hat folgende Rechte:

  • See all host and services
  • Set/remove downtimes

Unter der URL, die Yggy gepostet hat, findet man auch den API-Endpunkt:

https://[cmk.domain]/[site]/check_mk/api/1.0/ui/#/Downtimes/cmk.gui.openapi.endpoints.downtime.create_host_related_downtime

Dort ist nur die “Set/remove downtimes” Permission gelistet:

Ich habe ein Bash-Skript, was per systemd beim Herunterfahren ausgeführt wird. Das sieht wie folgt aus:

#!/bin/bash
#
# this script sets a fixed downtime from now for the next 10 minutes
# it is being called by a systemd service when the server shuts down
#
# requires an automation user with a role that has these two perms:
# - "See all host and services"
# - "Set/Remove downtimes"
#####################################################################
API_URL="https://checkmk.domain.tld/sitename/check_mk/api/1.0"
USERNAME="bot_downtime"
PASSWORD="sesam_oeffne_dich"
#####################################################################
START_TIME=$(date -uIs | sed -E 's#\+..:..$#Z#')
END_TIME=$(date -uIs --date="now +10 minutes" | sed -E 's#\+..:..$#Z#')
HOST_NAME=$(hostname -s)
curl \
  --request POST \
  --header "Authorization: Bearer $USERNAME $PASSWORD" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  -s \
  --data '{
          "comment": "Automatic Reboot Downtime",
          "downtime_type": "host",
          "duration": 10,
          "recur": "hour",
          "end_time": "'$END_TIME'",
          "host_name": "'$HOST_NAME'",
          "start_time": "'$START_TIME'"
        }' \
  "$API_URL/domain-types/downtime/collections/host"

Wenn ich mich recht erinnere, muss man aus Gründen auch bei angegebener “duration” noch eine Endzeit setzen. Auch ohne recur funktionierte es glaube ich nicht, sonst hätte ich es rausgenommen, zumal es ja an der Stelle recht verwirrend ist, da es sich nicht um eine wiederkehrende Downtime handelt.

1 Like

When you don’t want recur, or with raw you can’t use it, you can set the value to fixed.
I set duration to 0, but I explicitly use end_time.

Otherwise your script looks pretty much the same as mine that I linked. Although not sure what the sed -E 's#\+..:..$#Z#' part does with your date time strings.

Hallo

ist es eher zu empfehlen ein Benutzer separat dazu erstellen der mit Benutzername/Kennwort oder ein “Automatisierungspasswort für Maschinenkonten” zu nehmen. Das Konto sollte auch nur das Recht zum setzen der Downtime auf bestimmte Hosts erhalten (Steuerung erfolgt bei uns über Kontaktgruppen).
Wo kann ich dann die beiden von dir genannten Rechte setzen?

MfG Paul

Setup > Users > Roles & permissions > Edit role [username]

General Permissions > See all host and services
Commands on host and services > Set/Remove downtimes