Add physical location to host and notification

Hi all,
Is there a way to add the physical location of a host to the hosts properties, and have that included on any e-mail notifications our administrators receive? We have about 50 locations, and all hosts are labelled by a site number, such as S14-DFCS01. When reading notification e-mails after-hours, looking up what site that is can be difficult.

Thanks!

This could be achieved by defining a custom host attribute under Setup → Hosts → Custom host attributes.

Example:

By selecting the last checkbox, the attribute can be used as a variable/macro in notifications.

4 Likes

Thanks for that. I was able to create a custom attribute for the location. I’ve been trying to figure out how to get the location included in our default notifications, any thoughts there?

In a notification script, the location should now be available in the environment variable $NOTIFY_HOST_LOCATION. At least with the CMC.

If you use the Nagios core, you need to edit the check-mk-notify command in ~/etc/nagios/conf.d/check_mk_templates.cfg. Insert a line like

NOTIFY_HOST_LOCATION='$_HOSTLOCATION$' \

in the variable definitions. After that change you need to restart Checkmk with cmk -R.

When using the predefined notification methods (e.g. HTML email or ASCII email), you can reference the custom attribute at some places. Example:

2 Likes

nice thread, searched something like this in the past.

tried it but doesn´t work. using raw edition, edit the check_mk_templates.cfg.

$_HOSTLOCATION$ resolved as CONTENT in notification mail…

Where comes the definition from, that $_HOSTLOCATION$ is the custom host attribute “Location”?

You need to dig a bit into Nagios configuration to track this.

When you edit a host object and enter a location in Checkmk, and activate your changes, Checkmk creates the file ~/etc/nagios/conf.d/check_mk_objects.cfg. Here, the content entered into the custom host attribute “location” is stored as _LOCATION within a host object. Example (shortened):

define host {
  _ADDRESS_4                    10.20.30.40
  _ADDRESS_FAMILY               4
  _FILENAME                     /wato/printer/hosts.mk
  _LOCATION                     My Office, 1st floor
  address                       10.20.30.40
  alias                         Brother MFC-L3750
  check_command                 check-mk-host-ping!-w 200.00,80.00% -c 500.00,100.00%
  host_name                     bromfc
  hostgroups                    printer
  use                           check_mk_host
}

The Nagios core makes the custom host attributes available as macros. From the Nagios documentation, chapter “Custom Variable Macros”:

Any custom object variables that you define in host, service, or contact definitions are also available as macros. Custom variable macros are named as follows:

  • $_HOSTvarname$
  • $_SERVICEvarname$
  • $_CONTACTvarname$

So in this case, the location information is available as macro _HOSTLOCATION.

2 Likes

That worked! Couldn’t figure out how to get it in the body of the e-mail, but I think it’s fine just as part of the subject. Good enough. Honestly, I’m really surprised this isn’t a built-in function by default when creating hosts.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.