Notification by Email

mail at catsnest.co.uk mail at catsnest.co.uk
Fri Feb 11 17:02:48 CET 2011


Sorry for top posting...

What command are you using for the notification? / How are you sending
these mails?

We originally used a simple one like this...
which just 'echos' text in to the mail command
=============================================
# 'notify-by-email' command definition
define command{
        command_name    customer-notify-by-email
        command_line    /bin/echo "To: $CONTACTEMAIL$\n\
Subject: $SERVICESTATE$ alert for $HOSTNAME$/$SERVICEDESC$\n\
\n\
\n\
 application=\"Nagios\"\n\
 node=\"$HOSTNAME$\"\n\
 type=\"$NOTIFICATIONTYPE$\"\n\
 service=\"$SERVICEDESC$\"\n\
 criticality=\"$_SERVICECRITICALITY$\"\n\
 service status=\"$SERVICESTATE$\" (for $SERVICEDURATION$)  last time
it was \"$LASTSERVICESTATE$\"\n\
 message=\"$SHORTDATETIME$ - $SERVICEDESC$ on $HOSTNAME$
$SERVICESTATE$ - $SERVICEOUTPUT$ - $TOTALSERVICESCRITICAL$ services
critical in total\"\n\
 msg=\"$LONGSERVICEOUTPUT$\"\n\
 checked using=\"$SERVICECHECKCOMMAND$\"\n\
" | /usr/bin/mail $CONTACTEMAIL$
}
=============================================



Then went for a neater solution that work work across our different platforms
this sends the arguments from nagios in to a wrapper scrip for mail...
=============================================
# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /etc/nagios/global/commands/nagios-mailx.sh -t
$CONTACTEMAIL$ -s "$SERVICESTATE$ Service Alert:
$HOSTNAME$/$SERVICEDESC$" -y "$NOTIFICATIONTYPE$" -m "***** Nagios
*****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService:
$SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState:
$SERVICESTATE$\nCriticality: $_SERVICECRITICALITY$\n\nDate/Time:
$LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nSee:
$_SERVICENAGIOS_URL$host=$HOSTNAME$&service=$SERVICEDESC$\n\nCommand:
$SERVICECHECKCOMMAND$"
=============================================

===========================================================================
cat /etc/nagios/global/commands/nagios-mailx.sh
#!/bin/sh
#script to send mail for nagios
#this should work on mutiple OS's


PROGNAME=`/bin/basename $0`
PRINTF='/usr/bin/printf'


find_mailx() {
        #find a version of mailx
        if [ -x /bin/mailx ] ; then
                MAILX='/bin/mailx'
        elif [ -x /usr/bin/mailx  ] ; then
                MAILX='/usr/bin/mailx'
        fi
}


print_usage() {
    echo "Usage: $PROGNAME -s subject -t to: address -m \"message text"
    echo "Usage: $PROGNAME --help"
}

print_help() {
    print_revision $PROGNAME
    echo ""
    print_usage
    echo ""
    echo "a script to send mail for Nagios"
    echo ""
    support
}

# Make sure the correct number of command line
# arguments have been supplied

if [ $# -lt 6 ]; then
    print_usage
    exit 1
fi

find_mailx
type=''

while getopts "s:t:m:y:h" flag
do
    case $flag in
        h)
            print_help
            exit 0
            ;;
        y)
            type=$OPTARG
            ;;
        s)
            subject=$OPTARG
            ;;
        t)
            sendTo=$OPTARG
            ;;
        m)
            msgText=$OPTARG
            bodyText=`$PRINTF "%b\n" "$msgText"`
            ;;
        *)
            print_usage
            exit $STATE_UNKNOWN;
            ;;
    esac;
done

if [ -n "${type}" ] && [ "${type}" != '$' ]; then
        subject="${subject} [${type}]"
fi

$MAILX -s "$subject"  $sendTo << MAILBODY
$bodyText
MAILBODY
===========================================================================

Ritchie,
--
Fnord...
<-- http://23.me.uk --> <-- http://wiki.s23.org --> <--
http://twitter.com/23me -->
<- -Only the lavender prairie dogs know the key to unlock the secret
of the tumble-weeds. -->



