Bug in API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Bug in API

Post by BanditBBS »

I just found a killer bug(for me) in the new API.

I am trying to automate adding our new hosts into XI with the basic checks. I have the host going in(works fine) and then a list of 11 services in 11 separate CURL statements being called. Only the last one gets added. I can rearrange all I want and only the last one of the list of services is added. Now, I put an apply changes API call between 2 of then and a sleep(30) and the one before the apply and the last one are both added. I would not be able to of course do that in production.

So, my question, is this a bug or by design?

To show you, the CURLS all work:

Code: Select all

{ "success": "Successfully added test667 to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Load to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: CPU to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Disk to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Cron Scheduler to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Log File to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Memory to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: NFS to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Read-Only File System to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Swap to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Total Processes to the system. Config imported but not yet applied." } 
{ "success": "Successfully added test667 :: Zombie Processes to the system. Config imported but not yet applied." }
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Bug in API

Post by tmcdonald »

I'll bet we are overwriting the unique ID in the DB. Do this:

Make a curl call to add a service, then run:

echo "use nagiosql; select id, service_description from tbl_service order by id desc limit 0,3;" | mysql -u root -p<yourpassword>

then do another curl call for a different service and run the same thing again. Post results.
Former Nagios employee
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: Bug in API

Post by jolson »

I attempted to recreate this bug in a test environment and could not do so - after adding the services via the API, they appeared properly in the Core Config Manager. After the configuration was applied, everything was written out properly. I figured I would throw my experience in here - could you post the API calls you used specifically?
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Bug in API

Post by BanditBBS »

jolson wrote:I attempted to recreate this bug in a test environment and could not do so - after adding the services via the API, they appeared properly in the Core Config Manager. After the configuration was applied, everything was written out properly. I figured I would throw my experience in here - could you post the API calls you used specifically?
I have to agree, it works flawlessly from cli, as I tested many times after Trevor's reply. I'm VPN'd into work and going to debug this until I find the cause or the solution. My php is good, so it is really confusing me as to why its doing it. The only thing different between it and cli is the php is being called from within XI itself in a component. I'm going to hardcoded some variables and run the php from cli and verify that it is good. When that is proven, then will try it with everything hardcoded and from component again and see if it doesn't work. I'll be updating this thread :)
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Bug in API

Post by BanditBBS »

Ok, here is the code output:

Code: Select all

Everything worked, adding to NagiosXI..... 
Host : OK : { "success": "Successfully added test667 to the system. Config imported but not yet applied." } 
Load : OK : { "success": "Successfully added test667 :: Load to the system. Config imported but not yet applied." } 
CPU : OK : { "success": "Successfully added test667 :: CPU to the system. Config imported but not yet applied." } 
Disk : OK : { "success": "Successfully added test667 :: Disk to the system. Config imported but not yet applied." } 
Cron : OK : { "success": "Successfully added test667 :: Cron Scheduler to the system. Config imported but not yet applied." } 
/var/log/messages : OK : { "success": "Successfully added test667 :: Log File to the system. Config imported but not yet applied." } 
Memory : OK : { "success": "Successfully added test667 :: Memory to the system. Config imported but not yet applied." } 
NFS : OK : { "success": "Successfully added test667 :: NFS to the system. Config imported but not yet applied." } 
Read Only FS : OK : { "success": "Successfully added test667 :: Read-Only File System to the system. Config imported but not yet applied." } 
Swap : OK : { "success": "Successfully added test667 :: Swap to the system. Config imported but not yet applied." } 
Total Procs : OK : { "success": "Successfully added test667 :: Total Processes to the system. Config imported but not yet applied." } 
Zombie Procs : OK : { "success": "Successfully added test667 :: Zombie Processes to the system. Config imported but not yet applied." } 
That is the same output no matter if it works or not. I found a work around to make it work and can take a pretty good guess at what is causing the problem.

The Issue: Only the host and the 11th service was being added even though I got success on all 11 services. They are configured in the php and 12 curl statements one right after another, so firing off very quick(and all receiving the success).
The fix: Add a "sleep(3);" between each curl(api call). The host and all 11 services are then added to database.
The observation: Change the sleep to 2 instead of 3 and only half the items get added to database even though all return with success. There is some issue hitting the API to quickly, even though it returns success.

So I can work around the issue by slowing the script down by a total of 30+ seconds and probably will change the sleep to a 4 just to be safe. Hate to do it, but looks like it is needed.

Edit: Created bug report - 766
Last edited by BanditBBS on Wed Oct 28, 2015 1:01 pm, edited 1 time in total.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Bug in API

Post by lmiltchev »

I was able to recreate the issue and I will do some more digging into it (before filing a bug report). I thought I could use a "workaround"... I used "applyconfig=0" in all of my commands and "applyconfig=1" in the last one. This didn't work however - the effect was the same - only the last service was added. When I used "sleep 5", all of the 10 services were added. I am waiting on a feedback from our developers.
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: Bug in API

Post by lmiltchev »

Update: I just submitted an internal bug report (TASK ID 6598).
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Bug in API

Post by BanditBBS »

You guys are going to hate this post, so, sorry in advance!

I just saw http://tracker.nagios.com/view.php?id=766 was marked as fixed in 5.2.1. Any ETA on arrival of this awesome bugfix version? :) This bug is the only thing slowing me down from automating adding of newly deployed hosts here, something that really needs to get done.

Delete this if you want, I just had to ask, lol!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Bug in API

Post by tmcdonald »

You are going to hate this response, so, not sorry in advance!

No idea :) Up to the devs, I was pushing for as close to weekly or tweekly (my word for "every two weeks" since "bi-weekly" means different things depending on who you ask) but that did not happen. Soon? It'll be soon.
Former Nagios employee
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Bug in API

Post by BanditBBS »

This bug is still present in 5.2.1. I just added a host with 11 services and only the host and 7 of the services were added, even though all 11 got the success message.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
Locked