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 »

Jake,

Tested the 'utils-api.inc.php' patch and did some tests. It effectively starts the 'Apply Configuration', but I do get a warning:
From the CLI of the Reactor server:

Code: Select all

curl -k -XPOST --data "apikey=apikeyblabla&pretty=1" "https://nagiosxiprodserver.domain/nagiosxi/api/v1/system/applyconfig"
{"success":"Apply config command has been sent to the backend."}
Also tested with POST:

Code: Select all

curl -k -POST --data "apikey=apikeyblabla&pretty=1" "https://nagiosxiprodserver.domain/nagiosxi/api/v1/system/applyconfig"
{"success":"Apply config command has been sent to the backend."}
Both seem to work.

Code: Select all

tail -f /usr/local/nagiosxi/var/cmdsubsys.log
.......
PROCESSED 0 COMMANDS
NAGIOSCORE CONFIG...
CMDLINE=cd /usr/local/nagiosxi/scripts && ./reconfigure_nagios.sh
URL: https://localhost/nagiosxi/includes/components/ccm/
CMDLINE
--2015-12-10 13:14:13--  https://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:443... connected.
    WARNING: certificate common name “nagiosxiprodserver.domain” doesn't match requested host name “localhost”.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.login”

     0K .......... .......... .......... ......                 562K=0.07s

2015-12-10 13:14:13 (562 KB/s) - “nagiosql.login” saved [37646]

/usr/bin/wget --save-cookies nagiosql.cookies --keep-session-cookies https://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'submit=Login&hidelog=true&loginSubmitted=true&username=nagiosxi&password=password' -O nagiosql.loginLOGIN SUCCESSFUL!
IMPORTING CONFIG FILES...URL: https://localhost/nagiosxi/includes/components/ccm/
Array
(
)
RESETTING PERMS
URL: https://localhost/nagiosxi/includes/components/ccm/
CMDLINE
--2015-12-10 13:14:14--  https://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:443... connected.
    WARNING: certificate common name “nagiosxiprodserver.domain” doesn't match requested host name “localhost”.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.login”

     0K .......... .......... .......... ......                 559K=0.07s

2015-12-10 13:14:15 (559 KB/s) - “nagiosql.login” saved [37646]

/usr/bin/wget --save-cookies nagiosql.cookies --keep-session-cookies https://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'submit=Login&hidelog=true&loginSubmitted=true&username=nagiosxi&password=password' -O nagiosql.loginLOGIN SUCCESSFUL!
URL: https://localhost/nagiosxi/includes/components/ccm/
CMDLINE:
/usr/bin/wget --load-cookies=nagiosql.cookies https://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'cmd=apply&type=writeConfig' -O nagiosql.export.monitoring
--2015-12-10 13:14:15--  https://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:443... connected.
    WARNING: certificate common name “nagiosxiprodserver.domain” doesn't match requested host name “localhost”.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.export.monitoring”

     0K .......... .....                                        973 =17s

2015-12-10 13:14:32 (973 B/s) - “nagiosql.export.monitoring” saved [16344]

WRITE CONFIGS SUCCESSFUL!
OUTPUT:
Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
        Checked 14982 services.
        Checked 803 hosts.
        Checked 168 host groups.
        Checked 86 service groups.
        Checked 73 contacts.
        Checked 21 contact groups.
        Checked 307 commands.
        Checked 86 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 803 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 86 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
RET: 0
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
OUTPUT=Starting nagios: done.
RETURNCODE=0
.....................^C
WARNING: certificate common name “nagiosxiprodserver.domain” doesn't match requested host name “localhost”.

What would be the officer problem with this warning?

I still don't get it working with the 'Submit an HTTP request' action from Nagios Reactor.

Code: Select all

INFO - 2015-12-10 13:25:40: STEP 1 : ****** BEGIN RUN 34063 ******
INFO - 2015-12-10 13:25:41: STEP 1 : Running block in basic mode.
INFO - 2015-12-10 13:25:41: STEP 1 : Running success actions.
INFO - 2015-12-10 13:25:41: STEP 1 : action (Submit an HTTP request) : (context) : Running action: Submit an HTTP POST request to 'https://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig'
INFO - 2015-12-10 13:25:41: STEP 1 : action (Submit an HTTP request) : (context) : Translated context variable: https://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig = https://nagiosxiprodserver.domain/nagiosxi/api/v1/system/applyconfig
INFO - 2015-12-10 13:25:41: STEP 1 : action (Submit an HTTP request) : (context) : Translated context variable: --data "apikey=%nagiosxiapikey%&pretty=1" -k = --data "apikey=apikeyblabla&pretty=1" -k
INFO - 2015-12-10 13:25:41: STEP 1 : action (Submit an HTTP request) : (context) : Performing POST request to https://nagiosxiprodserver.domain/nagiosxi/api/v1/system/applyconfig
INFO - 2015-12-10 13:25:42: STEP 1 : action (Submit an HTTP request) : (context) : HTTP status was 200
INFO - 2015-12-10 13:25:42: STEP 1 : action (Submit an HTTP request) : (context) : (Submit an HTTP POST request to 'https://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig') finished with result (0)
INFO - 2015-12-10 13:25:42: STEP 1 : Run complete (success)
Could someone let me know what I'm doing wrong here? (What is the difference between POST and XPOST by the way..?)

Grtz

Willem
You do not have the required permissions to view the files attached to this post.
Nagios XI 5.8.1
https://outsideit.net
User avatar
Nagios Support
Posts: 36
Joined: Thu Sep 04, 2014 12:16 pm

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

