Downtime on multiple hosts via url or REST API

hi @LaSoe and @elias.voelker thanks for the quick reply, i am not an expert on API hehe learning as you all do, i was able to fix it in a way as become as below:

#Put the Hosts in checkmk Downtime

#Disable SSL Verification
[System.Net.ServicePointmanager]::ServerCertificateValidationCallback = {$true}
$username = "api-user"
$secret = "key"
####Get the list of hosts entered in the DTESXList.txt

$hostlist = get-content -Path "C:\nca\PowerCLI PS\BOS Patches\DTESXList.txt"
#write-host $hostlist

#$hostname = "dxbesx1"

#### Time Zone Variables
$Delta = 60
$StartTime = Get-Date
$EndTime = $StartTime.AddMinutes($Delta)
$StartTimeREST = [System.String]$(Get-Date $StartTime -Format 'yyyy-MM-ddTHH:mm:ssK')
$EndTimeREST = [System.String]$(Get-Date $EndTime -Format 'yyyy-MM-ddTHH:mm:ssK')




####Header Inputs
$Header = @{
"Authorization" = "Bearer $username $secret"
}

foreach ($hostname in $hostlist) {

###### Hashtable
##### the Z at the end is for UTC Time Zone
$Data = @{
   "start_time" = $startTimerest
   "end_time" = $endTimerest
   "recur" = "fixed"
   "comment" = "Security updates"
   "downtime_type" = "host"
   "host_name" = "$hostname" (this was the issue i had to put double quotes on the variable itself)
} | ConvertTo-Json

$Parameters = @{
Method = "POST"
Uri = "https://checkmk.xx.com/ncamaster/check_mk/api/1.0/domain-types/downtime/collections/host"
Headers = $Header
Body = $data
ContentType = "application/json"
}

Invoke-RestMethod @Parameters


}
2 Likes