NRDP API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Gavin
Posts: 58
Joined: Mon Dec 24, 2012 4:56 am

NRDP API

Post by Gavin »

I'm trying to include a call to NRDP as part of a script we use on Windows. I don't really want to use any of the existing clients but, from what I've seen, calling it directly shouldn't be a problem.

Is there a published API Document for NRDP? No matter what POST data I send to NRDP, I always get the full html page come back (the same one you get in a web browser when browsing to http://nagios/nrdp/).

If there isn't one, can anyone tell me what I need to send to NRDP, what needs to go into the headers etc? I don't need much detail, just enough to get me going.

Thanks,

Gavin
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: NRDP API

Post by lmiltchev »

You can review our documentation on NRDP, in particular the "Testing The NRDP API" section:

http://assets.nagios.com/downloads/nagi ... erview.pdf

Also, you may want to take a look at this one:

http://old.nagios.org/developerinfo/ext ... ndlist.php

Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Gavin
Posts: 58
Joined: Mon Dec 24, 2012 4:56 am

Re: NRDP API

Post by Gavin »

Thanks for that. I've tried reverse engineer to the script that document references, but I must be doing something wrong as I keep getting the html page come back:
HTTP/1.1 200 OK
Connection: close
Content-Length: 1243
Content-Type: text/html; charset=UTF-8
Date: Sat, 26 Jan 2013 21:41:05 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3

<strong>Submit Nagios Command:</strong><br>
<form action="" method="get">
<input type="hidden" name="cmd" value="submitcmd">
Token: <input type="text" name="token" value="" size="15"><br>
Command: <input type="text" name="command" size="50" value="DISABLE_HOST_NOTIFICATIONS;somehost"><br>
<input type="submit" name="btnSubmit" value="Submit Command">
</form>

<hr>

<strong>Submit Check Data</strong><br>
<form action="" method="post">
<input type="hidden" name="cmd" value="submitcheck">
Token: <input type="text" name="token" value="" size="15"><br>
Check Data:<br>
<textarea cols="80" rows="15" name="XMLDATA">
<?xml version='1.0'?>
<checkresults>
<checkresult type='host'>
<hostname>somehost</hostname>
<state>0</state>
<output>Everything looks okay!|perfdata</output>
</checkresult>
<checkresult type='service'>
<hostname>somehost</hostname>
<servicename>someservice</servicename>
<state>1</state>
<output>WARNING: Danger Will Robinson!|perfdata</output>
</checkresult>
</checkresults>
</textarea><br>
<input type="submit" name="btnSubmit" value="Submit Check Data">
</form>
What do I need to send in the HTTP request? I've tried sending the token, the cmd and the XMLDATA in the headers, which I thought was what the script did...

Thanks,

Gavin
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NRDP API

Post by scottwilkerson »

Hmm, be sure you are posting to the full path, ie.

Code: Select all

http://nagiosxi/nrdp/
not

Code: Select all

http://nagiosxi/nrdp
Otherwise, what you stated sounds correct
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Gavin
Posts: 58
Joined: Mon Dec 24, 2012 4:56 am

Re: NRDP API

Post by Gavin »

Thanks, I've got it sorted now. Took me a while to realise why the data wasn't appearing in Nagios... turns out the NRDP config file hadn't been updated with the new location of our /spool/ directory (which is now on a ramdisk).

If anybody is interested, PowerShell 3.0 comes with a handy little command called 'Invoke-RestMethod', which can easily call NRDP. For example:

Code: Select all

$NagiosURL="http://nagios/nrdp/"
$token="tokenhere"
$cmd="submitcheck"

$XMLDATA= "<?xml version='1.0'?> 
<checkresults>
	<checkresult type='service'>
		<hostname>somehost</hostname>
		<servicename>someservice</servicename>
		<state>1</state>
		<output>WARNING: Danger Will Robinson!|perfdata</output>
	</checkresult>
</checkresults>"

$PostRequest = "token=$Token&cmd=$cmd&XMLDATA=$XMLDATA"

Invoke-RestMethod -Method POST -URI $NagiosURL -Body $PostRequest
Thanks,

Gavin
Locked