Object file management and structure

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
gossamer
Posts: 20
Joined: Wed Jul 13, 2011 9:56 pm

Object file management and structure

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Object file management and structure

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gossamer
Posts: 20
Joined: Wed Jul 13, 2011 9:56 pm

Re: Object file management and structure

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Object file management and structure

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gossamer
Posts: 20
Joined: Wed Jul 13, 2011 9:56 pm

Re: Object file management and structure

Post 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  }
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Object file management and structure

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gossamer
Posts: 20
Joined: Wed Jul 13, 2011 9:56 pm

Re: Object file management and structure

Post by gossamer »

Ah, I wasn't aware you could do that. Looks like that fixed it, thanks. I'll continue to experiment.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Object file management and structure

Post by scottwilkerson »

Sounds good!
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked