Can't get REST API to work with XPOST

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Can't get REST API to work with XPOST

Post by WillemDH »

Sean,

The good news is that it works with curl XPOST after edting /usr/local/nagiosxi/html/api/includes/utils-api.inc.php as you suggested.

But I'm not getting it to work from Reactor submit HTTP request chain. Not with HTTP, nor with HTTPS.

Code: Select all

INFO - 2016-01-20 14:41:24: STEP 1 : ****** BEGIN RUN 39991 ******
INFO - 2016-01-20 14:41:24: STEP 1 : Running block in basic mode.
INFO - 2016-01-20 14:41:24: STEP 1 : Running success actions.
INFO - 2016-01-20 14:41:24: STEP 1 : action (Submit an HTTP request) : (context) : Running action: Submit an HTTP POST request to 'http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig'
INFO - 2016-01-20 14:41:24: STEP 1 : action (Submit an HTTP request) : (context) : Translated context variable: http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig = http://nagiosserver/nagiosxi/api/v1/system/applyconfig
INFO - 2016-01-20 14:41:24: STEP 1 : action (Submit an HTTP request) : (context) : Performing POST request to http://nagiosserver/nagiosxi/api/v1/system/applyconfig
INFO - 2016-01-20 14:41:25: STEP 1 : action (Submit an HTTP request) : (context) : HTTP status was 200
INFO - 2016-01-20 14:41:25: STEP 1 : action (Submit an HTTP request) : (context) : (Submit an HTTP POST request to 'http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig') finished with result (0)
INFO - 2016-01-20 14:41:25: STEP 1 : Run complete (success)
I do get a HTTP statuc ocde of 200 instead of 404, so we are getting closer. I tried different combinations in the Extra GET/POST Params textbox:

Code: Select all

--data "apikey=blablaapikey&pretty=1"

Code: Select all

"apikey=blablaapikey&pretty=1"
Neither of the above is working.

Grtz

Willem
Nagios XI 5.8.1
https://outsideit.net
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Can't get REST API to work with XPOST

Post by ssax »

I have it working with HTTP but it's not working with HTTPS at the moment, I will finish the rest of it tomorrow and let you know what the solution is.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Can't get REST API to work with XPOST

Post by ssax »

Ok, it works for me now with both HTTP and HTTPS, here's what I did:

URL:

Code: Select all

https://YOURXISERVER/nagiosxi/api/v1/system/applyconfig
Request Type:

Code: Select all

POST
Extra GET/POST Params:

Code: Select all

apikey=YOURAPIKEY&pretty=1
This works for both HTTP and HTTPS, however, if you are redirecting/forcing SSL on your XI server then you must edit this file:

Code: Select all

/var/www/html/nagiosreactor/application/helpers/reactor_pluggables_helper.php
Around line 169, change this code:

Code: Select all

$ch = curl_init();
To this:

Code: Select all

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Now it should work.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Can't get REST API to work with XPOST

Post by WillemDH »

This works for both HTTP and HTTPS, however, if you are redirecting/forcing SSL on your XI server then you must edit this file:
This sounds weird, as I'm not (yet) forcing HTTPS.

But the good new is that after editing the file with your suggestions, it finally works! :D

This thread has gone long enough. Please not that the Nagios XI How to configure SSL documentation should be updated with the correct nagiosxi.conf settings. I hope all the changes we did are implemented in the next Nagios Reactor release. :)

Greetings, thanks and please close this thread. If I would encounter more problems, I'll make a new one.

Willem
Nagios XI 5.8.1
https://outsideit.net
Locked