Using Custom Variables in Email Notification or Host Alias?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
gregbeyer
Posts: 181
Joined: Fri Sep 11, 2020 2:13 pm

Using Custom Variables in Email Notification or Host Alias?

Post by gregbeyer »

Hello, I have two questions around using custom variables.

First, we have a custom variable (_role) set for our hosts which show the role it plays in the environment (database, storage, utility, etc.). When Nagios issues an alert, I would like to include that custom variable in the message.

I have included this variable in the email alert template in the format I believe it should be (below). However when the email is issued, it contains, literally, the string %_role%, rather than the content of the custom variable. Do I need a different syntax for custom variable than the standard variables which do come through as expected? I added %contactemail% to the template, and it comes thru fine.

***** Nagios XI Alert *****

%alertsummary%

Notification Type: %type%
Host: %host%
State: %hoststate%
Address: %hostaddress%
Info: %hostoutput%
Date/Time: %datetime%

Respond: %responseurl%
Nagios URL: %xiserverurl%

Node's Role: %_role%

Persons notified: %contactemail%

Second question, can I include custom variables in the host alias field? When looking at a long list of Host or Service Status it would be helpful for the viewer to, again, know the role of the host at a glance.
User avatar
lgute
Posts: 420
Joined: Mon Apr 06, 2020 2:49 pm

Re: Using Custom Variables in Email Notification or Host Alias?

Post by lgute »

Hi @gregbeyer, thanks for reaching out.

It sounds like you have already done step 1. Have you added the custom variable to the xi_host_notification_handler?
  1. Going by the "Custom Variable Macros" section of the Macros doc, the "Example" section of the Custom Object Variables doc, and because this is a HOST object variable, the _role custom variable should be available as the macro $_HOSTROLE$.
  2. Then in the Understanding Nagios XI Notification Variables doc, page 9, it shows how to add the $HOSTROLE$ macro to the xi_host_notification_handler's command line, so it is available as %_role%.
I believe you can include custom variables in a Host's alias field. Probably something like this...

Code: Select all

alias  ThisHostsAlias $_HOSTROLE$
I have not verified this, so please test, before changing all your hosts.
Please let us know if you have any other questions or concerns.

-Laura
gregbeyer
Posts: 181
Joined: Fri Sep 11, 2020 2:13 pm

Re: Using Custom Variables in Email Notification or Host Alias?

Post by gregbeyer »

Thanks for the info
Post Reply