Nagios XI - API Issues Creating Hosts

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
chicjo01
Posts: 194
Joined: Tue Jul 28, 2015 2:52 pm

Nagios XI - API Issues Creating Hosts

Post by chicjo01 »

I have 2 issues going on with the NagiosXI API.

Issue 1:
Attempting to add a new host through the API. The response says successful, but the host is not created in the DB or the config files. I think it is due to the remote DB we have setup and the API is trying to use the local DB and not the remote DB. Does the API use the /usr/local/nagiosxi/html/config.inc.php or some other configuration file? If I use the same exact curl command against a NagiosXI server which has a local DB, it works correctly.

- Nagios Version: 5.2.2 and 5.2.3 (Mixed Environment. All servers will be on 5.2.3, in a few weeks)
- Using admin API key
Command Used:
curl -XPOST "http://<Nagios Server>/nagiosxi/api/v1/config/host?apikey=<API Key>&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."
}
Issue 2:
Using the create a new host API command, it requires a number of fields. I want to use the template instead of forcing the values on each host. Is there a way to do that?

- Nagios Version: 5.2.2 and 5.2.3 (Mixed Environment. All servers will be on 5.2.3, in a few weeks)
- Using admin API key
curl -XPOST "http://<Nagios Server>/nagiosxi/api/v1/config/host?apikey=<API Key>&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&use=testhosttemplate&applyconfig=1"

{
"error": "Missing required variables",
"missing": [
"max_check_attempts",
"check_period",
"notification_interval",
"notification_period",
"contacts OR contact_groups"
]
}

Host Template:
define host {
name testhosttemplate
alias testhosttemplate
check_command check-host-alive!!!!!!!!
initial_state u
max_check_attempts 5
check_interval 4
retry_interval 5
active_checks_enabled 1
check_period 24x7_with_sunday_maintenance
flap_detection_options u,
process_perf_data 1
contact_groups nocontact
notification_interval 0
notification_period 24x7_with_sunday_maintenance
notification_options d,u,r,f,s,
register 0
}
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI - API Issues Creating Hosts

Post by lmiltchev »

Issue 1:
I am not able to recreate this issue. I have a test Nagios XI box with offloaded MySQL db. I ran the same command, and the host was added just fine.

Code: Select all

curl -k -XPOST "https://x.x.x.x/nagiosxi/api/v1/config/host?apikey=l3i0i3np&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."
}
Note: The only difference is that I passed "-k" flag as I am using SSL, and curl was not "happy". :) This is a development revision of XI. I don't have a "vanilla" 5.2.3 with offloaded db to test it. So, if this is not working for you, it *should* work in the next release of XI as it is working for me now (on the dev revision).
example01.PNG
Issue 2:

There was a bug I filed in October last year - "Nagios XI Bug Report: Nagios XI - REST API can't use templates" (TASK ID 6782), which is fixed. However, I believe that you will need to pass "&force=1" to your command in order to use a template. Here's a command I used:
curl -k -XPOST "https://x.x.x.x/nagiosxi/api/v1/config/ ... p&pretty=1" -d "host_name=APITESTHOST&address=127.0.0.1&use=xiwizard_generic_host&contacts=nagiosadmin&force=1&applyconfig=1"
example02.PNG
Hope this helps.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI - API Issues Creating Hosts

Post by lmiltchev »

Forgot to mention - mysqld is not even running on this box, as it's offloaded.

Code: Select all

service mysqld status
mysqld is stopped
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
chicjo01
Posts: 194
Joined: Tue Jul 28, 2015 2:52 pm

Re: Nagios XI - API Issues Creating Hosts

Post by chicjo01 »

Thank you for the information. Do you know how close the next patch is?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI - API Issues Creating Hosts

Post by lmiltchev »

It should be fairly soon. We are doing some testing now. When all of the tests are done, we will release the next version of XI. I don't have an ETA but don't think it will take more than 2 weeks.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
chicjo01
Posts: 194
Joined: Tue Jul 28, 2015 2:52 pm

Re: Nagios XI - API Issues Creating Hosts

Post by chicjo01 »

lmiltchev wrote:It should be fairly soon. We are doing some testing now. When all of the tests are done, we will release the next version of XI. I don't have an ETA but don't think it will take more than 2 weeks.
Thank you for the information. Will let you know the results after the next patch.
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Nagios XI - API Issues Creating Hosts

Post by bwallace »

Thanks for that update, did you have any other questions or may we lock this thread?
Be sure to check out the Knowledgebase for helpful articles and solutions!
User avatar
chicjo01
Posts: 194
Joined: Tue Jul 28, 2015 2:52 pm

Re: Nagios XI - API Issues Creating Hosts

Post by chicjo01 »

bwallace wrote:Thanks for that update, did you have any other questions or may we lock this thread?
Go head. Thank you all.
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Nagios XI - API Issues Creating Hosts

Post by bwallace »

Glad we were able to help. We'll lock this thread now and feel free to open another should you require assistance with anything else.
Be sure to check out the Knowledgebase for helpful articles and solutions!
Locked