<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Here's the full hack if anyone is interested.</div><div><br></div><div><br></div><div><span class="Apple-style-span" style="text-decoration: underline;">Service Notification</span></div><div><div>        command_line    $USER3$/scripts/send-email.sh "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$HOSTALIAS$" "$HOSTADDRESS$" "$SERVICESTATE$" "$LONGDATETIME$" "$SERVICEOUTPUT$$LONGSERVICEOUTPUT$" "$CONTACTGROUPNAME$" "$CONTACTEMAIL$"</div><div><br></div><div><span class="Apple-style-span" style="text-decoration: underline;">Host Notification</span></div><div>        command_line    $USER2$/scripts/send-email.sh "$NOTIFICATIONTYPE$" "" "$HOSTALIAS$" "$HOSTADDRESS$" "$HOSTSTATE$" "$LONGDATETIME$" "$HOSTOUTPUT$$LONGHOSTOUTPUT$" "$CONTACTGROUPNAME$" "$CONTACTEMAIL$"</div><div><br></div></div><div><br></div><div><b><span class="Apple-style-span" style="text-decoration: underline;">send-email.sh</span></b></div><div><div><br></div><div>#!/bin/bash</div><div><br></div><div># Author: Caylan Larson</div><div># Date: 3/20/08</div><div># Note: This script is called by ~nagios/etc/commands.cfg to send out</div><div>#       email notifications for both services and hosts.</div><div><br></div><div>NOTIFICATIONTYPE=$1</div><div>SERVICEDESC=$2          # Empty if host notification</div><div>HOSTALIAS=$3</div><div>HOSTADDRESS=$4</div><div>STATE=$5</div><div>LONGDATETIME=$6</div><div>PLUGINOUTPUT=$7</div><div>CONTACTGROUPNAME=$8</div><div>CONTACTEMAIL=$9</div><div><br></div><div>if [ -z $SERVICEDESC ]; then</div><div>  # Send out host notification</div><div>  EMAIL_SUBJECT="Host $STATE alert for $HOSTADDRESS!"</div><div>  GREP_1=$HOSTADDRESS</div><div>  GREP_2='define host {'</div><div>else</div><div>  # Send out service notification</div><div>  EMAIL_SUBJECT="$STATE $NOTIFICATIONTYPE alert   $HOSTADDRESS/$SERVICEDESC"</div><div>  SERVICE_LINE="Service: $SERVICEDESC"</div><div>  GREP_1=$SERVICEDESC</div><div>  GREP_2=$HOSTADDRESS</div><div>fi</div><div><br></div><div><div># To make up for an absent macro (below) I coded this hack.  Caylan Larson</div><div>#   $SERVICECONTACTGROUPS$ - "A comma separated list of the short names taken from the contact_groups directive of the service definition."</div><div>SERVICECONTACTGROUPS=$( grep "$GREP_1" ~nagios/var/objects.cache -B 1 -A 3 \</div><div>  | grep "$GREP_2" -A 5 \</div><div>  | grep contact_groups \</div><div>  | awk '{print $2}' \</div><div>  | sed -r "s/,*$CONTACTGROUPNAME//" \</div><div>  | sed -r 's/^,|,$//' )</div><div>  # The 2nd to the last sed removes the current contact group</div><div>if [ -z "$SERVICECONTACTGROUPS" ]; then</div><div>  SERVICECONTACTGROUPS="NA (Only $CONTACTGROUPNAME)"</div><div>fi</div><div><br></div><div><div># Send Email</div><div>cat <<EOF | mail -s "$EMAIL_SUBJECT" $CONTACTEMAIL</div><div>***** Nagios  *****</div><div><br></div><div>Notification Type: $NOTIFICATIONTYPE</div><div><br></div><div>$SERVICE_LINE</div><div>Host: $HOSTALIAS</div><div>Address: $HOSTADDRESS</div><div>State: $STATE</div><div><br></div><div>Date/Time: $LONGDATETIME</div><div>Other Contacts: $SERVICECONTACTGROUPS</div><div><br></div><div>Additional Info:</div><div><br></div><div>$PLUGINOUTPUT</div><div>EOF</div></div></div><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div><br></div><div>---</div><div><br></div><div>Caylan</div><br class="Apple-interchange-newline"></div></span> </div><br><div><html>On Mar 20, 2008, at 2:54 PM, Caylan Van Larson wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>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).</div><div><br></div><div>To my surprise Nagios 3 does not include this macro.</div><div><br></div><div><b>$SERVICECONTACTGROUPS$ - </b>"A comma separated list of the short names taken from the contact_groups directive of the service definition."</div><div><br></div><div>In the meantime I can use this ugly hack inside a script to get the list of contact-groups fit for emailing:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>grep "$SERVICEDESC" ~nagios/var/objects.cache -B 1 -A 3 | grep $HOSTADDRESS -A 5 | grep contact_groups | awk '{print $2}'</div><div><br></div><div>Thoughts?</div><div><br></div></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div>---</div><div><br></div><div>Caylan</div><br class="Apple-interchange-newline"></div></span> </div><br></div>-------------------------------------------------------------------------<br>This SF.net email is sponsored by: Microsoft<br>Defy all challenges. Microsoft(R) Visual Studio 2008.<br><a href="http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________">http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________</a><br>Nagios-users mailing list<br>Nagios-users@lists.sourceforge.net<br>https://lists.sourceforge.net/lists/listinfo/nagios-users<br>::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. <br>::: Messages without supporting info will risk being sent to /dev/null</blockquote></div><br></div></body></html>