Back to the main page

ZFS appliance files Bugzilla bug

The ZFS appliances (like ZS3-2 ZS3-4, Sun Storage 7410) can send an email as Alert Action. See the image:

And the idea here is to take that email and file Bugzilla bug.
In this exmaple, email is sent to local account on host where Bugzilla is running, this local account is storalert2bug and hostname is ca-sysadmin.
Once email arrives, it's basically argument for the script that files a bug. This is accomplished with the line in /etc/aliases file.

storalert2bug: "|xargs sudo /usr/local/sbin/"
Don't forget to run newaliases after editing /etc/aliases file.

I've done one more adjustment for Postfix, it was running but port 25 wasn't open, because inet_interfaces was configured only for localhost (in the file /etc/postfix/, so I added host's IP address, and the line reads now:
inet_interfaces = localhost

Since this work is performed by user nobody, /etc/sudoers needs to have:
nobody ALL=(ALL)  NOPASSWD: /usr/local/sbin/

Here is the script that files a bug:

readonly storage_alert="$*" # alert from storage is argument, can be any number of words
readonly progname=`/bin/basename $0`
readonly loggerinfo="logger -t ${progname} Info:"
readonly loggerwarning="logger -t ${progname} Warning:"
readonly loggerproblem="logger -t ${progname} Problem:"

#### function: error  #########
# args: multiple
# what: print args to STDERR
err() {
        echo ; echo "Problem: $*" ; echo
        ${loggerproblem} "$*"
        exit 1

# it must be at least one argument
if [ $# -eq 0 ]; then
 err "It must be at least one argument, exiting."

# temp file and cleanup of same

tmp_file_cleaning () {
        [ -f ${tmp_file}.$$ ] && rm ${tmp_file}.$$

# --- cleaning in case of script termination and regular exit
trap tmp_file_cleaning HUP INT QUIT ABRT EXIT

${loggerinfo} ======== Start at `date +'%Y-%m-%dT%H-%M-%S_%Z'` ===============

# find which storage sends alert
storage_hostname=`echo "${storage_alert}" | awk -F\Subject: '{print $2}' | awk -F\: '{print $1}'`

# create temp file used to file a bug
echo "From:
Subject: ${storage_hostname}: Defects and Faults

@product = Storage
@component = Problems
@version = unspecified
@op_sys = Solaris
@platform = Other
@priority = P2
@severity = normal

Note: Please login to ${storage_hostname} and see details !!!!
--------------------------------------------------------------------" \
| tee ${tmp_file}.$$

echo ${storage_alert} |\
sed 's/From/\nFrom/' |\
sed 's/Return-Path/\nReturn-Path/' |\
sed 's/X-Original-To/\nX-Original-To/' |\
sed 's/Delivered-To/\nDelivered-To/' |\
sed 's/Received/\nReceived/' |\
sed 's/Message-Id/\nMessage-Id/' |\
sed 's/To/\nTo/' |\
sed 's/Subject/\n\nSubject/' |\
sed 's/SUNW-MSG-ID/\n\nSUNW-MSG-ID/' |\
sed 's/EVENT-TIME/\n\nEVENT-TIME/' |\
sed 's/PLATFORM/\n\nPLATFORM/' |\
sed 's/SOURCE/\n\nSOURCE/' |\
sed 's/EVENT-ID/\n\nEVENT-ID/' |\
sed 's/DESC/\n\nDESC/' |\
sed 's/IMPACT/\n\nIMPACT/' |\
sed 's/REC-ACTION/\n\nREC-ACTION/' |\
sed 's/SEE/\n\nSEE/' |\
tee -a ${tmp_file}.$$

# now file the bug
/usr/share/bugzilla/ < ${tmp_file}.$$ || \
   err "cannot file bug for alert from ${storage_hostname}"
${loggerinfo} A bug has been filed for the alert from ${storage_hostname}
${loggerinfo} ======== Finish at `date +'%Y-%m-%dT%H-%M-%S_%Z'` ===============
exit 0

Now when email arrives, /var/log/maillog reads:
postfix/local[14404]: 5B73F1757: to=<>, 
relay=local, delay=0.18, delays=0.06/0.02/0/0.1, dsn=2.0.0, 
status=sent (delivered to command: xargs sudo /usr/local/sbin/

And created bug is:

Back to the main page