Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

All examples on this page are based on cURL because most Python programmers can easily transfer that to a requests call. The other way around, it's more difficultcomplicated.

Hosts

Showing all Attributes of a Host

...

Code Block
languagebash
themeRDark
titleComplex Query to set a host downtime
HOST_NAME="localhost"
PROTOCOL="https"
USERNAME="automation"
SITE_NAME="klapplg"
QUERY_HOST="klappedieerste"
PASSWORD="********"
API_URL="$PROTOCOL://$HOST_NAME/$SITE_NAME/check_mk/api/1.0"

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 '{"comment": "Schedule downtime on host which are in two groups",
             "downtime_type": "host_by_query",
             "duration": 0,
             "end_time": "2022-05-03T13:18:40Z",
             "recur": "fixed",
             "start_time": "2022-05-03T11:48:40Z",
             "query": {"op": "and", "expr":[{"op": ">=", "left": "groups", "right": "hostgroupA"}, {"op": ">=", "left": "groups", "right": "hostgroupB"}]}}' \
    "$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}')
echo "$resp" | jq
if [[ $code -lt 400 ]]; then     echo "OK"; else     echo "Request error"; fi

Restrictions

  1. Currently, itIt's not possible impossible to restrict the output to a single column, ; you have to must request at least two columns.
  2. It's not possible impossible to query data from columns of the type "blob", like "mk_inventory".