Created
August 1, 2022 01:36
-
-
Save tfentonz/1586315995cd78bfc2f237be9b45528e to your computer and use it in GitHub Desktop.
CloudWatch alarms for multiple accounts and regions
This file contains 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 | |
profile_prefix="ProfilePrefix" | |
region="us-east-1" | |
for i in Account1 Account2 Account3 | |
do | |
length=$(aws cloudwatch describe-alarms \ | |
--state-value ALARM \ | |
--query "length(MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`])" \ | |
--profile "${profile_prefix}-${i}" \ | |
--region "$region") | |
if [ "$length" != "0" ]; then | |
echo "# $i" | |
aws cloudwatch describe-alarms \ | |
--state-value ALARM \ | |
--query "MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`].[AlarmName,AlarmDescription]" \ | |
--output text \ | |
--profile "${profile_prefix}-${i}" \ | |
--region "$region" | |
fi | |
done | |
region="us-east-2" | |
for i in Account4 Account5 | |
do | |
length=$(aws cloudwatch describe-alarms \ | |
--state-value ALARM \ | |
--query "length(MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`])" \ | |
--profile "${profile_prefix}-${i}" \ | |
--region "$region") | |
if [ "$length" != "0" ]; then | |
echo "# $i" | |
aws cloudwatch describe-alarms \ | |
--state-value ALARM \ | |
--query "MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`].[AlarmName,AlarmDescription]" \ | |
--output text \ | |
--profile "${profile_prefix}-${i}" \ | |
--region "$region" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment