Comment 0 for bug 392106

Revision history for this message
Ketil Malde (ketil-ii) wrote : acupsd email should be properly threaded

Binary package hint: apcupsd

Acupsd is a really nice package, so this is just a suggestion for a small improvement. By default, acupsd emails me (i.e. system admin) on power outage, and when power returns. However, these emails have different subjects, and thus tend to get threaded separately, while ideally, events belonging together should thread together.

The easiest solution is through the scripts (/etc/acupsd/offbattery and onbattery) to record the message ID and set an appropriate References or In-Reply-To header in the emails. Here's my attempt, but this can probably be done more elegantly:

#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
SYSADMIN=root
APCUPSD_MAIL="mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power has returned"
if test -f /var/lib/apcupsd/$HOSTNAME.power; then
        LASTEVENT=`cat /var/lib/apcupsd/$HOSTNAME.power`
fi
#
(
   echo "Subject: $MSG"
   echo " "
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $APCUPSD_MAIL -a "In-Reply-To: $LASTEVENT" -s "$MSG" $SYSADMIN
exit 0

==> /etc/apcupsd/onbattery <==
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
SYSADMIN=root
APCUPSD_MAIL="mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power Failure !!!"
MSGID="<"`date +%H%M%S`"@$HOSTNAME>"
echo $MSGID > /var/lib/apcupsd/$HOSTNAME.power
#
(
   echo "Subject: $MSG"
   echo " "
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $APCUPSD_MAIL -a "Message-Id: $MSGID" -s "$MSG" $SYSADMIN