Page 1 of 1

Submit nrdp with curl

Posted: Tue Jun 20, 2017 10:38 am
by BanditBBS
I'm trying to replicate this post: https://support.nagios.com/forum/viewto ... 16&t=43618

I replaced the values(token, hostname, servicename, etc) and it just loads the page, it doesn't perform the POST.

Code: Select all

curl -X POST --data-urlencode 'token=xxxx&cmd=submitcheck&XMLDATA=<?xml version='\''1.0'\''?><checkresults><checkresult type='\''service'\''><hostname>localhost</hostname><servicename>Host Automation</servicename><state>1</state><output>Warning - this is a test</output></checkresult></checkresults>' http://xxxxx.itciss.com/nrdp/
And this is the output I get instead of the expected result of a successful processing:

Code: Select all

        <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>

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 10:46 am
by SteveBeauchemin
Jim,

I just compared the 2 curl statements. The only difference I see is the final tic after the nrdp/' The working example has it, your example does not.

I have not tried anything, I'm just noticing one character missing.

Steve B

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 10:52 am
by BanditBBS
Steve, I must be blind as I don't see anything after nrdp/

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 10:56 am
by SteveBeauchemin
Damn, where did it go... :P

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 10:59 am
by tmcdonald
You got some funky escaping of your single quotes. I would suggest mixing single and double instead of trying to escape. Here:

Code: Select all

curl -X POST --data-urlencode 'token=xxxx&cmd=submitcheck&XMLDATA=<?xml version='\''1.0'\''?>
when you escape the second single quote after version you are essentially breaking the --data-urlencode string. You need to escape the first one. Effectively you have this string:

Code: Select all

curl -X POST --data-urlencode 'token=xxxx&cmd=submitcheck&XMLDATA=<?xml version='
Do this:

Code: Select all

curl -X POST --data-urlencode 'token=xxxx&cmd=submitcheck&XMLDATA=<?xml version="1.0"?><checkresults><checkresult type="service"><hostname>localhost</hostname><servicename>Host Automation</servicename><state>1</state><output>Warning - this is a test</output></checkresult></checkresults>' http://xxxxx.itciss.com/nrdp/

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 11:08 am
by SteveBeauchemin
yeah, what Trevor said...

I also noticed this
<checkresult Type='\''service'\''> - working example
<checkresult type='\''service'\''> - your example

Is case sensitivity an issue?

Also, in the output I see the working example has a pipe character. Do you need to terminate with that?
<output>Warning - this is a test</output>
<output>Warning - this is a test|</output>

Steve B

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 11:10 am
by tmcdonald
I also generally just pass it all in as a GET request:

Code: Select all

curl -L 'http://192.168.1.100/nrdp?cmd=submitcmd&token=banditbbsismyhero&command=PROCESS_SERVICE_CHECK_RESULT;localhost;automation;1;testing'
Does it work if you format it that way?

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 11:23 am
by BanditBBS
tmcdonald wrote:I also generally just pass it all in as a GET request:

Code: Select all

curl -L 'http://192.168.1.100/nrdp?cmd=submitcmd&token=banditbbsismyhero&command=PROCESS_SERVICE_CHECK_RESULT;localhost;automation;1;testing'
Does it work if you format it that way?
That works and is much simpler! Thanks!

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 11:26 am
by SteveBeauchemin
Cool... he's my hero too.
Thanks for the easy answer.
Steve B

Re: Submit nrdp with curl

Posted: Tue Jun 20, 2017 11:59 am
by tmcdonald
Closin' it up.