-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws-queues.sh
executable file
·73 lines (64 loc) · 1.9 KB
/
aws-queues.sh
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
#!/usr/bin/env bash
#
set -e
queues=(
"_aaa_async_jobs_deadletter.fifo"
"_aaa_background_jobs_deadletter.fifo"
"_aaa_batch_jobs_deadletter"
"_aaa_data_sync_jobs_deadletter"
"_aaa_delayed_jobs_deadletter"
"_aaa_elastic_jobs_deadletter"
"_aaa_elastic_report_jobs_deadletter"
"_aaa_import_jobs_deadletter"
"_aaa_marketing_jobs_deadletter.fifo"
"_aaa_pdf_jobs_deadletter.fifo"
"_aaa_slow_jobs_deadletter"
"_aaa_sysop_jobs_deadletter"
)
aws_profile="$1"
[ -z "$1" ] && echo "please specify aws profile" && exit
get_aws_account_id() {
aws sts get-caller-identity --profile $1|jq -r .Account
}
strip_cdk() {
echo "$1" |cut -d- -f2
}
strip_deadletter() {
echo "$1" |sed 's/_deadletter//g'
}
queue_name() {
local q=$1
if [[ "$aws_profile" == 'cdk-qa3' ]]; then
echo "qa_smrtqa$q"
else
echo "production_phpweb-$(strip_cdk $aws_profile)$q"
fi
}
get_number_of_msgs(){
aws sqs get-queue-attributes --attribute-names ApproximateNumberOfMessages \
--queue-url https://sqs.us-east-1.amazonaws.com/$(get_aws_account_id $aws_profile)/$1 \
--profile $aws_profile|jq -r .Attributes.ApproximateNumberOfMessages
}
deadletters() {
for q in ${queues[@]}; do
#echo "https://sqs.us-east-1.amazonaws.com/$(get_aws_account_id $aws_profile)/production_phpweb-$(strip_cdk $1)$q"
queue=$(queue_name "$q")
number_of_messages=$(get_number_of_msgs $queue)
if (( $number_of_messages > 0 )); then
echo "$queue: $number_of_messages"
fi
done
}
queues() {
echo "queues"
for q in ${queues[@]}; do
#echo "https://sqs.us-east-1.amazonaws.com/$(get_aws_account_id $aws_profile)/production_phpweb-$(strip_cdk $1)$q"
dead_queue=$(queue_name "$q")
queue="$(strip_deadletter $dead_queue)"
number_of_messages=$(get_number_of_msgs $queue)
if (( $number_of_messages > 0 )); then
echo "$queue: $number_of_messages"
fi
done
}
[ -z "$2" ] && deadletters "$1" || queues "$1"