Created
June 15, 2017 21:23
-
-
Save gkspranger/e0b6af62dabc9ea92a0b5eacf69de785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# checks for the number of AWS snapshots and allows alerts when threshold is met | |
# example usage: | |
# ./check_aws_snapshots.sh -w <integer> -c <integer> | |
### | |
### USES ANSIBLE to put AWS KEYs as VARS | |
### USES ANSIBLE to define NAGIOS REGION | |
### | |
### REQUIRES AWS CLI : https://aws.amazon.com/cli/ | |
### REQUIRES JQ : https://stedolan.github.io/jq/ | |
export AWS_ACCESS_KEY_ID={{ aws_access_key_id }} | |
export AWS_SECRET_ACCESS_KEY={{ aws_secret_access_key }} | |
warn=NULL | |
critical=NULL | |
help () { | |
cat << EOF | |
Check number of snapshots in AWS. | |
Usage: | |
check_aws_snapshots.sh -w <warning number> -c <critical number> | |
Options: | |
-h, | |
Print detailed help screen | |
-w INTEGER | |
Exit with WARNING status if greater than INTEGER | |
-c INTEGER | |
Exit with CRITICAL status if greater than INTEGER | |
EOF | |
exit 3 | |
} | |
while getopts "w:c:h" opt; do | |
case $opt in | |
w) | |
warn="$OPTARG" | |
;; | |
c) | |
critical="$OPTARG" | |
;; | |
h) | |
help | |
;; | |
esac | |
done | |
if [[ "$warn" == "NULL" ]] || [[ "$critical" == "NULL" ]]; then | |
help | |
fi | |
snapshots=`aws ec2 describe-snapshots --owner-ids self --region {{ ansible_ec2_placement_region }} | jq -r '.Snapshots | length'` | |
if [ $snapshots -ge $critical ]; then | |
dostatus="CRITICAL" | |
doexit=2 | |
elif [ $snapshots -ge $warn ]; then | |
dostatus="WARNING" | |
doexit=1 | |
elif [ $snapshots -lt $warn ]; then | |
dostatus="OK" | |
doexit=0 | |
else | |
dostatus="UNKOWN" | |
doexit=3 | |
fi | |
echo "AWS Snapshots ${dostatus} - ${snapshots} AWS Snapshots | snapshots=${snapshots};0;0;0;0" | |
exit $doexit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment