Downtime on multiple hosts via url or REST API

Hi,

I am looking for a way to set downtime on a list of hosts via ansible.
I did some web search and only found how to set downtime on a single host using an url like
{Checkmk_base}/check_mk/view.php?_do_confirm=yes&transit=-1&view_name=hoststatus&site=&output_format=JSON&_username={uname}&_secret={passwd}&host={hostn}&_down_from_now=From+now+for&_down_minutes=10&_down_comment=test

I feel it’s a bit much calling this URL for every single host in the list. Is there a way to form an url that handles multiple hosts at once like with the host_regex parameter instead of just “host”? Or is there a way to do this with a single REST API call?

Cheers

You could define a Hostgroup/Servicegroup and then set the Downtime on this Group.

Why? It’s automation. You do not have to do the calls manually.

Because if you have 50 Servers/Services and the Script has to make 50 individual API calls and each call needs 0.5s, then that is very slow and inefficient :wink:

it would be much easier and faster if you could pass a list of hosts/services in one API call.

I was afraid that’s the only option. Since the host list is dynamically created, that’s at least inconvenient.

You already named the reason why I prefer a single API call, but if there’s really no other way I think making one call per host is what I’d prefer here.

So far we had no group that could not be predefined. But if the groups are only known at runtime and cannot be meaningfully predefined, such as “all Linux servers at location x” or "all servers with tag/label me2, then you probably have no other choice than to call the API for each host individually (You could parallelise the API calls to a certain extent).

Please keep in mind that the Web API no longer exists as of 2.2. With the host_by_query option in the REST-API it should be possible to pass an adhoc group of hosts:

A query expression of the Livestatus ‘hosts’ table in nested dictionary form. If you want to use multiple expressions, nest them with the AND/OR operators.

query={"op": "or", "expr": [{"op": "=", "left": "host_name", "right": "host1"}, {"op": "=", "left": "host_name", "right": "host2"}]}

Please don’t share that with our Ansible team, they own 10.000 hosts in Checkmk… I don’t want 10.000 calls to our master server

ansible?

maybe this fits your needs?

Well, if we are already using the REST API, why don’t we dynamically create the hostgroup from the list of hosts as well? The API has the necessary endpoints.

So

  • Step 1: Create host group from list of hosts
  • Step 2: Set the host group into downtime

Should work, shouldn’t it?