rest api redirect not working

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

rest api redirect not working

Post by doneil326 »

hello,

i am trying to use the rest api following the documentation, but i have an issue. when trying the basic url curl -XGET "https://nagiosxi.lifelock.com/nagiosxi/ ... "&pretty=1" i get https://nagiosxi.lifelock.com/nagiosxi/ ... "&pretty=1

Not Found

The requested URL /nagiosxi/api/v1/objects/servicestatus was not found on this server.

Apache/2.2.15 (Red Hat) Server at nagiosxi.lifelock.com Port 443

it appears in the nagiosxi.conf that there is a rewrite rule for this. it should rewrite the url to ttps://nagiosxi.lifelock.com/nagiosxi/api/v1/index.php?request=objects/servicestatus&apikey="test"&pretty=1 but it does not. Here is copy of my .conf file. can you explain why this is not working?

Code: Select all

<Directory "/usr/local/nagiosxi/html">
   SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
#   AuthName "Nagios XI"
#   AuthType Basic
#   AuthUserFile /usr/local/nagiosxi/etc/htpasswd.users
#   Require valid-user
</Directory>

Alias /nagiosxi "/usr/local/nagiosxi/html"

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule nagiosxi/api/v1/(.*)$ /usr/local/nagiosxi/html/api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: rest api redirect not working

Post by rkennedy »

Do you have SSL enabled? Also, what version of XI are you running?

The reason I ask is because the command executed fine on my side, on a test box that forces SSL.

Code: Select all

[root@localhost ~]# curl -XGET "https://192.168.131.130/nagiosxi/api/v1/objects/servicestatus?apikey="test"&pretty=1" -k
{"error":"Invalid API Key"}
It looks like you have the same rewrite rule 18 times, you can take out all of the duplicates and leave one.

Additionally, not too sure where this part came from in your nagiosxi.conf. Did you add this in?

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
Former Nagios Employee
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: rest api redirect not working

Post by doneil326 »

i have 5.2.0. the rewrite rules came in from the upgrade. i tried removing all of them and it still has the same issue. the last rule in there is to try and do a redirect to https. ssl is enabled.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: rest api redirect not working

Post by rkennedy »

Can you run the CURL command and then post the results of the following?

Code: Select all

tail -25 /var/log/httpd/access_log
tail -25 /var/log/httpd/ssl_access_log
tail -25 /var/log/httpd/error_log
tail -25 /var/log/httpd/ssl_error_log
Former Nagios Employee
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: rest api redirect not working

Post by doneil326 »

see attachments
You do not have the required permissions to view the files attached to this post.
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: rest api redirect not working

Post by doneil326 »

last attachment
You do not have the required permissions to view the files attached to this post.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: rest api redirect not working

Post by Box293 »

The document "Configuring SSL for Nagios XI" was updated today:
https://assets.nagios.com/downloads/nag ... s%20XI.pdf

Can you double check your configuration matches this please.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: rest api redirect not working

Post by doneil326 »

please close this has been resolved
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: rest api redirect not working

Post by rkennedy »

Glad to see you were able to fix this. I will now close this thread out, but feel free to open another thread if you ever need assistance.
Former Nagios Employee
Locked