Hello,
I have a bit of an unusual question. So I am putting together some Nagios servers, and they are going to be using version control to sync up the configs across multiple boxes. I am putting configs that I want to run on specific Nagios servers in a directory called /etc/nagios/<hostname>, where the hostname is the value you get when you run hostname on the server. In Nagios.cfg, I have a cfgdir definition set up for each server, with a script that runs and comments out all of the cfgdir entries except the one with the local host's hostname. This works ok, but is a bit messy for the version control aspect. It would be ideal if I could do something like cfgdir=/etc/nagios/$(hostname)/, because then I'd be able to just have 1 nagios.cfg config file to rule them all, and they'd get their appropriate directory dynamically when nagios daemon starts. But I haven't been able to figure out how to get nagios.cfg to recognize any system variables that could give me that. Does anyone have any ideas on how I could do this?
Can nagios.cfg use system variables?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Can nagios.cfg use system variables?
You can't do that but you can set it to something like /etc/nagios/hosts and then place all of your host configs in that directory named something like <hostname>.cfg
-
- Posts: 20
- Joined: Tue Oct 16, 2018 4:29 pm
Re: Can nagios.cfg use system variables?
I do use separate .cfg files for hosts being monitored, and I have them in separate directories, based on which server is monitoring them, like this:
/etc/nagios/nagios-main/backupserv.cfg
/etc/nagios/nagios-qingdao/qdad2.cfg
nagios-main has a cfgdir entry in nagios.cfg that points to only /etc/nagios/nagios-main, and nagios-qingdao has one that points only to /etc/nagios/nagios-qingdao. This way, backupserv is monitored only by nagios-main, and qdad2 is monitored only by nagios-qingdao.
I was just hoping that there would be a unified way to use the same nagios.cfg to allow each of these servers to be pointed only to their respective directory.
/etc/nagios/nagios-main/backupserv.cfg
/etc/nagios/nagios-qingdao/qdad2.cfg
nagios-main has a cfgdir entry in nagios.cfg that points to only /etc/nagios/nagios-main, and nagios-qingdao has one that points only to /etc/nagios/nagios-qingdao. This way, backupserv is monitored only by nagios-main, and qdad2 is monitored only by nagios-qingdao.
I was just hoping that there would be a unified way to use the same nagios.cfg to allow each of these servers to be pointed only to their respective directory.
Re: Can nagios.cfg use system variables?
You could leverage something like Chef, Ansible, Salt, Puppet, or similar systems. At which point, "their respective directory" exists as an environment-level attribute that gets plugged into a more general nagios.cfg file.MarkCampbell wrote:I was just hoping that there would be a unified way to use the same nagios.cfg to allow each of these servers to be pointed only to their respective directory.
Chef has a nagios cookbook that could accomplish this.
Last edited by mcapra on Wed Jan 23, 2019 11:12 am, edited 1 time in total.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Can nagios.cfg use system variables?
I don't know any way to accomplish it with that formatMarkCampbell wrote:I do use separate .cfg files for hosts being monitored, and I have them in separate directories, based on which server is monitoring them, like this:
/etc/nagios/nagios-main/backupserv.cfg
/etc/nagios/nagios-qingdao/qdad2.cfg
nagios-main has a cfgdir entry in nagios.cfg that points to only /etc/nagios/nagios-main, and nagios-qingdao has one that points only to /etc/nagios/nagios-qingdao. This way, backupserv is monitored only by nagios-main, and qdad2 is monitored only by nagios-qingdao.
I was just hoping that there would be a unified way to use the same nagios.cfg to allow each of these servers to be pointed only to their respective directory.