-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_ec2_eni_is_bind
executable file
·59 lines (50 loc) · 1.18 KB
/
check_ec2_eni_is_bind
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
#!/bin/bash
# This script will check specified instance status
# TODO Allow user to specified desired status
# Get script directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Load configuration
source ${DIR}/aws.cnf
if [ -z $1 ]
then
echo "No eni identifier specified"
# Exit unknown status
exit 3
fi
eni_id=$1
if [[ -z $2 && -z $EC2_REGION ]]
then
EC2_REGION="eu-west-1"
else
if [[ -z $EC2_REGION ]]
then
EC2_REGION=$2
fi
fi
state=`${EC2_HOME}/bin/ec2-describe-network-interface-attribute ${eni_id} -a -K ${EC2_PRIVATE_KEY} -C ${EC2_CERT} --region ${EC2_REGION} --show-empty-fields|grep 'ATTACHMENT'`
ec2_instance=`echo ${state}|awk '{ print $2 }'`
state=`echo ${state}|wc -l`
# Nagios status are
# 0 - All is ok
# 1 - Warning
# 2 - Error
# 3 - unknown
return_status=3
case $state in
0)
return_message="Interface is not bind"
return_status=2
;;
1)
return_message="Interface is bind on ${ec2_instance} instance"
return_status=0
;;
*)
return_message="unknown return code"
return_status=3
;;
esac
echo $return_message
exit $return_status