etc/import creating duplicate services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gurkakrieg
Posts: 15
Joined: Mon Sep 09, 2013 5:43 pm

etc/import creating duplicate services

Post by gurkakrieg »

I'm using "/usr/local/nagiosxi/scripts/reconfigure_nagios.sh" to import new service configs into NagiosXI. The configs are defined in our "response-time.cfg" file, which contains a list of all of our webserver response checks. This grows over time, and we add new tests to this file, then copy the file into "/usr/local/nagios/etc/import" and run the "reconfigure" script. When we do this now, it creates duplicate entries in NagiosQL for services that were already defined. I thought the expected behavior was to overwrite existing entries.

Are we doing something wrong?

Here's an example of the configs we are importing:

Code: Select all

define service {
       use                               fdb-remote,fdb-active
       service_description       SOAP_FDBAllergenToExternalAllergen_Valid
       check_command            check-responsetime-soap!10000!10000!FDBAllergenToExternalAllergen_Valid!!!!!
}
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: etc/import creating duplicate services

Post by sreinhardt »

Do the imported configs differ from the configs currently existing in nagios? As a general rule, I would suggest against importing the same config multiple times if it can be avoided.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: etc/import creating duplicate services

Post by lmiltchev »

This is happening, because you are using a different config name while importing the config. For example, you have a file named "nagios.com.cfg" in the services directory, that you want to modify and re-import. You could do the following:

Code: Select all

cp /usr/local/nagios/etc/services/nagios.com.cfg /usr/local/nagios/etc/import/
Modify the file,

Code: Select all

vi /usr/local/nagios/etc/import/nagios.com.cfg
save, and exit. Run reconfigure:

Code: Select all

cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
This should work, and you shouldn't get any duplicates. However, if you save the file under a different name, you will get dups.

Code: Select all

cp /usr/local/nagios/etc/services/nagios.com.cfg /usr/local/nagios/etc/import/test.cfg
Modify the file,

Code: Select all

vi /usr/local/nagios/etc/import/test.cfg
save, and exit. Run reconfigure:

Code: Select all

cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
In this case, you will get duplicates.
Be sure to check out our Knowledgebase for helpful articles and solutions!
gurkakrieg
Posts: 15
Joined: Mon Sep 09, 2013 5:43 pm

Re: etc/import creating duplicate services

Post by gurkakrieg »

sreinhardt wrote:Do the imported configs differ from the configs currently existing in nagios? As a general rule, I would suggest against importing the same config multiple times if it can be avoided.
Originally, about 50% of the file was the same as the old file. The other 50% were new checks that we've added. My understanding was that the old configs would be overwritten with the same values, essentially leaving them the same. Is this incorrect?
lmiltchev wrote:This is happening, because you are using a different config name while importing the config. For example, you have a file named "nagios.com.cfg" in the services directory, that you want to modify and re-import. You could do the following:
I followed your steps, first copying the config (being sure not to change the filename):

Code: Select all

cp /usr/local/nagios/etc/services/response-time.cfg /usr/local/nagios/etc/import/
Then modifying the file to remove any duplicates. Finally, importing the file using

Code: Select all

/usr/local/nagiosxi/scripts/reconfigure_nagios.sh
After running this, "response-time.cfg" now has 4 of each configs. I believe this is one item per time that I've ran "reconfigure_nagios.sh". It looks to me like Nagios XI is maintaining the current list of services in memory and simply adding the output of the reconfigure command to whatever is in memory. Does this sound possible? Is there something I need to restart? The reason I'm going through with this is that we eventually want to use Chef to manage our configs and the plan was to use reconfigure_nagios.sh as our method of keeping our NagiosXI configs synchronized.

I dug around a bit and found a NagiosQL forum posting that shows this isn't going to work:
Basically NagiosQL is not designed to be used in that way.

The import function is designed to be used as first time import and to restore backup files if the database is corrupt.

While importing (and after edit an object with the gui), NagiosQL creates a HASH from that object to safely identify this configuration later.

For a service, this HASH is computed from any used host names, any used hostgroup names, the service description, the display name and the command name.

This means: if you change one of these values - the HASH will not be the same than stored in the database and so - for NagiosQL - this is a new object definition and not an existing.

Your other question: No, there is no functionality or trick to "batch delete" some objects from the database. You have to do this site by site in your GUI, but you can change the settings to show more than 15 lines and/or use the search function to hide some objects.

http://www.nagiosql.org/forum/general-q ... .html#3736
Thanks for you help. I think our go-forward plan will be to switch to static configs maintained through Chef.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: etc/import creating duplicate services

Post by sreinhardt »

that nagiosql post makes a lot of sense as to why some of this happens. I would agree either static configs or manage through the available APIs whichever you find easiest. If chef is already setup, that would make the most sense.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked