Page 1 of 1
Duration readout in email notification
Posted: Mon Sep 17, 2018 10:40 am
by rkane
I am looking to include a readout of the duration in my email notifications. I've created an email template but do not see a variable for this. My commands (notify-host/service-by-email) appear to be formatted like the default template.
Here is what I would like to work:
%alertsummary%
Notification Type: %type%
Host: %host%
State: %hoststate% (%HOSTDURATION%)
Address: %hostaddress%
Info: %hostoutput%
Date/Time: %datetime%
Respond: %responseurl%
Nagios URL: %xiserverurl%
Here is what I get:
Nagios has detected a problem with this host.
Notification Type: PROBLEM
Host: CONF-1
State: DOWN (%HOSTDURATION%)
Address: CONF-1
Info: check_icmp: Failed to resolve CONF-1
Date/Time: 2018-09-17 10:11:29
Re: Duration readout in email notification
Posted: Mon Sep 17, 2018 11:15 am
by cdienger
The notification commands do not pass HOSTDURATION to the template default and must be updated under Configure > Core Config Manager > Commands > _Commands. Here you'll find the default notify-host-by-email, notify-service-by-email, xi_host_notification_handler, xi_service_notification_handler. Any of these can be edited accordingly but it should be noted that the templates are applied to notification commands that use handle_nagioscore_notification.php.
An update to the xi_host_notification_handler command would look like:
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$" --hostduration="$HOSTDURATION$"
Some more information on notifications in XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Re: Duration readout in email notification
Posted: Mon Sep 17, 2018 11:32 am
by rkane
Much appreciated, I've read that doc many times

So the variable needs to be made available in the handler as shown below. Can I then use Admin > Notification Management to invoke the variable on my email template? Or do I need to get into that PHP file?
Looking at notify-host-by-email, notify-service-by-email they are not a match for my email template...is there another command created when a custom email template is created?
cdienger wrote:The notification commands do not pass HOSTDURATION to the template default and must be updated under Configure > Core Config Manager > Commands > _Commands. Here you'll find the default notify-host-by-email, notify-service-by-email, xi_host_notification_handler, xi_service_notification_handler. Any of these can be edited accordingly but it should be noted that the templates are applied to notification commands that use handle_nagioscore_notification.php.
An update to the xi_host_notification_handler command would look like:
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$" --hostduration="$HOSTDURATION$"
Some more information on notifications in XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Re: Duration readout in email notification
Posted: Mon Sep 17, 2018 11:56 am
by rkane
That didn't work
rkane wrote:...So the variable needs to be made available in the handler as shown below. Can I then use Admin > Notification Management to invoke the variable on my email template? ...
cdienger wrote:The notification commands do not pass HOSTDURATION to the template default and must be updated under Configure > Core Config Manager > Commands > _Commands. Here you'll find the default notify-host-by-email, notify-service-by-email, xi_host_notification_handler, xi_service_notification_handler. Any of these can be edited accordingly but it should be noted that the templates are applied to notification commands that use handle_nagioscore_notification.php.
An update to the xi_host_notification_handler command would look like:
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$" --hostduration="$HOSTDURATION$"
Some more information on notifications in XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Re: Duration readout in email notification
Posted: Mon Sep 17, 2018 1:09 pm
by cdienger
The template is case sensitive - try using %hostduration%.
Re: Duration readout in email notification
Posted: Mon Sep 17, 2018 1:25 pm
by rkane
worked, case closed, thank you!
cdienger wrote:The template is case sensitive - try using %hostduration%.