Here's the full hack if anyone is interested.

Service Notification
command_line $USER3$/scripts/send-email.sh "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$HOSTALIAS$" "$HOSTADDRESS$" "$SERVICESTATE$" "$LONGDATETIME$" "$SERVICEOUTPUT$$LONGSERVICEOUTPUT$" "$CONTACTGROUPNAME$" "$CONTACTEMAIL$"

Host Notification
command_line $USER2$/scripts/send-email.sh "$NOTIFICATIONTYPE$" "" "$HOSTALIAS$" "$HOSTADDRESS$" "$HOSTSTATE$" "$LONGDATETIME$" "$HOSTOUTPUT$$LONGHOSTOUTPUT$" "$CONTACTGROUPNAME$" "$CONTACTEMAIL$"


send-email.sh

#!/bin/bash

# Author: Caylan Larson
# Date: 3/20/08
# Note: This script is called by ~nagios/etc/commands.cfg to send out
#       email notifications for both services and hosts.

NOTIFICATIONTYPE=$1
SERVICEDESC=$2          # Empty if host notification
HOSTALIAS=$3
HOSTADDRESS=$4
STATE=$5
LONGDATETIME=$6
PLUGINOUTPUT=$7
CONTACTGROUPNAME=$8
CONTACTEMAIL=$9

if [ -z $SERVICEDESC ]; then
  # Send out host notification
  EMAIL_SUBJECT="Host $STATE alert for $HOSTADDRESS!"
  GREP_1=$HOSTADDRESS
  GREP_2='define host {'
else
  # Send out service notification
EMAIL_SUBJECT="$STATE $NOTIFICATIONTYPE alert $HOSTADDRESS/ $SERVICEDESC"
  SERVICE_LINE="Service: $SERVICEDESC"
  GREP_1=$SERVICEDESC
  GREP_2=$HOSTADDRESS
fi

# To make up for an absent macro (below) I coded this hack. Caylan Larson # $SERVICECONTACTGROUPS$ - "A comma separated list of the short names taken from the contact_groups directive of the service definition." SERVICECONTACTGROUPS=$( grep "$GREP_1" ~nagios/var/objects.cache -B 1 - A 3 \
  | grep "$GREP_2" -A 5 \
  | grep contact_groups \
  | awk '{print $2}' \
  | sed -r "s/,*$CONTACTGROUPNAME//" \
  | sed -r 's/^,|,$//' )
  # The 2nd to the last sed removes the current contact group
if [ -z "$SERVICECONTACTGROUPS" ]; then
  SERVICECONTACTGROUPS="NA (Only $CONTACTGROUPNAME)"
fi

# Send Email
cat <<EOF | mail -s "$EMAIL_SUBJECT" $CONTACTEMAIL
***** Nagios  *****

Notification Type: $NOTIFICATIONTYPE

$SERVICE_LINE
Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $STATE

Date/Time: $LONGDATETIME
Other Contacts: $SERVICECONTACTGROUPS

Additional Info:

$PLUGINOUTPUT
EOF

---

Caylan


On Mar 20, 2008, at 2:54 PM, Caylan Van Larson wrote:

Our contact group names are modeled after exchange distribution lists. Sometimes notifications are sent to multiple lists (service desk, dev team, oracle team). I need the notification emails to include the short names of the other contact groups (hence distribution list names) configured for the service. I understand that this is not a guarantee that a notification will be sent to all groups (since they could have different notification options).

To my surprise Nagios 3 does not include this macro.

$SERVICECONTACTGROUPS$ - "A comma separated list of the short names taken from the contact_groups directive of the service definition."

In the meantime I can use this ugly hack inside a script to get the list of contact-groups fit for emailing:

grep "$SERVICEDESC" ~nagios/var/objects.cache -B 1 -A 3 | grep $HOSTADDRESS -A 5 | grep contact_groups | awk '{print $2}'

Thoughts?

---

Caylan


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
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