Seperate cfg file for hosts in core 4.0.7

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
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Seperate cfg file for hosts in core 4.0.7

Post by tariqondego »

Is it possible to have seperate files eg hosts.cfg,service.cfg,hostgroups.cfg etc,on core 4.0.7.?
I have just created a hosts.cfg and defined 'hostTest'.But I keep getting error 'Host hosTest cannot be found',when i restart nagios.
But when I define this host inside locahost.cfg it works ok.

I would like to have separate files for the hosts,services and hostgroups.

Please advise.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Seperate cfg file for hosts in core 4.0.7

Post by Box293 »

Yes this is possible.

In your nagios.cfg file you need to define the config files, for example:

Code: Select all

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Re: Seperate cfg file for hosts in core 4.0.7

Post by tariqondego »

Thanks alot!
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Seperate cfg file for hosts in core 4.0.7

Post by eloyd »

You can also use the "cfg_dir" directive to include *.cfg in a particular directory. And you can mix and match. Here's an example:

Code: Select all

cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_dir=/usr/local/nagios/etc/my_custom_configs
This means you can put your own commands.cfg and contacts.cfg and hosts.cfg and services.cfg or host_name.cfg in the my_custom_configs directory and Nagios will pick up those config files without having to specify them directly.

Don't need a file anymore (maybe for testing)? "mv my_custom_configs/file.cfg my_custom_configs/file.cfg.xxx" and it will no longer be loaded. XXX can be anything, so long as the file doesn't end in *.cfg
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
Locked