Page 1 of 1

REST API does not work

Posted: Fri Feb 02, 2018 8:34 am
by Francesco
Hi all,
we want to use REST API NagiosXI, but probably we don't have something in our installation:

Code: Select all

GET https://<fqdn nagiosXI server>/nagiosxi/api/v1/objects/hostgroup?apikey=<API key>&pretty=1
404: The requested URL /nagiosxi/api/v1/objects/hostgroup was not found on this server.

# tail /var/log/httpd/ssl_error_log
[Fri Feb 02 14:19:39 2018] [error] [client <ip client>] File does not exist: /usr/local/nagiosxi/html/api/v1/objects

# ls -l /usr/local/nagiosxi/html/api/v1/
total 4
-rwxr-x--- 1 nagios nagios 1247 Nov 13 17:20 index.php

GET https://<fqdn nagiosXI server>/nagiosxi/api/v1/index.php?apikey=<API key>&pretty=1
404: NoEndpoint:

# tail /var/log/httpd/ssl_error_log
[Fri Feb 02 14:24:05 2018] [error] [client <ip client>] PHP Notice:  Undefined index: request in /usr/local/nagiosxi/html/api/v1/index.php on line 37
How activate NagiosXI REST API?

Thanks,

System:
  • Nagios XI Version : 5.4.11
  • <fqdn server> 2.6.32-573.3.1.el6.x86_64 x86_64
  • Red Hat Enterprise Linux Server release 6.7 (Santiago)
  • Gnome is not installed
Apache Information
  • PHP Version: 5.3.3
  • Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
  • Server Name: <fqdn server>
  • Server Address: <IP server>
  • Server Port: 443
Date/Time
  • PHP Timezone: Europe/Rome
  • PHP Time: Fri, 02 Feb 2018 14:26:32 +0100
  • System Time: Fri, 02 Feb 2018 14:26:32 +0100

Re: REST API does not work

Posted: Fri Feb 02, 2018 12:37 pm
by bolson
Hello,

Does this code block exist in /etc/httpd/conf.d/nagiosxi.conf

Code: Select all

<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>

Re: REST API does not work

Posted: Mon Feb 12, 2018 5:13 am
by Francesco
Hi,
code not present.

Added, and service httpd restarted. Same problem.
URL:
https://<FQDN SERVER>/nagiosxi/api/v1/system/status?apikey=<API key>&pretty=1

Reply:
Not Found
The requested URL /nagiosxi/api/v1/system/status was not found on this server.

In the log:

Code: Select all

[Mon Feb 12 10:46:43 2018] [error] [client <my client IP>] File does not exist: /var/www/html/favicon.ico, referer: https://<FQDN SERVER>/nagiosxi/api/v1/system/status?apikey=<API key>&pretty=1
[Mon Feb 12 10:47:42 2018] [error] [client <my client IP>] File does not exist: /usr/local/nagiosxi/html/api/v1/system
Please note that the is no files under "/usr/local/nagiosxi/html/api/v1", only a lonely "index.php"

Thanks,

Re: REST API does not work

Posted: Mon Feb 12, 2018 12:38 pm
by lmiltchev
Actually, add the following block on the bottom of the "/etc/httpd/conf.d/ssl.conf" file BEFORE the line </VirtualHost>:

Code: Select all

<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>
Restart apache:

Code: Select all

service httpd restart
Let us know if this helped.

Re: REST API does not work

Posted: Mon Feb 19, 2018 7:16 am
by Francesco
Now it works! Thanks you!

You can close this thread, for documentation please tell us who is the owner of creating/updating the file "[...]/ssl.conf", because last summer we updated NagiosXI, but I don't remember any info or warning about SSL and/or API.

Thanks again.

Re: REST API does not work

Posted: Mon Feb 19, 2018 10:26 am
by mcapra
From the "How To Configure SSL/TLS" documentation:
Now you have to tell the Apache web server (httpd) where to look for it. Open the /etc/httpd/conf.d/ssl.conf file in vi by executing the following command:

Code: Select all

vi /etc/httpd/conf.d/ssl.conf
Find these lines and update them as follows:

Code: Select all

SSLCertificateFile /etc/pki/tls/certs/certfile.crt
SSLCertificateKeyFile /etc/pki/tls/private/keyfile.key
Tip: typing /eFile and pressing Enter in vi should take you directly to this section in the file.

In that same file, navigate to the end (press SHIFT + G) and before the line </VirtualHost> add the following lines:

Code: Select all

<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>
It's not an explicit "do this or the API will break" mention in the documentation, but it is there as a discrete step.

Re: REST API does not work

Posted: Mon Feb 19, 2018 1:18 pm
by lmiltchev
@Francesco, as @mcapra explained, the step for enabling the REST API (in the ssl.conf) is already present in our documentation. I will be locking this topic now. If you have any more questions/issues, please start a new thread. Thank you!