Page 1 of 1

Question regarding hosts & hostgroups

Posted: Tue Dec 17, 2019 5:33 pm
by IT-Biscuit
Hi.

Please pardon this newbie question as I am kind of weeding my way through a preconfigured Nagios setup configured by an admin that left the company. I 'think' I get the basics but not entirely sure.

From what I gather, nagios can be configured to look 'anywhere' for a host configuration file which is configured in nagios.cfg. In my previous post -- https://support.nagios.com/forum/viewto ... =7&t=56828 -- I initially lost my hosts and restored them by enabling a backup copy of nagios.cfg and disabling the initial primary copy which lead me to believe there was a mistake in nagios.cfg - and after searching for hours I figured out one of the

Code: Select all

cfg_file=
sources were hashed out and wasn't so on the backup copy. It was

Code: Select all

cfg_dir=/usr/local/nagios/etc/servers
I'm assuming that the previous admin used servers as another folder to store hosts in where I found two .cfg files containing host definitions - for the every machine on the network.

In the hostgroups folder, I found multiple .cfg's

Code: Select all

/usr/local/nagios/etc$ ls hostgroups
apps.cfg          peds.cfg               logs.cfg         board.cfg
closet.cfg        hex.cfg                 table.cfg       principal.cfg
colfax.cfg        principal.cfg         vm.cfg
and within Nagios itself there are multiple hostgroups corresponding similar to these filenames (although I realize the groups are defined within the contents of the files.)

So what I am thinking is, the hosts (machines, servers, vm's, ect) are all defined in the servers folder under .cfg's that contain entries like this:

Code: Select all

define host {
        use                             linux-server
        host_name                       sw02
        alias                           sw02
        address                         x.x.x.x
        }
and those hosts are divided into groups in the hostgroups folder with .cfg's containing entries like this:

Code: Select all

define hostgroup {
  hostgroup_name  colfax
  alias           Colfax
}

define service{
        use                             local-service
        hostgroup_name                  colfax
        service_description             Current temperature
        check_command                   check_nrpe!check_temp
        notifications_enabled           1
        }
With additional services defined below that point...

...What I couldnt understand however is how Nagios know which host belongs to which hostgroup....

input?

Re: Question regarding hosts & hostgroups

Posted: Tue Dec 17, 2019 5:54 pm
by cdienger
The hostgroup definition can use the 'members' directive to add hosts to it:

https://assets.nagios.com/downloads/nag ... #hostgroup


OR service/host definitions can also use the 'hostgroup_name' directive to add itself to a hostgroup:

https://assets.nagios.com/downloads/nag ... .html#host
https://assets.nagios.com/downloads/nag ... ml#service

The example you provide is the later - the service definition 'Current temperature' adds itself tot he colfax group(using hostgroup_name).

Does this help clarify?