Page 1 of 1

Nagios API system/scheduleddowntime

Posted: Wed Nov 04, 2020 2:34 pm
by onegative
G 'Day Support,

So I need assistance. I am attempting to use the API to set a Scheduled Downtime for a host. The Powershell script I am using is attached, remove .txt. Can you please inspect it and give it a try. You'll need to set the Admin $apikey and $nagInstance variables. Once set you can execute the script by passing two mandatory parameters -l & -h for length in seconds & host

I am running Nagios XI 5.6.1 on my test system and when I invoke the Powershell script it appears to run successfully but I never see it actual defined within Scheduled Downtime screen or on the host itself.

I am uncertain how to troubleshoot and could use a hint in where the request which appears to be reaching and succeeding might be logged for troubleshooting.

Help is greatly appreciated...
Thanks,
Danny

p.s. I have successfully set Scheduled Downtime using Linux curl commands but this is my first attempt using Powershell.

The output from the invocation is as follows:

Code: Select all

PS C:\Users\billyBob\desktop> .\nagiosScheduledDowntime.ps1 -l 300 -h mlt-dcom-tool


StatusCode        : 200
StatusDescription : OK
Content           : {"success":"Schedule downtime command(s) sent successfully.","scheduled":{"hosts":["mlt-dcom-tool"]}}

RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Orgin: *
                    Access-Control-Allow-Methods: *
                    Content-Length: 102
                    Content-Type: application/json
                    Date: Wed, 04 Nov 2020 19:15:17 GMT
                    Server: Apache/2.4.6 (Red Hat...
Forms             : {}
Headers           : {[Access-Control-Allow-Orgin, *], [Access-Control-Allow-Methods, *], [Content-Length, 102], [Content-Type, application/json]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 102

Re: Nagios API system/scheduleddowntime

Posted: Thu Nov 05, 2020 3:18 pm
by benjaminsmith
HI Danny,

Not sure if it matters but I swapped the API key around during testing. It works but I don't think the timestamp calculation is correct. I hardcoded the values into the body of the request using the samples in the API example and that did the trick. The other time values were in the past so even though it was showing up in the log it wasn't being posted as scheduled downtime.

One tip is that you can filter on the Audit Log API field to see the incoming calls.
api-audit-log.png
Scheduled Downtime Page
scheduled-downtime.png
Hope that helps and let me know if you get it working.

Benjamin

Re: Nagios API system/scheduleddowntime

Posted: Fri Nov 06, 2020 10:55 am
by onegative
@benjaminsmith
Hey Benjamin,

You're right its the timestamp...I was generating timestamp based off the current offset...I had to change the format to get true Unix epoch time.

Changed as follows for the $start timestamp
From:
[int]$start = (Get-Date -Date ((Get-Date).DateTime) -UFormat %s)
to
[int]$start = (Get-Date (Get-Date).ToUniversalTime() -UFormat %s).split('.')[0]

Thus the I was trying to set a start time that had already past/expired from the API's perspective.

Thanks for your help...I just wasn't seeing it...the extra eyes helped.
Danny

p.s. Please locked this thread...

Re: Nagios API system/scheduleddowntime

Posted: Fri Nov 06, 2020 11:20 am
by scottwilkerson
onegative wrote:@benjaminsmith
Hey Benjamin,

You're right its the timestamp...I was generating timestamp based off the current offset...I had to change the format to get true Unix epoch time.

Changed as follows for the $start timestamp
From:
[int]$start = (Get-Date -Date ((Get-Date).DateTime) -UFormat %s)
to
[int]$start = (Get-Date (Get-Date).ToUniversalTime() -UFormat %s).split('.')[0]

Thus the I was trying to set a start time that had already past/expired from the API's perspective.

Thanks for your help...I just wasn't seeing it...the extra eyes helped.
Danny

p.s. Please locked this thread...
Locking thread