Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Import Macro Repair

...

Code Block
languagejs
themeRDark
  "domainType": "host_config",
  "id": "klappedieerste",
  "title": "klappedieerste",
  "members": {},
  "extensions": {
    "folder": "",
    "attributes": {
      "ipaddress": "127.0.0.1",
      "snmp_community": {
        "type": "v1_v2_community",
        "community": "publicenemy"
      },
      "labels": {
        "_mpac_spool_new": "/var/spool/mpac/remote/messages/new"
      },
      "meta_data": {
        "created_at": "2021-01-06T07:15:17+00:00",
        "updated_at": "2022-03-31T10:14:32.969304+00:00",
        "created_by": "cmkadmin"
      },
      "tag_criticality": "prod",
      "tag_action_ssh": "action_ssh",
      "tag_agent": "all-agents",
      "tag_snmp_ds": "snmp-v2"
    },
    "effective_attributes": null,
    "is_cluster": false,
    "is_offline": false,
    "cluster_nodes": null
  }

Restrictions

Custom attributes of a host are currently only visible when setting "effective_attributes=true".

Services

Showing a particular service

...

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

  • It's impossible to restrict the output to a single column; you must request at least two columns.
  • It's impossible to query data from columns of the type "blob", like "mk_inventory".

Related articles

Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ( "kb-how-to-article" , "howto" ) and type = "page" and space = "KB"
labelskb-how-to-article

...