Page 1 of 2

nagiosql api

Posted: Thu Jul 10, 2014 2:45 pm
by anil406
Hello, Do we have any api that interacts with nagiosql. I am planning to write a bootstrap script that talks to nagios via api and adds the host during bootstrap process for the new machines. Any Ideas?

Re: nagiosql api

Posted: Thu Jul 10, 2014 3:31 pm
by technick
I know of three solutions to this and none of them involve a fancy API and I can only recommend one of them.

Have your bootstrap process create and manage static files in the /usr/local/nagios/etc/static directory. My organization is currently doing this with Ansible on provisioning / de-provisioning of AWS resources and its working out great.

The alternative to this is writing your config files into the /usr/local/nagios/etc/import file and there is a script that will import anything found there into the database. I have not tested this but have seen it recommended on these boards before.

The other more sketchy unrecommended method is writing something that will do the SQL inserts into the MySQL database and manage the row linking but that might cause more headache than its worth.

Re: nagiosql api

Posted: Fri Jul 11, 2014 9:20 am
by tmcdonald
We have an API, but at the moment it only deals with querying and not editing:

http://assets.nagios.com/downloads/nagi ... nd_API.pdf

Re: nagiosql api

Posted: Fri Jul 18, 2014 9:25 am
by anil406
Hello technik, Can you please elaborate on first solution?

Re: nagiosql api

Posted: Fri Jul 18, 2014 10:42 am
by tmcdonald
The static directory is used to store config files that Nagios should use but you do not want to appear in the CCM in XI. This makes it easy to script out changes to those files that will not be overwritten on an Apply Config. You still need to restart Nagios in order for the changes to be picked up, however (Apply Config does this as part of its routine).

Re: nagiosql api

Posted: Fri Jul 18, 2014 2:38 pm
by anil406
thanks donald, so what I understood from you post is that we need to restart the nagios to get static changes updated, however changes does not appear in XI, correct? if so any alternative method to get it updated in XI?

Re: nagiosql api

Posted: Fri Jul 18, 2014 9:28 pm
by Box293
anil406 wrote:however changes does not appear in XI, correct?
They won't appear in Core Configuration Manager but they will appear in the normal user interface.

Re: nagiosql api

Posted: Tue Jul 29, 2014 7:42 pm
by anil406
I built custom host and services file for test host and copied to hosts and services directories respectively and restarted the nagios, it works fine. however whenever we make changes to any other things using CCM, this is removing manually copied hosts/services cfgs. Is there a way to import these to CCM aswell?

Re: nagiosql api

Posted: Tue Jul 29, 2014 8:17 pm
by Box293
It is normal behaviour for Nagios XI to remove manually added config files when CCM applies it's settings.

If you want to import into Nagios XI, copy the custom host and service files you've created into:

Code: Select all

/usr/local/nagios/etc/import
Then in CCM:
  • Tools > Import Config Files
    Select your custom files in the list
    Click Import
    It should then tell you if it succeeded
    Now Apply Configuration

Re: nagiosql api

Posted: Wed Jul 30, 2014 9:28 am
by anil406
I tried to import, but when I click on import link it says cannot connect to database. But nagios is running fine.