Page 1 of 2

API not functioning correctly

Posted: Mon Apr 24, 2017 12:23 pm
by daniel.ledford
I am having an issue on our system, where I submit an API call to create a new host or service. I receive a success message like below:

Code: Select all

curl -XPOST "http://<HOSTNAME>/nagiosxi/api/v1/config/service?apikey=<APIKEY>&pretty=1" -d "host_name=testapihostapply&service_description=PING2&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
{
    "success": "Successfully added testapihostapply :: PING2 to the system. Config applied, Nagios Core was restarted."
}
However when I look in CCM or anywhere in XI or Core the service was not added, and cannot be found. This happens with any host or service I try to add. However if I try to add a hostgroup or service group I still receive the success message, but they are actually added into Nagios XI.

Where can I start looking to troubleshoot this, and why would I still receive a success message when the host/service was not actually added into XI?

Re: API not functioning correctly

Posted: Mon Apr 24, 2017 12:37 pm
by lmiltchev
I may be wrong, but it seems like the API would not give you a warning/error message if the host (i.e. "testapihostapply") you are adding the service to doesn't exists...

Can you make sure that you actually add the host first, prior to adding the service?

Code: Select all

curl -XPOST "http://<HOSTNAME>/nagiosxi/api/v1/config/host?apikey=<APIKEY>&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
After the "testapihostapply" has been added successfully, try again running:

Code: Select all

curl -XPOST "http://<HOSTNAME>/nagiosxi/api/v1/config/service?apikey=<APIKEY>&pretty=1" -d "host_name=testapihostapply&service_description=PING2&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
I will do some more digging into this issue, and discuss my findings with our developers.

Let us know if adding the host first helped.

Re: API not functioning correctly

Posted: Mon Apr 24, 2017 1:44 pm
by daniel.ledford
I did as you asked and attempted to add the host first, and then the service. On both I received the success message but still nothing showed up in XI/CCM.

Code: Select all

curl -XPOST "http://<HOSTNAME>/nagiosxi/api/v1/config/host?apikey=<APIKEY>&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
{
    "success": "Successfully added testapihostapply to the system. Config applied, Nagios Core was restarted."
}

curl -XPOST "http://<HOSTNAME>/nagiosxi/api/v1/config/service?apikey=<APIKEY>&pretty=1" -d "host_name=testapihostapply&service_description=PING&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
{
    "success": "Successfully added testapihostapply :: PING to the system. Config applied, Nagios Core was restarted."
}


Re: API not functioning correctly

Posted: Mon Apr 24, 2017 1:52 pm
by lmiltchev
Let's clarify - you don't see the host or the service under Home->Host/Service Detail or under the CCM->Hosts/Services page, correct?

What is the Nagios XI version that you are currently running?

Can you apply configuration successfully? Do you see any configuration errors, when you go to CCM->Tools->Config File Management, and click on the following buttons (in exact same order) - Delete Files->Write Configs->Verify Files?

Re: API not functioning correctly

Posted: Mon Apr 24, 2017 2:35 pm
by daniel.ledford
Yes, that is correct. I do not see the host or service under Home->Host/Service Detail or under the CCM->Hosts/Services page.

Our Nagios XI version is 5.2.3

Yes, I can successfully apply configuration.

Delete - Ran successful
Write - ran fir a while then went to a blank page. I checked the error logs and found this corresponding error.

PHP Fatal error: Maximum execution time of 30 seconds exceeded in /usr/local/nagiosxi/html/includes/components/ccm/classes/config_class.php on line 1081, referer:
http://vhlgnngxi071.tvlport.net/nagiosx ... ?cmd=apply

I went back and reran the write config files and it finished successfully this time.

And lastly the verify ran successfully without any errors.

Re: API not functioning correctly

Posted: Mon Apr 24, 2017 3:55 pm
by lmiltchev
Open the "/etc/php.ini" file in a text editor, and increase the values listed below:

Example:

Code: Select all

max_execution_time = 60
max_input_time = 60
memory_limit = 256
Note: These values are found under the "Resource Limits" section.

