Page 1 of 1

Object file management and structure

Posted: Wed Jun 06, 2018 12:18 pm
by gossamer
Hi,
I have a fedora 27 system with nagios-4.3.4-3.fc27.x86_64 installed and I'm confused about how best to design the object config files that are used to store the service and host definitions.

Is it possible to define the config files based on the hostname?

The problem is that occasionally there are times when a host will go down for an extended period before I can mark it off-line, then not having a way for nagios to stop alerting me until the host can be brought back online again. A particular host may be offline for a day or longer.

I understand that once it's offline, it's not possible to mark it as offline or down for maintenance. I thought that by creating each host in its own config file that I could stop nagios, rename or move the file, then restart nagios without that host.

The problem I have is that some hosts overlap, such as with hostgroups where multiple hosts are connected.

Perhaps there's another way? Maybe I should just skip using hostgroups?

Re: Object file management and structure

Posted: Wed Jun 06, 2018 2:28 pm
by scottwilkerson
A common setup is to make sub directories for hosts/services and then name each .cfg in there the hosts name.cfg
Then you are correct that if you are going to assign services to hostgroups they need to go somewhere, I would place them in the services directory with a different naming structure.

The nice thing is, if you remove the host, it is already not going to be part of the hostgroup (especially if you add the hostgroups directive in the hosts .cfg file) and so it will already automatically be removed from the service that just had the hostgroup added.

Because of this flexability Nagios Core installations are like snowflakes, no 2 are the same.

Re: Object file management and structure

Posted: Wed Jun 06, 2018 2:46 pm
by gossamer
Hi, thanks for your help. However, I'm not sure I understand.

If a host is a member of a hostgroup, and that host is removed, it would also have to be removed from the hostgroup config file too, defeating the whole purpose of putting each host in a separate file.

In other words, here is one hostgroup example I have:

Code: Select all

define hostgroup {
        hostgroup_name  GDHQ
        alias           Home Base
        members         orion,mastermind,bwimail03
}
Hostgroups by nature contain more than one host. What if one of those hosts is the one I wish to take offline? Then not only do I have to move the host config files out of the way, I have to now edit this singular file, correct?

Is there no easier way?

It would be great if there was a config option through the main web interface to mark a server offline that's already down.

Re: Object file management and structure

Posted: Wed Jun 06, 2018 3:15 pm
by scottwilkerson
gossamer wrote:If a host is a member of a hostgroup, and that host is removed, it would also have to be removed from the hostgroup config file too
Not if you set it up ad follows

Code: Select all

define hostgroup {
        hostgroup_name  GDHQ
        alias           Home Base
        members         orion,mastermind,bwimail03
}
and

Code: Select all

define host {
	host_name			orion
	use					generic-host
	address			  1.1.1.1
	hostgroups		  GDHQ
	}	

define host {
	host_name			mastermind
	use					generic-host
	address			  2.2.2.2
	hostgroups		  GDHQ
	}	

define host {
	host_name			bwimail03
	use					generic-host
	address			  3.3.3.3
	hostgroups		  GDHQ
	}	
Where each of these host definitions can be in their own file.

Re: Object file management and structure

Posted: Wed Jun 06, 2018 3:27 pm
by gossamer
scottwilkerson wrote:
gossamer wrote:If a host is a member of a hostgroup, and that host is removed, it would also have to be removed from the hostgroup config file too
Not if you set it up ad follows

Code: Select all

define hostgroup {
        hostgroup_name  GDHQ
        alias           Home Base
        members         orion,mastermind,bwimail03
}
and

Code: Select all

define host {
	host_name			orion
	use					generic-host
	address			  1.1.1.1
	hostgroups		  GDHQ
	}	

define host {
	host_name			mastermind
	use					generic-host
	address			  2.2.2.2
	hostgroups		  GDHQ
	}	

define host {
	host_name			bwimail03
	use					generic-host
	address			  3.3.3.3
	hostgroups		  GDHQ
	}	
Where each of these host definitions can be in their own file.
Thank you, I've tried that, but it doesn't work. Nagios complains about missing host definitions (mastermind is the host with the separate config):

Code: Select all

Reading configuration data...
   Read main config file okay...
Error: Could not find any host matching 'mastermind' (config file '/etc/nagios/objects/hostgroups.cfg', starting on line 16)
Error: Could not expand members specified in hostgroup (config file '/etc/nagios/objects/hostgroups.cfg', starting on line 16)

Code: Select all

    16  define hostgroup {
    17          hostgroup_name  GDHQ
    18          alias           Home Base
    19          members         orion,mastermind,bwimail03
    20  }

Re: Object file management and structure

Posted: Wed Jun 06, 2018 3:33 pm
by scottwilkerson
My apologies, I meant to modify the hostgroup

It should be this

Code: Select all

define hostgroup {
        hostgroup_name  GDHQ
        alias           Home Base
}
With the members removed. The member get added through the directive in the host object.

Re: Object file management and structure

Posted: Wed Jun 06, 2018 3:57 pm
by gossamer
Ah, I wasn't aware you could do that. Looks like that fixed it, thanks. I'll continue to experiment.

Re: Object file management and structure

Posted: Wed Jun 06, 2018 4:43 pm
by scottwilkerson
Sounds good!