Environment Variables as Macros
Posted: Wed May 04, 2016 11:35 pm
Is there a way, in a notification command, to populate a macro with output or variable from a subshell?
The Nagios Core Document "Understanding Macros and How They Work": https://assets.nagios.com/downloads/nag ... acros.html describes using Macros as Environment Variables. I want to do the opposite.
The reason is that I want to do a lookup based on a host/service combination, derive a priority level to include with the notification, using something like:
mylookup | /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nPriority: $PRIORITY$ Host: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
where "mylookup" would populate $PRIORITY$.
Yes I can do this by writing a complete replacement notification script and I will likely do that but I am now wondering about whether this is possible. Hence this post.
So can it be done?
thanks,
CP
The Nagios Core Document "Understanding Macros and How They Work": https://assets.nagios.com/downloads/nag ... acros.html describes using Macros as Environment Variables. I want to do the opposite.
The reason is that I want to do a lookup based on a host/service combination, derive a priority level to include with the notification, using something like:
mylookup | /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nPriority: $PRIORITY$ Host: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
where "mylookup" would populate $PRIORITY$.
Yes I can do this by writing a complete replacement notification script and I will likely do that but I am now wondering about whether this is possible. Hence this post.
So can it be done?
thanks,
CP