Post by Nagios Support »

We will need some time to test this and will get back to you with a possible solution sometime tomorrow morning. Thank you!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

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

Post by lmiltchev »

Willem, passing "-k" from the command line will work but it is not going to work from the web UI. You could try setting up your command in a script on the Reactor and try running it this way. I am not sure if copying the certs over from the XI machine to Reactor will resolve the issue, but you can give it a try. I am going to try this next.
What is the difference between POST and XPOST by the way..?
X is the command in curl:

Code: Select all

curl -X POST
curl -XPOST
Be sure to check out our Knowledgebase for helpful articles and solutions!
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 »

Ludmill, the problem is I need to specify the -k option, as we still have a SHA1 cert in our chain. it is however being replaced between now and the end of December. I will test again after my Christmas holiday, as I won't ened to specify the -k option anymore then. Grtz
Nagios XI 5.8.1
https://outsideit.net
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

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

Post by lmiltchev »

Willem, give us some feedback after you test it. REST API works with XPOST for me but only if I don't use SSL. Passing "-k" didn't work for me. Using a script in reactor didn't prove to be successful, either. I will do some more digging into this. I will be keeping this thread open.
Be sure to check out our Knowledgebase for helpful articles and solutions!
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 »

ludmill,

I can't even get it to work with http.. But imho this should work with https no? How else can we safely submit http requests?

Code: Select all

INFO - 2015-12-15 15:20:15: STEP 1 : ****** BEGIN RUN 34795 ******
INFO - 2015-12-15 15:20:15: STEP 1 : Running block in basic mode.
INFO - 2015-12-15 15:20:15: STEP 1 : Running success actions.
INFO - 2015-12-15 15:20:15: STEP 1 : action (Submit an HTTP request) : (context) : Running action: Submit an HTTP POST request to 'http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig'
INFO - 2015-12-15 15:20:15: 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 - 2015-12-15 15:20:15: STEP 1 : action (Submit an HTTP request) : (context) : Translated context variable: --data "apikey=%nagiosxiapikey%&pretty=1" = --data "apikey=blabla&pretty=1"
INFO - 2015-12-15 15:20:15: STEP 1 : action (Submit an HTTP request) : (context) : Performing POST request to http://nagiosserver/nagiosxi/api/v1/system/applyconfig
INFO - 2015-12-15 15:20:15: STEP 1 : action (Submit an HTTP request) : (context) : HTTP status was 404
INFO - 2015-12-15 15:20:15: STEP 1 : action (Submit an HTTP request) : (context) : (Submit an HTTP POST request to 'http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig') finished with result (1)
INFO - 2015-12-15 15:20:15: STEP 1 : Run complete (failure)
Grtz
Nagios XI 5.8.1
https://outsideit.net
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

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

Post by lmiltchev »

Here's what I have in Reactor:

Code: Select all

Action Type: Submitt an HTTP request
URL: http://192.168.x.x/nagiosxi/api/v1/system/applyconfig/
Request Type: POST
Extra GET/POST Params: apikey=blabla&pretty=1
example01.PNG
I modified a service on my XI box but didn't apply configuration. When I submitted the command from reactor, the configuration got applied. I am not sure why it is not working for you. Try removing the "--data" portion.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
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 »

Ludmill,

Tried removing --data , but I get the same result:

Code: Select all

INFO - 2016-01-08 11:17:13: STEP 1 : ****** BEGIN RUN 37765 ******
INFO - 2016-01-08 11:17:14: STEP 1 : Running block in basic mode.
INFO - 2016-01-08 11:17:14: STEP 1 : Running success actions.
INFO - 2016-01-08 11:17:14: 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-08 11:17:14: 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-08 11:17:14: STEP 1 : action (Submit an HTTP request) : (context) : Translated context variable: "apikey=%nagiosxiapikey%&pretty=1" = "apikey=blabla&pretty=1"
INFO - 2016-01-08 11:17:14: STEP 1 : action (Submit an HTTP request) : (context) : Performing POST request to http://nagiosserver/nagiosxi/api/v1/system/applyconfig
INFO - 2016-01-08 11:17:14: STEP 1 : action (Submit an HTTP request) : (context) : HTTP status was 404
INFO - 2016-01-08 11:17:14: STEP 1 : action (Submit an HTTP request) : (context) : (Submit an HTTP POST request to 'http://%nagiosxiserver%/nagiosxi/api/v1/system/applyconfig') finished with result (1)
INFO - 2016-01-08 11:17:14: STEP 1 : Run complete (failure)
Seems I also can't get it to work anymore with curl from cli:

Code: Select all

curl -k -XPOST --data "apikey=blabla&pretty=1" "https://nagiosserver/nagiosxi/api/v1/system/applyconfig"
{"error":"Unknown API endpoint."}

Code: Select all

curl -XPOST --data "apikey=blabla&pretty=1" "http://nagiosserver/nagiosxi/api/v1/system/applyconfig"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /nagiosxi/api/v1/system/applyconfig was not found on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at nagiosserver Port 80</address>
</body></html>
I thought it did work last time I tried. I did update to 5.2.3 in the meantime. Is it possible utils-api.inc.php was updated by the 5.2.3 update?
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 »

Were you on 5.2.2 previously on this server?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

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

Post by rkennedy »

curl -XPOST --data "apikey=blabla&pretty=1" "http://nagiosserver/nagiosxi/api/v1/system/applyconfig"
Jumping in a bit late, I wonder if this is an apache rewrite rule though. Do you see anything in your error_log or ssl_error_log that pertains to when you run this?
Former Nagios Employee
Locked