Define Variables in Nagios Config

nagios

To kill some possible confusion right form the start, I'm not looking to define me own fields within host definitions, but instead to create a variable that I can use across multiple host definitions to fill in one of the standard fields.

When I add a VM to our Nagios server I add the machines in our virtualisation cluster as the parents of that machine, because if any one of those servers is up, the VM should be accessible. This results in an entry in the definition of each VM of the form:

define host{
        host_name               xxx1
        alias                   xxx1.domain.tld
        address                 xxx.xxx.xxx.xxx
        parents                 dom0_1, dom0_2, dom0_3, dom0_4, dom0_5, dom0_6
        ...
}

The thing is, our cluster keeps changing and expanding, and it's a pain in the backside to have to update this entry in every VM, I want to be able to change it in just one place, and have that change affect the definitions for all our VMs.

Best Answer

Agree with using templates but you need a slight different syntax for templating. A template is a host/service definition with "register 0" added, then you inherit the template in the actual host definition with use, don't forget to inherit the system default-host in your new template

define host {
  name host-template1
  use generic-host
  parents dom0_1,dom0_2
  register 0
 }

 define host {
   use host-template1
   host_name .....
   ....
  }