It looks like some macros have been dropped between Icinga1 and Icinga2?
For example, I can only add "HOSTDURATIONSEC" = "$host.duration_sec$",
to my template to then use it in the mail-host-notification
script like: State: $HOSTSTATE for $HOSTDURATIONSEC
which tells me how long the host has been in that state. But it only gives me seconds and that's not very helpful at a glance when receiving alerts.
Because HOSTDURATION
is no longer available or not yet implemented, I've tried converting the seconds to something more readable using functions and other bash attempts within that mail-host-notification
but it doesn't seem to work.
I'd like to be able to create a new variable in that script maybe using a command from a linux package timetrans like this:
#!/bin/sh
SECS=$HOSTDURATIONSEC
CONVERTSECONDS=`timetrans -c $SECS`
eval $CONVERTSECONDS
$HRTIME=`eval $CONVERTSECONDS`
template=`cat <<TEMPLATE
Date/Time: $SHORTDATETIME (EST)
Notification Type: $NOTIFICATIONTYPE
Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $HOSTSTATE for $HRTIME
------------------------------------------
New Jersey DC Icinga Monitoring
Additional Info: $HOSTOUTPUT
Notes on this device:
$HOSTNOTES
Comments: $NOTIFICATIONAUTHORNAME $NOTIFICATIONCOMMENT
TEMPLATE
`
...but like the attempts I've tried using functions to convert the seconds variable $HOSTDURATIONSEC
, it's not working. I'm tried in many ways, but it seems to me that Icinga isn't passing those env
's set in the template.
env = {
"NOTIFICATIONTYPE" = "$notification.type$"
"HOSTALIAS" = "$host.display_name$",
"HOSTADDRESS" = "$address$",
"HOSTSTATE" = "$host.state$",
"HOSTNOTES" = "$host.notes$",
"HOSTDURATIONSEC" = "$host.duration_sec$",
"LONGDATETIME" = "$icinga.long_date_time$",
"SHORTDATETIME" = "$icinga.short_date_time$",
"HOSTOUTPUT" = "$host.output$",
"NOTIFICATIONAUTHORNAME" = "$notification.author$",
"NOTIFICATIONCOMMENT" = "$notification.comment$",
"HOSTDISPLAYNAME" = "$host.display_name$",
"USEREMAIL" = "$user.email$"
}
Of course, anything I added to this list like "SHORTDATETIME" = "$icinga.short_date_time$",
, "HOSTNOTES" = "$host.notes$",
, etc. are working, but I'm having trouble trying to run linux commands against those variables in the script. Am I missing something? Anyone know where I'm going wrong? Any/All help is appreciated.