#!/bin/sh
# vim:shiftwidth=4:tabstop=4:expandtab:textwidth=78:softtabstop=4:ai:

   #########################################################
  # Written Mar 04, 2008 and released under the GNU/GPLv2 ##
 # (c) Jeff Schroeder (jeffschroeder@computer.org)       # #
#########################################################  #
#                                                       #  #
# send-email - Send an email to the systems team on     #  #
#              state change. This is a great way to     #  #
#              detect faulty hardware as a side effect  #  #
#                                                       # #
##########################################################

#$Id: send-email 67955 2008-03-11 19:55:39Z jschroeder $

export PATH=/bin:/usr/bin:$PATH
STATE=${1:-unknown}

ADMIN_EMAIL="admin1@company.com manager1@company.com admin2@company.com"
FROM_EMAIL="keepalived-no-reply@$(hostname -f)"

# This needs a locally configured mta of some sort to actually work
case $STATE in
    master|backup|fault)
         echo "`hostname -f` transitioned to $STATE on `date`" | \
         mail -s "`hostname -f` Transition to $STATE" $ADMIN_EMAIL \
	 -- -f $FROM_EMAIL -F keepalived
    ;;
    *)
        echo "Usage: $0 { master | backup | fault }" >&2
        exit 1
    ;;
esac