On Fri, Feb 11, 2011 at 11:57 AM, Andre Kruger <Andre.Kruger at trw.com> wrote:
> I have tried replacing my "&" with %26 , but that does not work. The %26
> shows in my Notification email but then the link does not work as expected.
>
> Next I tried the \ escape character, but then when I receive the
> notification email the "b" of "...&body=..." is gone.
>
> I am not sure about the escape_html_tags as this is the configuration for
> the Nagios web interface and I don't believe it would have any impact on
> Notifications sent out from Nagios
>
>>>> Yueh-Hung Liu <yuehung.liu at gmail.com> 2011/02/11 13:20 >>>
> maybe "escape_html_tags" in CGI configuration file?
>
>
> On Fri, Feb 11, 2011 at 6:56 PM, Andre Kruger <Andre.Kruger at trw.com> wrote:
>> I would try an escape key if I knew what it was. Any idea?
>>
>> It just seems strange to me that from Nagois on the way to Postfix the "&"
>> is dumped somewhere along the way.
>>
>>>>> <mail at catsnest.co.uk> 2011/02/11 12:35 >>>
>> On Fri, Feb 11, 2011 at 9:33 AM, Andre Kruger <Andre.Kruger at trw.com>
>> wrote:
>>> Hi
>>>
>>> I have a problem getting my status detail sent (correctly) via email. Let
>>> me
>>> explain. If I look at Nagios self and I look at the status detail for a
>>> printer that I monitor I see the following, which is correct BTW:
>>>
>>>
>>>
>>> service at kyocera.co.za?subject=Toner%20Order&body=Hi%20Nadia%0A%0AModel:%20KM-C3225%0AAsset#:%20"UAD6X01096"%0AMono:%2088108%20Colour:%20148705%0AColour%20Required:%20Magenta%0A%0ARegards%0AAndre
>>>
>>> If you copy and paste that link into word and you click it you will see
>>> that
>>> it populates the entire email for you and you just have to hit send. Now
>>> when this service goes into critical (like I have done here to test) it
>>> send
>>> me an email, but this is where the problem comes in. When I get my email
>>> the
>>> "&" is missing from the above link and then it does not work properly.
>>> Somewhere Nagios removes it and I have no clue where. I have sent a test
>>> mail from a shell on my Nagios machine as follows:
>>>
>>> /usr/bin/printf "Body&Text" | /bin/mail -s "Subject"
>>> andre.kruger at trw.com.
>>>
>>> When I receive this mail it still has the "&" in the body. So I am making
>>> the assumption that somewhere between Nagios and Postfix when it send the
>>> notification the "&" is removed. Can somebody please shed some light on
>>> this?
>>
>>
>>
>> try escaping or html encoding the #
>>
>>>
>>> Regards
>>> Andre
>>>
>>> P Please consider your environmental responsibility before printing this
>>> e-mail or any other document. Ask yourself whether you need a hard copy.
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
>>> Pinpoint memory and threading errors before they happen.
>>> Find and fix more than 250 security defects in the development cycle.
>>> Locate bottlenecks in serial and parallel code that limit performance.
>>> http://p.sf.net/sfu/intel-dev2devfeb
>>> _______________________________________________
>>> Nagios-users mailing list
>>> Nagios-users at lists.sourceforge.net
>>> 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
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
>> Pinpoint memory and threading errors before they happen.
>> Find and fix more than 250 security defects in the development cycle.
>> Locate bottlenecks in serial and parallel code that limit performance.
>> http://p.sf.net/sfu/intel-dev2devfeb
>> _______________________________________________
>> Nagios-users mailing list
>> Nagios-users at lists.sourceforge.net
>> 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
>>
>> P Please consider your environmental responsibility before printing this
>> e-mail or any other document. Ask yourself whether you need a hard copy.
>>
>> ------------------------------------------------------------------------------
>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
>> Pinpoint memory and threading errors before they happen.
>> Find and fix more than 250 security defects in the development cycle.
>> Locate bottlenecks in serial and parallel code that limit performance.
>> http://p.sf.net/sfu/intel-dev2devfeb
>> _______________________________________________
>> Nagios-users mailing list
>> Nagios-users at lists.sourceforge.net
>> 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
>>
>
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> 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
>
>
> P Please consider your environmental responsibility before printing this
> e-mail or any other document. Ask yourself whether you need a hard copy.
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> 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
>

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
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





More information about the Users mailing list