We need you: Evolution of the Downtime Module

Good people of the Checkmk forum! I call upon you once again with a query for aid:

Our very own @lars.getwan is currently refactoring the checkmk.general.downtime module and we want to make sure it lands well. This is where y’all come into play: Go ahead and take a look, or even better, try out the current state yourself. :hammer_and_wrench:

You can find the pull request over at GitHub.

If you want to try out the current development state in your lab or test environment, you can do so utilizing a requirements.yml file:

---
collections:
  - name: https://github.com/Checkmk/ansible-collection-checkmk.general.git
    type: git
    version: feature/module-downtime-rework

If you want to help, but do not know how, please do reach out in the thread.
Also, your feedback is valued both in the pull request directly and here in the thread, whichever you prefer. :handshake:

2 Likes

Hi Robin,
Hi Lars,

at the moment I write at some tools to make it easier to make a downtime at the hosts to set a towntime on a host when someone is working on it, for example now + 1h…
My Idea was to use a API-Proxy where a server mus be registered one time so i can execute two commands on a host base instead of a user base where a user have to logon with user/password every time. And so it would be perfect to excute the two api endpoints

/objects/host_config/ (to check if the host exists at Checkmk)

and

/domain-types/downtime/collections/host ( to set a downtime)

with the registration key for the bakery and here only for the registred hostname not all hosts.

also “berear ” as authentication.

In this case i canwrite a small tool (CLI for linux and GUI for windows) which can read the registration key (all users are administrative users) and set a downtime for the host and only for the host the user is allowed for!

The touls would append the logged in User in windows as user who execute the script and root on a linus host (all users are working as root because the linux hosts are all server and we have tu work as root…)

This feature can be switched on in the General settings.

This would make our life so much easier :wink:

Frank

Hi Frank,

typically, you would use an automation user to access the REST API from a monitored host. Why have you decided not to do that?
I also wouldn’t use Ansible and access the REST API directly in that case, as Ansible is rather useful if you manage your Checkmk environment from a control node.

Best regards
Lars

Hi Lars

We use an extended version of the Checkmk downtime script, but ultimately Ansible should be able to provide the similar core functionality:

  • Schedule downtimes for:
    • hosts or host groups
    • services or service groups
    • hosts/services filtered and/or by tags or labels
  • List:
    • all active downtimes
      • filtere and/or by host, service, host group, service group, comment, tag, label
    • all upcoming downtimes
      • filtere and/or by host, service, host group, service group, comment, tag, label
  • Remove:
    • specific downtimes
    • all downtimes for hosts or host groups
    • all downtimes for services or service groups
    • filtering by and/or comment, author, tag, or label
  • Default behaviour for downtime removal:
    • filter by author (ansible) to ensure downtimes created manually via the GUI remain untouched

Regards, Lars

Thank you, @FrankB and @LaSoe for sharing your thoughts! :folded_hands:

While we appreciate your insights, this thread primarily asked to look at and test the updated downtime module and provide feedback on it. If you cannot do that, that is perfectly fine, I just wanted to clarify our ask.

@LaSoe: I quickly went through your requirements and the downtime module already meets most of them out-of-the-box, while the “groups”-part can be done through queries or the Ansible inventory directly. Whatever is missing with the new version can of course be raised as a dedicated issue on GitHub, so we can put it into the backlog.

@robin.gierse
Thanks for taking a look. My comment was mainly intended as feedback based on real-world operational use cases, where usability, scalability, and especially execution time are key factors.

Two things stand out to me:

  1. How well does the module perform when adding, updating, or cancelling downtimes for 10,000 services at scale via Ansible, and how manageable is this in practice? It’s entirely possible that I may have overlooked or misunderstood something here.

  2. Another critical issue is that the module removes all downtimes by default, including those created by other users. In my opinion, this should be limited to the current user unless explicitly configured otherwise.

Why is this problematic? A user or another tool schedules a downtime for a specific reason. Later, an Ansible job periodically creates its own downtime and removes it again once the scheduled task ends. However, the module removes all downtimes, including the one created by the other user or tool. The same issue can occur with overlapping downtimes created by different tasks. This creates a risk of unintentionally triggering alerts even though a downtime had already been scheduled.

