I've made a script that will set a scheduled downtime for a host and its triggered children in Icinga 2.
But when I run it I receive
Invoke-WebRequest : The remote server returned an error: (500) Internal Server Error.
At line:31 char:1
+ Invoke-WebRequest -Headers $headers -Uri "$Uri" -Method Post -Body $b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Even with debug logging enabled on the Icinga 2 server there is not much to go with.
The user logs in properly with the webserver and that's it. Nothing else.
I think the code is pretty OK, but perhaps I've missed something obvious making it not work.
To test it yourself, replace everything starting with "test-" to something in your environment.
Also, the first line has a comment about using the env:computername.
The idea of the script is to run it as a PreUpdateScript with Cluster Aware Updating to schedule downtime for the node when it it's turn to get updated.
A PostUpdateScript will need to be made that removes the downtime.
Further, this is just for the node, eventually I will add the iDRAC (in our case) and Spongebob (our canary VM because Canary and Dodo was already in use).
$hostname = "test-server" # ${env:COMPUTERNAME}.ToLower()
# Start and End time in epoch
$start_time = Get-Date -UFormat %s
$end_time = Get-Date (Get-Date).AddDays(1) -UFormat %s
# Authentication
$user = "test-user"
$pass = "test-password"
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
# Stuff to send to the webserver
$Uri = "https://icinga.network.net:5665/v1/actions/schedule-downtime?host=hv-$hostname&type=Host"
$headers = @{ "Authorization" = "$basicAuthValue"; "Accept" = "application/json" }
$body = @{
author = 'test-user'
comment = 'Cluster Aware Updating'
child_options = 2
start_time = $start_time
endtime = $end_time
}
$body = $body | ConvertTo-Json
# Ignore self signed certificates
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
# Schedule the downtime
Invoke-WebRequest -Headers $headers -Uri "$Uri" -Method Post -Body $body
# Don't ignore self signed certificates anymore
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null