Why is remove-downtime so insane?

I created a PowerShell script to scheduld downtime on a server plus it’s services for use with Cluster Aware Updating as a Pre-Updating script.
The next part would be the Post-Updating script which will remove the set downtimes.
However, for some insane reason you need to filter the host, the services linked to it and then loop over all the ID returned so remove them one by one.

Why is this so ridiculous? Scheduling a downtime is as easy as specifying the host in the Uri, and use “child_options = 2”. Why can’t the same be used for remove-downtime?

To give an idea of what I would like to achieve, and I think it should work but it doesn’t at the moment:

$hostname = ${env:COMPUTERNAME}.ToLower()

# Authentication
$user = "<username>"
$pass = "<password>"
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"

# Icinga stuff
$Uri = "https://icinga.example.net:5665/v1/actions/remove-downtime"
$headers = @{ "Authorization" = "$basicAuthValue"; "Accept" = "application/json" }
$body = @{
    type    = 'Downtime'
    filter  = 'host.name == filterHost && downtime.author == filterAuthor'
    filter_vars = @{
        filterhost      = "$hostname"
        filterAuthor    = '<username>'
    }
    pretty  = $true
}
$body = $body | ConvertTo-Json

# Ignore self signed certificates
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

# Schedule the downtime
Invoke-RestMethod -Headers $headers -Uri $Uri -Method Post -ContentType 'application/json' -Body $body

# Don't ignore self signed certificates anymore
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null

If I read the API page (https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#remove-downtime) on remove-downtime correctly, this should filter for the hostname and author, and remove all set downtime.
Except it throws a 404 Not Found at me. No clue why.

To clarify, in this case I do not care if multiple downtimes are set. There shouldn’t be in this case.

Hi,

calling something insane/ridiculous adds a bad tone on your question, and you might not get good answers. Keep that in mind when asking for help in our community, the FAQ holds some more hints for a nice and gentle conversation.

remove-downtime needs the previously generated downtime names/IDs or a provided filter. This specific filter must match - if there are no matches because of

  • wrong filter or not existing objects
  • missing permissions

then you’ll receive a 404. That leads to the question of a list of the downtimes, e.g. via GET from /v1/objects/downtimes. Also, the ApiUser object with basic auth should have permissions set, please share the configuration snippet.

Last but not least, please add the exact version of Icinga 2 where you’re targeting the API requests onto.

Cheers,
Michael