Nagios xi hostgroups definition

This support forum board is for support questions relating to Nagios xi, our flagship commercial network monitoring solution.
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Nagios xi hostgroups definition

Post by TSCAdmin »

Hello,

We are using Nagios xi 2009R1.3 and monitoring over 1500 hosts. This is how the host configuration looks

Code: Select all

define host {
        host_name                       server1
        use                             xiwizard_linuxserver_host
        address                         server1
        parents                         core-switch1
        max_check_attempts              3
        check_interval                  5
        retry_interval                  1
        notification_interval           60
        icon_image                      redhat.png
        statusmap_image                 redhat.png
        _xiwizard                       dh_linux_server
        register                        1
        }
and hostgroups are defined in hostgroups.cfg which I have to update manually by writing new file in import directory each time a host is added in a data centre. Since our servers are hosted in different data centres and are running different services a host can be a part of several hostgroups, e.g. linux-servers,linux-servers-datacentre1,linux-oracle-server etc.

I am planning to make our host configurations look something like following

Code: Select all

define host {
        host_name                       server1
        use                             xiwizard_linuxserver_host
        address                         server1
        parents                         core-switch1
        hostgroups                      linux-servers,linux-servers-datacentre1,linux-oracle-server
        .....
The reason I am trying to do this is that each time a new host is added I can just craft a configuration file with hostgroup information, place it in import directory and apply configuration; which would save time and efforts to update hostgroups.cfg file.

I was wondering what are the best practices that are followed while defining hostgroups.

Is there an easy way to achieve what I am trying to do?

On a side note, my understanding to update files is this:

1. copy host files in import directory
2. add hostgroup information in each file
3. apply configuration

Is that correct?
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Nagios xi hostgroups definition

Post by mguthrie »

Just a note on this: The import directory and import procedure is not intended to be used for configuration changes. It's designed to be an initial import tool, and although it works to dump files into the import directory, I wouldn't recommend it.

With that many hosts, I would consider some of the following options.

- Instead of making changes to any of your existing hosts, I definitely go the route of adding or modifying a template that has all of your hostgroup information. You can create a template where the only config directive in it is hostgroup information.
- OR, you could also just create new hostgroups, and then from the CCM, add assign hosts to it from the Configure->Core Config Manager->Hostgroups page. With 1500 hosts you really don't want to have the assignments in the individual host files.

Take a look at the following doc, it's not the lightest read ever, but it gives some good suggestions for larger configurations. Almost all of these tips can be done through the Core config manager except for exclusions.
http://nagios.sourceforge.net/docs/3_0/ ... tance.html
http://nagios.sourceforge.net/docs/3_0/ ... ricks.html

My personal recommendation is to make as much use of templating as possible. That way if you have to make a mass change in the future it will only be a change to one template instead of a change to 500 hosts.
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Re: Nagios xi hostgroups definition

Post by TSCAdmin »

Hello Mike,

Thank you for your swift response.
mguthrie wrote:Just a note on this: The import directory and import procedure is not intended to be used for configuration changes. It's designed to be an initial import tool, and although it works to dump files into the import directory, I wouldn't recommend it.
When I used Nagios Core we just manually edited the host configuration file, restarted Nagios Core and the changes were applied. What is the best way to make changes in a configuration file, using Nagios xi, if not import directory? Does it work the same way as Nagios Core?
mguthrie wrote:- Instead of making changes to any of your existing hosts, I definitely go the route of adding or modifying a template that has all of your hostgroup information. You can create a template where the only config directive in it is hostgroup information.
This options sounds good to me but would it be possible for you to expand a little bit more on this, with any working example, if that's not much of a hassle?
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Nagios xi hostgroups definition

Post by mguthrie »

If you want to manually maintain any or all config files as you did with Core, you can place them under the /usr/local/nagiosxi/etc/static directory. The Core Config Manager will not do anything to manage or modify these files.

Here's a basic example.
If you're using straight config files, they would look like this:

Code: Select all

define host {
        host_name                       server1
        use                             xiwizard_linuxserver_host,hostgroups_template
        address                         server1
        parents                         core-switch1
}

##template 
define host {
        name                              hostgroups_template
        hostgroups                      linux-servers,linux-servers-datacentre1,linux-oracle-server
        register                           0 
}
OR, you can also manage hostgroup assignments from the hostgroup config. If you want to do this from the GUI, just access the Core Config Manager->Hostgroups page.

Code: Select all

define hostgroup {
        hostgroup_name    linux-servers
        members              hosta,hostb,hostc,hostd,hoste,hostf,hostg

}
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Re: Nagios xi hostgroups definition

Post by TSCAdmin »

Hello Mike,

If we are using the first method and we are creating hostgroups_template, what is the easiest way to add this to massive number of host configuration files?

Let's say I have created five different hostgroups templates and there are 200 servers for each hostgroup type, how will I be adding that information to each host configuration file amending "use" directive?

Please let me know if it sounds confusing.

Many thanks
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Nagios xi hostgroups definition

Post by mguthrie »

That depends on if these groups are using existing common templates. If they are, you can add the relationship to the templates. However, if there isn't a template difference in the groups that you need to separate, then that might be something to consider as well for faster large group host management. Otherwise, without the template assignments already in place, there isn't necessarily a speedy way to create this initial setup.
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Re: Nagios xi hostgroups definition

Post by TSCAdmin »

Unfortunately we have only one template defined for each type of platform, e.g. xiwizard_linuxserver_host for Linux hosts, xiwizard_windowsserver_host for Windows hosts.

Coming back to the question, would it mean that we have to manually edit each host file (or script it) and append hostgroup template information in their use directive?

Everything is reasonable, if my understanding is correct on above mentioned part, till this point.

My major question is how do I bring this change into effect. Edit each file and put it in import directory and then from CCM -> import configuration -> apply configuration or are there any other ways?

I tried making configuration change directly into host file and restart Nagios just like I did in Nagios Core. The changes were not applied.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Nagios xi hostgroups definition

Post by mguthrie »

Edit each file and put it in import directory and then from CCM -> import configuration -> apply configuration or are there any other ways?
I strongly advise against maintaining configs this way. The import process is for new configs, not modifications.
I tried making configuration change directly into host file and restart Nagios just like I did in Nagios Core. The changes were not applied.
Yeah, unless you place your files in the /usr/local/nagios/etc/static directory, the Core Config Manager will just overwrite any changes next time an "Apply Configuration" occurs.

Based on what you're describing, I would actually consider just creating new hostgroups, and then bulk assigning members from the Configure->Core Config Manager->Hostgroups page. This will be much easier to implement on the existing install and shouldn't take very long.
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Re: Nagios xi hostgroups definition

Post by TSCAdmin »

Hello,

So I was moving my hostgroups file to static directory.

This is what I did:

1. Deleted all hostgroups from CCM (because of the error mentioned below)
2. Deleted hostgroup information from all host files
3. Edited nagios.cfg to add cfg_file=/usr/local/nagios/etc/static/hostgroups.cfg and remove old cfg_file directive (etc/hostgroups.cfg)
4. Created new hostgroups.cfg file in static directory
5. Applied configuration

But after configuration was applies successfully it created a hostgroups.cfg file in etc directory automatically. No matter how many times I remove it, it will be there again after apply configuration step.

I added hostgroup blocks in the static/hostgroups.cfg and get the following error:


Warning: Duplicate definition found for hostgroup 'windows-servers-turnford' (config file '/usr/local/nagios/etc/static/hostgroups.cfg', starting on line 1)
Error: Could not add object property in file '/usr/local/nagios/etc/static/hostgroups.cfg' on line 2.
Error processing object config files!

Now I have the following queries:

1. How do I prevent Nagios xi from recreating hostgroups.cfg in etc directory
2. How do I add hostgroup information in static/hostgroups.cfg

Thank you in advance.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Nagios xi hostgroups definition

Post by mguthrie »

1. How do I prevent Nagios xi from recreating hostgroups.cfg in etc directory
You probably can't, but you don't need to. As long as you don't define any hostgroups through the Core Config Manager, this file will just be empty.
How do I add hostgroup information in static/hostgroups.cfg
First thing: remove what you did below:
3. Edited nagios.cfg to add cfg_file=/usr/local/nagios/etc/static/hostgroups.cfg and remove old cfg_file directive (etc/hostgroups.cfg)
Everything under the static directory will automatically be included, so I'm betting this is the source of the duplicate definition.

If you still get a config error from that file, take a look at the syntax for hostgroup configs.
http://nagios.sourceforge.net/docs/3_0/ ... #hostgroup