Custom macros in host definitions

Posted on the August 16th, 2008 under Life by Christian

Well, I was playing with the hostgroup inheritance earlier. One problem with that is, if you define a duplicate service Nagios is really unpredictable or rather inconsistent. Now, as Thomas Guyot-Sionnest told me, I should try custom macros for the check definition. So what I did was the following:

templates/host-windows.cfg

define host {
  name         generic-windows
  register     0
  _RDPPORT     3389
}

hostgroups/windows.cfg

define hostgroup {
  hostgroup_name          windows
  alias                   Windows Servers
  hostgroup_members       windows-terminal
}
 
define service {
  use                     generic-service
  check_command           check_tcp!$_HOSTRDPPORT$
  service_description     RDP
  hostgroup_name          windows
}

hosts/terminal1.cfg

define host {
  use                   generic-windows
  host_name             terminal1
  alias                 terminal1.barfoo.org
  address               10.0.0.250
  parents               barfoo-home
  hostgroups            windows-terminal
  _RDPPORT              3390
}

As you can see, the default RDP port is 3389 (as defined in the host template), but for some systems you might want to “change” the port (for example, if you’re having a citrix farm and you changed the RDP port to something else and still want to be able to check whether or not the RDP service is active), thus the check using the macro, and a single host redefining the macro, thus having a bit more flexibility.

Leave a Reply
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">