Page 2 of 4

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

Posted: Thu Dec 10, 2015 7:21 am
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

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

Posted: Thu Dec 10, 2015 6:10 pm
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!

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

Posted: Fri Dec 11, 2015 12:40 pm
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

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

Posted: Mon Dec 14, 2015 2:54 am
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

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

Posted: Mon Dec 14, 2015 11:59 am
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.

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

Posted: Tue Dec 15, 2015 9:23 am
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

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

Posted: Tue Dec 15, 2015 5:53 pm
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.

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

Posted: Fri Jan 08, 2016 5:41 am
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?

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

Posted: Fri Jan 08, 2016 3:20 pm
by ssax
Were you on 5.2.2 previously on this server?

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

Posted: Fri Jan 08, 2016 3:22 pm
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?