How to use API/automation user to get service group status?

Hey guys,

I want to use the API and automation user to request specific service groups or host groups and I hope there is a way to get back the status of all group members.

I would expect to get some sort of json data, which I could use and parse on a different server.
I already tried something like:
curl "http://127.0.0.1/mysite/check_mk/view.py?optservice_group=myservicegroup&servicegroup=myservicegroup&view_name=servicegroup&_username=automation&_secret=SECRET"

As per documentation, there does not seem to be a special request command or action like ā€œget_servicegroupā€. So Iā€™m not sure how to use the webapi.py, which should look like:
curl "http://127.0.0.1/mysite/check_mk/webapi.py?action=get_host&_username=automation&_secret=SECRET&output_format=python" -d 'request={"hostname":"myhost"}'

Currently I am using another automation user to enable and disable custom downtimes for specific services and it works fine:
http://127.0.0.1/mysite/check_mk/view.py?host=HOSTNAME&service=SERVICENAME&site=mysite&view_name=service&_username=automation&_secret=SECRET&_do_confirm=yes&_transid=-1&_do_actions=yes&_down_comment=downtime-test&_down_from_now=From+now+for&_down_minutes=1&filled_in=actions

Could you give me a hint?

To get information about host and service groups you only need use the normal automation user and some views.
The WATO API can only be used to define some groups and rules to assign these groups.

Example
http://127.0.0.1/mysite/check_mk/view.py?filled_in=filter&opthost_group=test&search=Search&view_name=searchhost&output_format=json&_username=automation&_secret=SECRET

Output

[
 [
  "host_state", 
  "host", 
  "host_icons", 
  "num_services_ok", 
  "num_services_warn", 
  "num_services_unknown", 
  "num_services_crit", 
  "num_services_pending"
 ], 
 [
  "UP", 
  "Server1", 
  "themes/facelift/images/icon_menu", 
  "24", 
  "0", 
  "0", 
  "0", 
  "0"
 ]
]

You see it is good to create your own views to remove unneeded columns like ā€œhost_iconsā€.

1 Like

Many thanks Andreas, thatā€™s exactly what I needed!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.