apcupsd email should be properly threaded

Bug #392106 reported by Ketil Malde
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apcupsd (Ubuntu)
New
Undecided
Unassigned

Bug Description

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:

==> /etc/apcupsd/offbattery <==
#!/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

Revision history for this message
Ketil Malde (ketil-ii) wrote :

One more thing, what's with the "echo $MSG"'s? Is it for broken mailers that add no headers on their own? But mail is called with -s option later on...

description: updated
Sergey Svishchev (svs)
summary: - acupsd email should be properly threaded
+ apcupsd email should be properly threaded
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.