Nagios API system/scheduleddowntime

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
onegative
Posts: 175
Joined: Tue Feb 17, 2015 12:06 pm

Nagios API system/scheduleddowntime

Post 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
You do not have the required permissions to view the files attached to this post.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Nagios API system/scheduleddowntime

Post 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
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
onegative
Posts: 175
Joined: Tue Feb 17, 2015 12:06 pm

Re: Nagios API system/scheduleddowntime

Post 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...
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios API system/scheduleddowntime

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked