REST api fetch service status, missing details/summary

Hi,
I need to fetch from checkmk the status of a service via API, I need the service status if ok / warn / critical but also the detail that I can see from “summary” and “details” fields on web interface.

tried this:

curl -X 'GET' \
  'https://$HOST/$SITE/check_mk/api/1.0/objects/host/$HOSTNAME/actions/show_service/invoke?service_description=$SERVICENAME' \
  -H 'accept: application/json' \
  -H 'Authorization: Basic $AUTHTOKEN'

but the result is

{
  "links": [
    {
      "domainType": "link",
      "rel": "self",
      "href": "https://XXXX/XXXX/check_mk/api/1.0/objects/service/XXX-XXXX",
      "method": "GET",
      "type": "application/json"
    }
  ],
  "domainType": "service",
  "id": "XXX-XXX",
  "title": "Service XXXX",
  "members": {},
  "extensions": {
    "description": "XXX",
    "host_name": "XXX",
    "state_type": 1,
    "state": 0,
    "last_check": 1678873268
  }
}

and the summary and details are missing…

How can I perform a REST api request to fetch also theese fields?

thanks

Matteo

“Show the monitored service of a host” doesn’t have the query parameter “Columns” . So, its not possible to show the summary of the service check using this endpoint.

However, you could use the “Show the monitored services of a host” has a columns parameter in order to get the required information.

1 Like

Hi! do you mean “/domain-types/service/collections/all” “Show all monitored services” REST API?

Ok I found the field “perf_data” that contains the text message of the check result.

Now I have an issue with the filtering via the “query” parameter.

Example using {“op”: “!=”, “left”: “state”, “right”: “1”}
the api reponse is:

{
“title”: “Bad Request”,
“status”: 400,
“detail”: “These fields have problems: op, right, left”,
“fields”: {
“op”: [
“Unknown field.”
],
“right”: [
“Unknown field.”
],
“left”: [
“Unknown field.”
]
}
}

without query it works fine.

I tried to type the query in other forms but always I catch that error… does someone have an idea?

thanks

Matteo

Ok! there are some issues with the swagger interface…tried manually and it works fine:

curl -G \
  --header "Accept: */*" \
  -H 'Authorization: Bearer automation XXXx' \
  --data-urlencode 'columns=host_name' \
  --data-urlencode 'columns=description' \
  --data-urlencode 'columns=perf_data' \
  --data-urlencode 'query={"op": "and", "expr":[{"op": "=", "left": "host_name", "right": "XXXX"}, {"op": "=", "left": "description", "right": "XXXX"}, { "op": "!=", "left": "state", "right": "1" }]}' \
  'https://XXXX/check_mk/api/1.0/domain-types/service/collections/all'

in this test I’m filtering with the query:

  • service XXX of host XXX in critical state
  • fetch the fields host_name, description, perf_data

wonderful! thanks!!

Matteo

1 Like

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.