/usr/lib/ocf/resource.d/heartbeat/MailTo is in cluster-agents 1:1.0.4-0ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #!/bin/sh
#
# Resource script for MailTo
#
# Author: Alan Robertson <alanr@unix.sh>
#
# Description: sends email to a sysadmin whenever a takeover occurs.
#
# Note: This command requires an argument, unlike normal init scripts.
#
# This can be given in the haresources file as:
#
# You can also give a mail subject line or even multiple addresses
# MailTo::alanr@unix.sh::BigImportantWebServer
# MailTo::alanr@unix.sh,spoppi@gmx.de::BigImportantWebServer
#
# This will then be put into the message subject and body.
#
# OCF parameters are as below:
# OCF_RESKEY_email
# OCF_RESKEY_subject
#
# License: GNU General Public License (GPL)
#
# Copyright: (C) 2005 International Business Machines
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
#######################################################################
ARGS="$0 $*"
us=`uname -n`
usage() {
echo "Usage: $0 {start|stop|status|monitor|meta-data|validate-all}"
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="MailTo">
<version>1.0</version>
<longdesc lang="en">
This is a resource agent for MailTo. It sends email to a sysadmin whenever
a takeover occurs.
</longdesc>
<shortdesc lang="en">Notifies recipients by email in the event of resource takeover</shortdesc>
<parameters>
<parameter name="email" unique="0" required="1">
<longdesc lang="en">
The email address of sysadmin.
</longdesc>
<shortdesc lang="en">Email address</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="subject" unique="0">
<longdesc lang="en">
The subject of the email.
</longdesc>
<shortdesc lang="en">Subject</shortdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="10" />
<action name="stop" timeout="10" />
<action name="status" depth="0" timeout="10" interval="10" />
<action name="monitor" depth="0" timeout="10" interval="10" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
</actions>
</resource-agent>
END
}
MailProgram() {
$MAILCMD -s "$1" "$email" <<EOF
$Subject
Command line was:
$ARGS
EOF
return $?
}
SubjectLine() {
case $1 in
??*) echo $@;;
*) echo "Resource Group";;
esac
}
MailToStart() {
Subject="`SubjectLine $subject` Takeover in progress at `date` on $us"
MailProgram "$Subject" $1
ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} start
}
MailToStop () {
Subject="`SubjectLine $subject` Migrating resource away at `date` from $us"
MailProgram "$Subject" $1
ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} stop
}
MailToStatus () {
# ocf_log warn "Don't stat/monitor me! MailTo is a pseudo resource agent, so the status reported may be incorrect"
if ha_pseudo_resource MailTo_${OCF_RESOURCE_INSTANCE} monitor
then
echo "running"
return $OCF_SUCCESS
else
echo "stopped"
return $OCF_NOT_RUNNING
fi
}
MailToValidateAll () {
if [ -z "$MAILCMD" ]; then
ocf_log err "MAILCMD not set: complain to the packager"
exit $OCF_ERR_INSTALLED
fi
check_binary "$MAILCMD"
return $OCF_SUCCESS
}
#
# See how we were called.
#
# The order in which heartbeat provides arguments to resource
# scripts is broken. It should be fixed.
#
if
( [ $# -ne 1 ] )
then
usage
exit $OCF_ERR_GENERIC
fi
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
status|monitor) MailToStatus
exit $?
;;
usage) usage
exit $OCF_SUCCESS
;;
*) ;;
esac
if
[ -z "$OCF_RESKEY_email" ]
then
ocf_log err "At least 1 Email address has to be given!"
exit $OCF_ERR_CONFIGURED
fi
email=$OCF_RESKEY_email
subject=$OCF_RESKEY_subject
MailToValidateAll
case $1 in
start) MailToStart
;;
stop) MailToStop
;;
validate-all) ;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
|