Boeckman, Matthew wrote:
> Hello list!
> 
> Is there a way to configure a custom notification email for
> acknowledgements? What I have currently is a lightly modified version of
> notify-host-by-email and notify-service-by-email to include the ACK
> macro's:
> 
> 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\n
> $HOSTACKAUTHOR$ ack'd the alarm with message
> $HOSTACKCOMMENT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "**
> $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
> $CONTACTEMAIL$
>         }
> 
> This works, but of course my text "ack'd the alarm with message" appears
> in all types of notifications with nothing in the macro fields, and for
> ACK's it works just fine. 
> 
> I'm wondering if there is something do-able like notify-ack-by-email
> that would only function on NOTIFICATIONTYPE=ACKNOWLEDGEMENT and thus
> use a specific printf statement about the ack. I see how I could
> configure another command definition and include it, but I'm not clear
> how to do the IF-THEN type logic. 
> 
> Any pointers are appreciated, thanks!
> 

I use an external sh script (see attachment). It's called without arguments 
(taking
advantage of nagios 2.x exporting of macros to the environment) like so:

define command {
        command_name notify-by-email
        command_line $USER3$/notify-by-email.sh
}

I use the same script for all notification and generate the contents based on 
the presence
of certain macros -> env variables. The script could probably be better, but 
it's working
for me ATM.

-- 
Russell A. Jackson <[EMAIL PROTECTED]>
Network Analyst
California State University, Bakersfield

Don't make a big deal out of everything; just deal with everything.
#!/bin/sh
#
# $Id$

NAGIOSHOST=nagios.domain
NAGIOSCGIURL="https://${NAGIOSHOST}/cgi-bin/cmd.cgi";

tmpfile=$(mktemp /tmp/$$.XXXXXX)
exec > $tmpfile

host_info() {
        printf "Host:\t\t$NAGIOS_HOSTNAME\n"
        printf "Address:\t$NAGIOS_HOSTADDRESS\n"

        if [ "$NAGIOS_SERVICEDESC" ]; then
                printf "Service:\t$NAGIOS_SERVICEDESC\n"
        fi
}

state_info() {
        printf "State:\t\t"
        if [ "$NAGIOS_SERVICESTATE" ]; then
                printf "$NAGIOS_SERVICESTATE"
        elif [ "$NAGIOS_HOSTSTATE" ]; then
                printf "$NAGIOS_HOSTSTATE"
        fi
        printf "\n"
}

state_detail() {
        if [ "$NAGIOS_SERVICEOUTPUT" ]; then
                printf "$NAGIOS_SERVICEOUTPUT"
        elif [ "$NAGIOS_HOSTOUTPUT" ]; then
                printf "$NAGIOS_HOSTOUTPUT"
        fi
        printf "\n"
}

alert_ack_url() {
        printf "Acknowledge this alert:\n\n"
        if [ "$NAGIOS_SERVICEDESC" ]; then
                printf 
"\t${NAGIOSCGIURL}?cmd_typ=34&host=${NAGIOS_HOSTNAME}&service=${NAGIOS_SERVICEDESC}\n"
        else
                printf "\t${NAGIOSCGIURL}?cmd_typ=33&host=${NAGIOS_HOSTNAME}\n"
        fi
}

ack_info() {
        printf "Who:\t\t"
        if [ "$NAGIOS_SERVICEACKAUTHOR" ]; then
                printf "$NAGIOS_SERVICEACKAUTHOR"
        elif [ "$NAGIOS_HOSTACKAUTHOR" ]; then
                printf "$NAGIOS_HOSTACKAUTHOR"
        fi
        printf "\n\n"
        
        if [ "$NAGIOS_SERVICEACKCOMMENT" ]; then
                printf "$NAGIOS_SERVICEACKCOMMENT"
        elif [ "$NAGIOS_HOSTACKCOMMENT" ]; then
                printf "$NAGIOS_HOSTACKCOMMENT"
        fi
        printf "\n"
}

case "$NAGIOS_NOTIFICATIONTYPE" in
        PROBLEM|FLAPPINGSTART)
                TAG="ALERT"

                if ! [ "$NAGIOS_CONTACTPAGER" ]; then
                        host_info
                        printf "\n"
                        state_info
                        printf "\n"
                fi

                state_detail

                if ! [ "$NAGIOS_CONTACTPAGER" ]; then
                        printf "\n"
                        alert_ack_url
                fi
        ;;

        RECOVERY|FLAPPINGSTOP)
                TAG="OK"

                if ! [ "$NAGIOS_CONTACTPAGER" ]; then
                        host_info
                        printf "\n"
                        state_info
                        printf "\n"
                fi

                state_detail
        ;;

        ACKNOWLEDGEMENT)
                TAG="ACK"
                
                if ! [ "$NAGIOS_CONTACTPAGER" ]; then
                        host_info
                        printf "\n"
                fi

                ack_info
        ;;

        *)
                echo "invalid notification type" > /dev/stderr
                exit 1
        ;;
esac

if [ "$NAGIOS_CONTACTEMAIL" ]; then
        recipient="$NAGIOS_CONTACTEMAIL"
elif [ "$NAGIOS_CONTACTPAGER" ]; then
        recipient="$NAGIOS_CONTACTPAGER"
else
        [EMAIL PROTECTED]
fi

subject="[${TAG}] ${NAGIOS_HOSTNAME}"
if [ "$NAGIOS_SERVICEDESC" ]; then
        subject="${subject}/${NAGIOS_SERVICEDESC}"
fi

if [ "$NAGIOS_SERVICESTATE" ]; then
        subject="${subject} ${NAGIOS_SERVICESTATE}"
elif [ "$NAGIOS_HOSTSTATE" ]; then
        subject="${subject} ${NAGIOS_HOSTSTATE}"
fi

mail -s "$subject" "$recipient" < $tmpfile
rm -f $tmpfile

exit 0

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nagios-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

Reply via email to