Page 1 of 1

NRDP API

Posted: Fri Jan 25, 2013 4:25 pm
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

Re: NRDP API

Posted: Fri Jan 25, 2013 5:00 pm
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.

Re: NRDP API

Posted: Sat Jan 26, 2013 4:44 pm
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

Re: NRDP API

Posted: Sat Jan 26, 2013 11:25 pm
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

Re: NRDP API

Posted: Mon Jan 28, 2013 1:30 am
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