Page 1 of 2
api reports success but host does not get added
Posted: Wed Aug 11, 2021 1:49 pm
by warapp
I have been using the api to add/remove hosts objects for some time. The process works as expected on my old box, NagiosXI 5.4.13 on CentOS 6. However, on my new system, host deletes work, but, the add host api call does not work. The add host call returns a success message, but, the hosts is not added to core/xi.
Here is my host add call command:
curl -XPOST "
https://nagios.example.com/nagiosxi/api ... y&pretty=1" -d "host_name=testapihost&address=192.168.20.22&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"
Here's the response:
{
"success": "Added testapihost to the system. Config applied, Nagios Core was restarted."
}
Despite the response, and the fact that I see the core restart messages in the log after the api call, when I look for host config in /usr/local/nagios/etc/hosts/ it's not there. And, when I search in xi, either in CCM or in Host Status details page, the host is not present.
I have tested other api calls to add hosts and they all result in the same behavior.
This system was built (manual install of nagiosxi 5.7.5, which completed without error) on top of a fresh install of Oracle 8. I then restored a nagiosxi backup taken on a device running CentOS6 and running the same version, nagiosxi version 5.7.5. The restore went without error and I have a "functioning" nagiosxi running on oracle 8.
Any help with this error would be greatly appreciated.
Thank you,
-wr
Re: api reports success but host does not get added
Posted: Wed Aug 11, 2021 5:02 pm
by gsmith
Hi,
I tried running your command but it didn't work:
Code: Select all
[root@localhost nagiosxi]# curl -k -XPOST "https://192.168.23.81/nagiosxi/api/v1/config/host?apikey=eTZvgpcbkr63AP3Z44KaoIfQ5cnnb9BIiRdRgJjEaoWZtYZA3ZKqHfA2qXJUmgDY&pretty=1" -d "host_name=testapihost&address=192.168.23.82&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7;"
{
"error": "Missing required variables",
"missing": [
"notification_interval",
"notification_period",
"contacts OR contact_groups"
]
}
When I added the additional three parameters it worked, but it didn't apply the config, which is correct as that is a separate api call:
Code: Select all
[root@localhost nagiosxi]# curl -k -XPOST "https://192.168.23.81/nagiosxi/api/v1/config/host?apikey=eTZvgpcbkr63AP3Z44KaoIfQ5cnnb9BIiRdRgJjEaoWZtYZA3ZKqHfA2qXJUmgDY&pretty=1" -d "host_name=testapihost&address=192.168.23.82&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7¬ification_interval=5;¬ification_period=24x7;&contacts=nagiosadmin;"
{
"success": "Added testapihost to the system. Config imported but not yet applied."
}
Now when I run the applyconfig api callI am able to see the host in the system:
Code: Select all
[root@localhost nagiosxi]# curl -XPOST "http://192.168.23.81/nagiosxi/api/v1/system/applyconfig?apikey=eTZvgpcbkr63AP3Z44KaoIfQ5cnnb9BIiRdRgJjEaoWZtYZA3ZKqHfA2qXJUmgDY"
{"success":"Apply config command has been sent to the backend.","command_id":4}
[root@localhost nagiosxi]#
It looks like the command you are using got cut off in the original post. Could you please provide it in its entirety to
me? I am curious as to the result you got - that it added the host and applied the config.
Thanks
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 7:29 am
by warapp
Here's the command and result.
curl -XPOST "
https://nagios.sample.com/nagiosxi/api/ ... y&pretty=1" -d "host_name=testapihost&address=192.168.20.22&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"
{
"success": "Added testapihost to the system. Config applied, Nagios Core was restarted."
}
===============
Here's what I see /usr/local/nagiosxi/var/cmdsubsys.log
RETURNCODE=0
PROCESSING COMMAND ID 53895...
PROCESS COMMAND: CMD=1160, DATA=
CMDLINE=/bin/true
OUTPUT=
RETURNCODE=0
PROCESSING COMMAND ID 53896...
PROCESS COMMAND: CMD=1150, DATA=remove
CMDLINE=php /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=syncall
PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 11:12 am
by gsmith
Hi,
The command is still getting cut-off. Can you please paste it into a text file and
send it to me?
Also please send me a System Profile.
To send us your system profile.
1. Login to the Nagios XI GUI using a web browser.
2. Click the "Admin" > "System Profile" Menu
3. Click the "Download Profile" button
4. Save the profile.zip file and share this in a private message and then reply to this post to bring it up in the queue.
And just to confirm, after migrating to Oracle 8, you are still running Nagios XI 5.7.5, right?
Thanks!
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 11:21 am
by warapp
The api command is attached. When the command is run, I receive the following response:
{
"success": "Added testapihost to the system. Config applied, Nagios Core was restarted."
}
But, the host is not added.
I will send the profile via pm.
Yes, I am running 5.7.5 with postgress db backend.
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 2:27 pm
by gsmith
Hi
Please make this change:
edit /etc/php.ini:
Code: Select all
max_input_vars = 50000
memory_limit = 1024M
max_execution_time = 120
max_input_time = 300
Then restart apache/http and nagios.
Please let me know the results, in the meantime I am loading up your System Profile.
Thanks
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 2:41 pm
by warapp
Changes applied to php.ini and httpd has been restarted.
Tested api add host command and received the same results. Host does not appear on disk, in core or in xi, despite success message.
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 3:23 pm
by gsmith
HI,
I loaded up your System Profile but can't duplicate the issue. I am chasing down an error in the logs.
Are you using BPI ?
Thanks
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 3:32 pm
by warapp
No, I am not using BPI.
Re: api reports success but host does not get added
Posted: Thu Aug 12, 2021 6:28 pm
by gsmith
Based on:
PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
That message is coming from a deprecated component that you can remove from the server.
So please take a backup:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
And then run the following command to remove this component.
Code: Select all
rm -rf /usr/local/nagiosxi/html/includes/components/nagiosim
Then try the api call.
Thanks