-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_elb_instances_v2
executable file
·61 lines (49 loc) · 2.04 KB
/
check_elb_instances_v2
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
#!/bin/bash
# --------- License Info ---------
# Copyright (c) 2013 Emind Systems Ltd. - http://www.emind.co
# This file is part of Emind Systems DevOps Toolset.
# Emind Systems DevOps Toolset is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Emind Systems DevOps Toolset is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Emind Systems DevOps Toolset. If not, see http://www.gnu.org/licenses.
while getopts "k:s:e:r:h" arg; do
case $arg in
k)
export AWS_ACCESS_KEY_ID=$OPTARG
;;
s)
export AWS_SECRET_ACCESS_KEY=$OPTARG
;;
e)
LB_NAME=$OPTARG
;;
r)
AWS_REGION=$OPTARG
;;
h)
echo "Usage: $0 -k <WS-AccessKeyId> -s <AWS-SecretKey> -r <AWS-Region> -e <LB_NAME>"
exit 99
;;
esac
done
CMD="/usr/bin/aws elb describe-instance-health"
OPT="--region ${AWS_REGION} --load-balancer-name ${LB_NAME}"
JSON=$(${CMD} ${OPT})
if [ $? -eq 0 ]; then
IN_SERVICE_COUNT=$(echo ${JSON} | jq -c '.InstanceStates[].State' | grep InService |wc -l)
TOTAL_COUNT=$(echo ${JSON} | jq -c '.InstanceStates[].State' | wc -l)
if [ ${IN_SERVICE_COUNT} -eq 0 ]; then
NAGIOS_STATE=CRITICAL
EXIT_CODE=2
elif [ ${TOTAL_COUNT} -eq ${IN_SERVICE_COUNT} ]; then
NAGIOS_STATE=OK
EXIT_CODE=0
elif [ ${IN_SERVICE_COUNT} -lt ${TOTAL_COUNT} ]; then
NAGIOS_STATE=WARNING
EXIT_CODE=1
fi
echo "${NAGIOS_STATE}: ELB:${LB_NAME} Total:${TOTAL_COUNT} Healthy:${IN_SERVICE_COUNT} | Total=${TOTAL_COUNT} Healthy=${IN_SERVICE_COUNT}"
else
echo "Failed to retrieve ELB Instances health from AWS"
EXIT_CODE=99
fi
exit ${EXIT_CODE}