Re: Nagios map setting issue 4.3.2
Posted: Thu Jun 28, 2018 9:00 am
The only way to have it both ways is to create your own custom notification script, and then change the message based on the value of $NOTIFICATIONTYPE$
Support for Nagios products and services
https://support.nagios.com/forum/
Much of this is way easier in Nagios XI and is configurable through the GUI, you may want to take that for a 60 day free trialCode: Select all
# 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\nComment: $NOTIFICATIONCOMMENT$ \n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } # 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n Comment : $NOTIFICATIONCOMMENT$ \n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ }
Code: Select all
#!/bin/bash
message=$(cat)
# your logic here to manipulate the message
echo $message | /usr/bin/mail -s "** $1 Host Alert: $2 is $3 **" $4Code: Select all
# 'your-custom-host-handler' command definition
define command{
command_name your-custom-host-handler
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\nComment: $NOTIFICATIONCOMMENT$ \n" | your-handler.sh "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$CONTACTEMAIL$"
}