# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
#
#rds-alarm-apply start
#confirms that executables required for succesful script execution are available
prerequisitecheck()
{
for prerequisite in basename cut grep mon-put-metric-alarm rds-describe-db-instances
do
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
hash$prerequisite&> /dev/null
if[[$?==1]]#has exits with exit status of 70, executable was not found
thenecho"In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2;exit70
fi
done
}
#calls prerequisitecheck function to ensure that all executables required for script execution are available
prerequisitecheck
region="us-east-1"
#handles options processing
whilegetopts :d:r:t:p:e:a opt
do
case$opt in
d)dbname="$OPTARG";;
r)region="$OPTARG";;
t)topicname="$OPTARG";;
e)evaluationperiod="$OPTARG";;
p)previewmode="$OPTARG";;
a)allrds="true";;
*)echo"Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2;exit 64;;
esac
done
#sets previewmode - will echo commands rather than performing work
case$previewmode in
true|True)previewmode="echo";echo"Preview Mode is set to \"True.\"" 1>&2;;
""|false|False)previewmode="";;
*)echo"You specified \"$previewmode\" for Preview Mode. If specifying a Preview Mode you must specificy either \"true\" or \"false.\"" 1>&2;exit 64;;
esac
# evaluationperiod validator - must be a number between 1 and 99
case$evaluationperiod in
"")evaluationperiod=1;;
[1-99]);;
*)echo"You specified \"$evaluationperiod\" for your evaluation period. If specifying an evalaution period you must specify a period between 1 and 99." 1>&2;exit 64;;
elseecho"The RDS instance \"$dbname\" does not exist. You must specify a valid RDS instance." 1>&2;exit64
fi
fi
# multiple RDS instance validator - runs if applying to all instances
if[[$allrds=="true"]]
then
if[[$dbname !=""]]
then
echo"You specified both \"All\" RDS instances and \"$dbname\" to apply alarms to. You must specify either one particular RDS instance (-d <dbname>) or all RDS instances (-a)." 1>&2;exit64
else
echo"Alarms will be applied to all RDS instances."