But those are just my two cents on this.

Nevertheless, keep up the great work; it’s very much appreciated.

1 Like

Well, Ansible is not the fastest tool by design and the Check REST API can drag it’s legs sometimes as well, so I do see you point. We have not stress tested any module in terms of performance. I would assume it gets the job done, but might take a while.

I think there migh be a misunderstanding there. The module always uses the comment to match downtimes, only if you omit it will you remove all downtimes. So by default no unmanaged downtimes should be touched and you can use the comment to control the scope of your actions. I do see the ask for filtering based on the current user, but I am not sure, if that provides too much value.

But we will consider your feedback and look into it. Thank you!

The performance problem is self-inflicted and has nothing to do with Ansible in the first place. There is a significant difference between making 10,000 API calls at 0.5 seconds each for 10,000 individual services or using insted a single call that completes in 5 seconds and processes all 10,000 services at once.

Fair point.

From my practical experience, it is better to use the user “Ansible” to control the main scope instead of relying on the comment “Managed by Ansible”. You achieve the same effect while making the solution far less error-prone and even more flexible :wink:

Using the query parameter, you can already create/update/delete a downtime on a host group. If the host group contains 10.000 hosts, it will do this in under 1s. :slight_smile:
I have now added an example for that to the module.

- name: "Schedule host downtimes for a host group using a query."
  checkmk.general.downtime:
    server_url: "https://myserver/"
    site: "mysite"
    api_user: "myuser"
    api_secret: "mysecret"
    query: '{"op": ">=", "left": "host_groups", "right": "my_hostgroup"}'
    downtime_type: "host"
    comment: "Maintenance for my_hostgroup"
    end_after:
      hours: 4
1 Like

Good to know there is a allways a workaround available :slightly_smiling_face:

Out of curiosity, is there a specific reason why the official API downtime types hostgroup and servicegroup are not supported directly? Supporting them natively would make the implementation much simpler and more intuitive.

I assume these options exist in the API for a reason :wink:

@LaSoe the reason is, that currently we want to land a first rewrite and see how it performs. We want to avoid creating too much code in the Collection, if there is a good solution (I would not even call it “workaround”) already available.

I understand, that there could be more convenience, but we want to focus on good and sturdy solutions. That does not mean that at some point someone will add the functionality you request. :slight_smile:

In my view, this mindset, which I believe is fairly common within Checkmk, can sometimes lead to solutions that are technically sound but not sufficiently grounded in real-world experience. The guiding principle should be to focus on well-designed, robust, and practical solutions.

Where there is already a clear and simple solution, I would suggest favoring the approach that is easiest for the people using it, rather than simply what is easiest to implement in code.

For example, the proposed hostgroup/servicegroup parameter would make this use case very straightforward:

- name: "Schedule host downtimes for a host group"
  checkmk.general.downtime:
    server_url: "https://myserver/"
    site: "mysite"
    api_user: "myuser"
    api_secret: "mysecret"
    hostgroup: "my_hostgroup"  # vs. query: '{"op": ">=", "left": "host_groups", "right": "my_hostgroup"}'
    downtime_type: "host"
    comment: "Maintenance for my_hostgroup"
    end_after:
      hours: 4

The difference is quite small from an implementation perspective, but significantly clearer for the user: hostgroup: "my_hostgroup" directly expresses the intent, while the query requires the user to understand how the underlying API query works.

That said, I still think this is a great project that will certainly make everyday life easier for many people.

I’ve done my best to contribute a small practical perspective, and I hope it helps shape the solution in the best possible way. :slightly_smiling_face:

2 Likes

@LaSoe we do very much appreciate your feedback and it is heard! :folded_hands:
While we cannot act on all of it (now,) we do our best to accomodate.

P.S.: Sometimes a simple missing feature is just an opportunity in disguise for new contributors. :slight_smile:

1 Like

Thanks for the not-so-subtle hint, but Ansible still isn’t really my area of expertise but never say never. . :slight_smile:

1 Like