Save the changes, exit, and restart apache:

Code: Select all

service httpd restart
Let us know if this helped.

Re: API not functioning correctly

Posted: Tue Apr 25, 2017 10:49 am
by daniel.ledford
I made the changes you stated, and now was able to complete the Delete, Write, Verify without any problems.

I once again attempted to add the host via the API and it still reports success, but the host has not been added in XI / Core.

Re: API not functioning correctly

Posted: Tue Apr 25, 2017 1:52 pm
by ssax
Run this tail command (and let it run), try adding through the API, and then attach he entire output from the tail command:

Code: Select all

tail -f /var/log/httpd/*error_log
Thank you

Re: API not functioning correctly

Posted: Fri May 12, 2017 7:51 am
by daniel.ledford
[Thu May 04 03:01:01 2017] [error] [client 172.31.19.211] File does not exist: /var/www/html/sdk
[Tue May 09 02:58:59 2017] [error] [client 172.31.19.211] File does not exist: /var/www/html/sdk
[Wed May 10 03:02:29 2017] [error] [client 172.31.19.211] File does not exist: /var/www/html/sdk
[Thu May 11 19:36:06 2017] [error] [client 172.18.37.152] PHP Notice: Undefined offset: 0 in /usr/local/nagiosxi/html/includes/configwizards/windowssnmp/windowssnmp.inc.php on line 341, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php?update=1&nextstep=2&nsp=6a8cf1ac8066559305ed13dd80bcc54d&wizard=windowssnmp
[Thu May 11 19:36:06 2017] [error] [client 172.18.37.152] PHP Notice: Undefined offset: 0 in /usr/local/nagiosxi/html/includes/configwizards/windowssnmp/windowssnmp.inc.php on line 341, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php?update=1&nextstep=2&nsp=6a8cf1ac8066559305ed13dd80bcc54d&wizard=windowssnmp
[Thu May 11 19:36:06 2017] [error] [client 172.18.37.152] PHP Notice: Undefined offset: 0 in /usr/local/nagiosxi/html/includes/configwizards/windowssnmp/windowssnmp.inc.php on line 341, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php?update=1&nextstep=2&nsp=6a8cf1ac8066559305ed13dd80bcc54d&wizard=windowssnmp
[Thu May 11 19:36:06 2017] [error] [client 172.18.37.152] PHP Notice: Undefined offset: 0 in /usr/local/nagiosxi/html/includes/configwizards/windowssnmp/windowssnmp.inc.php on line 341, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php?update=1&nextstep=2&nsp=6a8cf1ac8066559305ed13dd80bcc54d&wizard=windowssnmp
[Thu May 11 19:37:12 2017] [error] [client 172.18.37.152] PHP Notice: Undefined index: tpl in /usr/local/nagiosxi/html/config/monitoringwizard.php on line 967, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php
[Thu May 11 19:37:19 2017] [error] [client 172.18.37.152] PHP Notice: Undefined index: tpl in /usr/local/nagiosxi/html/config/monitoringwizard.php on line 1373, referer: https://<HOST>/nagiosxi/config/monitoringwizard.php
[Fri May 12 03:06:50 2017] [error] [client 172.31.19.211] File does not exist: /var/www/html/sdk

This is the output as requested. I attempted to add via the API again, but nothing & no new error message came up.

Also, another symptom is that when I run a config wizard it will complete successfully with apply config, but the host & services are not added.
The only way I have been able to add a service successfully is to manually create it in the Core Config Manager -> Add new service.

Re: API not functioning correctly

Posted: Fri May 12, 2017 10:31 am
by tgriep
When adding the host, it may not of generated an error for the error_log files so can you try creating the host using the API but run this tail command instead and post the output?

Code: Select all

tail -f /var/log/httpd/*_log
I want to see if it shows up in any of the Apache log files.

Also, run the same tail command while running one of the wizards, when you finish running the wizard, post the output of that tail command.

Then, login to the Nagios server in a shell, run the following commands and post the output.

Code: Select all

cd /usr/local/nagiosxi/scripts
su nagios
./reconfigure_nagios.sh
Thanks