Skip to content

Instantly share code, notes, and snippets.

@maxheadroom
Last active August 29, 2015 14:06
Show Gist options
  • Save maxheadroom/a14b274dd672bb7b5755 to your computer and use it in GitHub Desktop.
Save maxheadroom/a14b274dd672bb7b5755 to your computer and use it in GitHub Desktop.
check for AWS maintenance
#!/bin/bash
#
REGIONS="us-east-1 ap-southeast-2 eu-west-1 ap-southeast-1 us-west-2 us-west-1"
JQ=~/Downloads/jq
OPTS="--profile mspprod"
# check for maintenance in above AWS regions
for region in $REGIONS; do
#check for instance in the regions that need maintenance
echo "==================================================="
echo "checking $region"
for machine in `aws $OPTS ec2 describe-instance-status --include-all-instances --filters "Name=event.code,Values=system-reboot" --region $region | $JQ '.InstanceStatuses[].InstanceId'`; do
# echo "looking at $machine"
m=`echo $machine | sed 's/\"//g'`
resultset=`aws $OPTS ec2 describe-instance-status --instance-ids $m --filters "Name=event.code,Values=system-reboot" --region $region`
BEGIN=`echo $resultset | $JQ '.InstanceStatuses[].Events[].NotBefore'`
END=`echo $resultset | $JQ '.InstanceStatuses[].Events[].NotAfter'`
image=`aws $OPTS ec2 describe-instances --region $region --instance-ids $m`
IMAGEID=`echo $image | $JQ '.Reservations[].Instances[].ImageId'`
TAGS=`echo $image | $JQ '.Reservations[].Instances[].Tags'`
i=`echo $IMAGEID | sed 's/\"//g'`
IMAGENAME=`aws $OPTS --region $region ec2 describe-images --image-ids $i | $JQ '.Images[].Name'`
echo "for $machine in $region we see $IMAGENAME"
echo "Maintenance: $BEGIN -> $END"
echo $TAGS
echo
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment