GET host service_status via new REST-API

Hi all,

Is there a way of using the new REST-API to get the state of a service from a host?

e.g. I like to know if service Running Processes on host example.com is up/down or ok/critical?

The api docs mention under Service status to use /domain-types/service/collections/all but when running the below I get a list of services for this host but this does not include information about the state of the service.

curl -X GET "https:/example.com/production/check_mk/api/v1/domain-types/service/collections/all?host_name=example.com

If anyone could point me in the right direction please? Much appreciated.

Anyone has any idea? :slight_smile: Much appreciated!

Hi,
I think it’s not possible at the moment (2.0.0b7). You have to use a livestatus query for this. Have a look at the documentation:
https://docs.checkmk.com/latest/en/livestatus.html#_setting_a_simple_filter
https://docs.checkmk.com/latest/en/livestatus.html#combining

Karl

2 Likes

Thanks for your reply @kdeutsch . Appreciated!

Do you know to happen if this is a planned feature at some point? I can see this a pretty useful feature to connect other platforms to checkmk instances via webhooks. Thanks again for confirming.

Hi @flokuek,
I don’t know if there are future plans for this feature. I would appreciate it :slight_smile:

Karl

If you don’t like to use the livestatus you also could get this information of the view directly as json output for simple parsing.

https://example.com/<SITE>/check_mk/view.py?host=<HOST>&service=<SERVICE>&site=<SITE>&view_name=service&output_format=json

This should also work with an automation user and secret attached.

@kdeutsch: is this still working in 2.0? i haven’t an installation at the moment. can you please check this?

3 Likes

Hi @tosch,

this is still working in 2.0.

Karl

Thanks @tosch . That’s a really good alternative for now :slight_smile:

I noticed that the json output formats in a really weird way and not in key/value pairs…

[
 [
  "sitealias", 
  "host", 
  "service_description", 
  "service_labels", 
  "service_icons", 
  "service_state",
 ], 
 [
  "Test Monitoring", 
  "TESTHOST", 
  "PING", 
  "", 
  "themes/facelift/images/icon_menu themes/facelift/images/icon_pnp stale", 
  "OK", 
 ]
]

It’s prepared like a table. Understand the first line as table header and all following lines as data rows.

1 Like

Okay that makes sense. Got my automation working :slight_smile:
Thanks for your help! @tosch Appreciated!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.