Host/Service ACK's Notifications
Kyle Tucker
kylet at panix.com
Wed Mar 22 15:26:14 CET 2006
>
> A follow up to this is that I found a Macro "$NOTIFICATIONTYPE$". The
> problem is I don't want this Macro sent out on every notification. I
> need to find someway of allowing for the seperate config for a
> acknowledgement notification. The word "ACKNOWLEDGEMENT" specified is
> also to long for text/sms messages.
>
> $NOTIFICATIONTYPE$ - "Identifies the type of notification that is being
> sent ("PROBLEM", "RECOVERY", or "ACKNOWLEDGEMENT")."
I worked around these issues and set my self up for the future to be
as flexible as needed by changing my notification command to be a local
script I pass the macros to as arguments, so I can test values and
conditions and do what I want. For instance, here's the original and
new definitions from misccommands.cfg.
# 'notify-by-email' command definition
define command{
command_name notify-by-email
# command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nHost Descripti
on: $HOSTALIAS$\nIP Address: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mailx -s "** Nagios
alert ($NOTIFICATIONTYPE$) $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
command_line /usr/local/bin/nagios-notification "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTADDRESS$" "$SERVICESTATE$" "$LONGDATE
TIME$" "$SERVICEOUTPUT$" "$CONTACTEMAIL$" "$SERVICEACKAUTHOR$" "$SERVICEACKCOMMENT$" $USER3$ $USER4$ $USER5$
}
And the the script /usr/local/bin/nagios-notification looks like this. In this
instance, I've set it up for two actions I wanted - 1. to allow an SNMP-triggered
action when I acknowledge a certain service issue, and 2. I don't want to go out
for services that are stale from a downed host. I get mailed for the host, so
that's enough. If just a service is stale, we'll catch that visually on the
web pages. Hope this helps.
#!/bin/ksh
# notification wrapper script
# For testings
# set -x
# exec > /tmp/mail.out 2>&1
NOTIFICATIONTYPE=$1
SERVICEDESC=$2
HOSTNAME=$3
HOSTALIAS="$4"
HOSTADDRESS=$5
SERVICESTATE=$6
LONGDATETIME="$7"
SERVICEOUTPUT="$8"
CONTACTEMAIL=$9
SERVICEACKAUTHOR="${10}"
SERVICEACKCOMMENT="${11}"
USER3=${12}
USER4=${13}
USER5=${14}
if [ $NOTIFICATIONTYPE = "ACKNOWLEDGEMENT" ]
then
/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE\n\nService: $SERVICEDESC\nHost: $HOSTNAME\nHost Description: $HOSTALIAS\nIP
Address: $HOSTADDRESS\nState: $SERVICESTATE\n\nDate/Time: $LONGDATETIME\n\nAdditional Info:\n\n$SERVICEOUTPUT\n\nAcknowledged by: $SERVICEACKAUTHOR\nAcknowledgement c
omments: $SERVICEACKCOMMENT" | /usr/bin/mailx -s "** Nagios alert ($NOTIFICATIONTYPE) $HOSTNAME/$SERVICEDESC is $SERVICESTATE **" $CONTACTEMAIL
case $SERVICEDESC in
check-messages)
/usr/local/bin/snmpget -l AuthPriv -v 3 -u $USER3 -a MD5 -A $USER4 -x DES -X $USER5 $HOSTADDRESS nsExtendResult.\"nagiosreset\"
;;
check-else)
/usr/local/bin/snmpget -l AuthPriv -v 3 -u $USER3 -a MD5 -A $USER4 -x DES -X $USER5 $HOSTADDRESS extCommand.12
;;
esac
else
if echo $SERVICEOUTPUT | grep "Service results are stale" > /dev/null 2>&1
then
: Drop notification
else
/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE\n\nService: $SERVICEDESC\nHost: $HOSTNAME\nHost Description: $HOSTAL
IAS\nIP Address: $HOSTADDRESS\nState: $SERVICESTATE\n\nDate/Time: $LONGDATETIME\n\nAdditional Info:\n\n$SERVICEOUTPUT" | /usr/bin/mailx -s "** Nagios alert ($NOTIFICA
TIONTYPE) $HOSTNAME/$SERVICEDESC is $SERVICESTATE **" $CONTACTEMAIL
fi
fi
--
- Kyle
---------------------------------------------
kylet at panix.com http://www.panix.com/~kylet
---------------------------------------------
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
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