API exec error

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

API exec error

Post by rajasegar »

Can you please advice how to troubleshoot this issue?

The following is not working on the new server we setup 5.6.12 running on RHEL7.6.
API key is correct for the user in this server and it works fine on all the other servers.

Code: Select all

curl "http://10.10.1.10/nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=test&ticket=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM"
<?xml version="1.0" encoding="utf-8"?>
<error>
<errormessage>Authentication Failure</errormessage>
</error>

Thanks
Last edited by rajasegar on Thu Apr 23, 2020 9:28 pm, edited 1 time in total.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: API exec error

Post by rajasegar »

FYI, this works
curl -XGET "http://10.10.1.10/nagiosxi/api/v1/objec ... putype=xml"

{"recordcount":"18","stateentry":[{"instance_id":"1","state_time":"2020-04-24 08:09:52","object_id":"967","objecttype_id":"2","host_name":"MYWCBPIFRSDBS01","service_description":"MSSQL: Connection Time IFRS9-MY","state_change":"1","state":"0","state_type":"1","current_check_attempt":"2","max_check_attempts":"2","last_state":"1","last_hard_state":"0","output":"OK - 0.03 seconds to connect as nagios"},{"instance_id":"1","state_time":"2020-04-24 08:05:03","object_id":"967","objecttype_id":"2","host_name":"MYWCBPIFRSDBS01","service_description":"MSSQL: Connection Time IFRS9-MY","state_change":"1","state":"1","state_type":"0","current_check_attempt":"1","max_check_attempts":"2","last_state":"0","last_hard_state":"0","output":"WARNING - 3.04 seconds to connect as nagios"},{"instance_id":"1","state_time":"2020-04-24 05:44:08","object_id":"968","objecttype_id":"2","host_name":"MYWCBPIFRSDBS01","service
....
It is not coming out as XML though. We still need the backend version output as all the import routines is based on that.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API exec error

Post by ssax »

In order to use the depracated backend API, you need to go to Admin > System Settings > Backwards Compatibility tab and turn on "Allow Insecure Logins" and click the Update Settings button.

Then you will need to login (or masquerade as the user you want to allow it from) and click their username in the top right corner, then select "Enable Insecure Login" and click the Update Settings button.

That should do it.
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: API exec error

Post by rajasegar »

ssax wrote:In order to use the depracated backend API, you need to go to Admin > System Settings > Backwards Compatibility tab and turn on "Allow Insecure Logins" and click the Update Settings button.

Then you will need to login (or masquerade as the user you want to allow it from) and click their username in the top right corner, then select "Enable Insecure Login" and click the Update Settings button.

That should do it.
Capture1.JPG
Now Backend API works from browser but not from command line. Both API key and Insecure ticket works using the backend api from web browser. However when using curl I still getting the same error. Running on the same server ssh session also same issue.

The new API command below works fine from command line though.

Code: Select all

curl "http://10.104.18.193/nagiosxi/api/v1/objects/hoststatus?apikey=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM&pretty=1"
Please advice where else to check on this.

Code: Select all

[nagios@nagiosprodxi1 scripts]$ curl -v "http://10.104.18.193/nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=rajasegar&ticket=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM"
* About to connect() to 10.104.18.193 port 80 (#0)
*   Trying 10.104.18.193... connected
* Connected to 10.104.18.193 (10.104.18.193) port 80 (#0)
> GET /nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=rajasegar&ticket=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 10.104.18.193
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 27 Apr 2020 02:33:51 GMT
< Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips PHP/5.4.16
< X-Powered-By: PHP/5.4.16
< Set-Cookie: nagiosxi=7c8lqnio9bjvh5engh2t2c6tf3; expires=Mon, 27-Apr-2020 03:03:51 GMT; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< X-Frame-Options: SAMEORIGIN
< Content-Security-Policy: frame-ancestors 'self'
< Access-Control-Allow-Origin: *
< Content-Length: 108
< Content-Type: text/xml
<
<?xml version="1.0" encoding="utf-8"?>
<error>
<errormessage>Authentication Failure</errormessage>
</error>
* Connection #0 to host 10.104.18.193 left intact
* Closing connection #0

Code: Select all

[nagios@nagiosprodxi1 scripts]$ curl -v "http://10.104.18.193/nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=rajasegar&ticket=Z50PJXaeufi0HockAVtkKnptYG65sX7ri7A0kJv9YQpVuEf4PLnAoPjGrILXF8IX"
* About to connect() to 10.104.18.193 port 80 (#0)
*   Trying 10.104.18.193... connected
* Connected to 10.104.18.193 (10.104.18.193) port 80 (#0)
> GET /nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=rajasegar&ticket=Z50PJXaeufi0HockAVtkKnptYG65sX7ri7A0kJv9YQpVuEf4PLnAoPjGrILXF8IX HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 10.104.18.193
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 27 Apr 2020 02:36:05 GMT
< Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips PHP/5.4.16
< X-Powered-By: PHP/5.4.16
< Set-Cookie: nagiosxi=s3okqa0rjv90516nep55fkq1g7; expires=Mon, 27-Apr-2020 03:06:06 GMT; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< X-Frame-Options: SAMEORIGIN
< Content-Security-Policy: frame-ancestors 'self'
< Access-Control-Allow-Origin: *
< Content-Length: 108
< Content-Type: text/xml
<
<?xml version="1.0" encoding="utf-8"?>
<error>
<errormessage>Authentication Failure</errormessage>
</error>
* Connection #0 to host 10.104.18.193 left intact
* Closing connection #0
You do not have the required permissions to view the files attached to this post.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API exec error

Post by ssax »

This is a bug, I'm able to replicate it on my system. Reporting this to development now.

Code: Select all

NEW TASK created - Nagios XI Bug Report: XI - Insecure Login Ticket functionality broken
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API exec error

Post by ssax »

You should be able to get XML from the API like this: (you missed a t in outputtype)

Code: Select all

curl -XGET "http://10.10.1.10/nagiosxi/api/v1/objects/statehistory?apikey=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM&outputtype=xml"
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: API exec error

Post by rajasegar »

ssax wrote:You should be able to get XML from the API like this: (you missed a t in outputtype)

Code: Select all

curl -XGET "http://10.10.1.10/nagiosxi/api/v1/objects/statehistory?apikey=oqhpGMNfQbG7FU77lLTKiDOEBk7jXX9Gnp5kr8ChieoepOENPtN7mR2dc8P95YOM&outputtype=xml"
Thanks. This works fine. You can close the thread.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
Locked