forked from skyscrapers/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_autoscalegroup.py
executable file
·55 lines (44 loc) · 1.46 KB
/
check_autoscalegroup.py
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
#!/usr/bin/env python
# Written by filip@skyscrape.rs
# 2014-02-11
import json
import os
import sys
from pprint import pprint
import commands
paramList = sys.argv
if len(paramList) <= 1:
print "USAGE " + paramList[0] + " <auto scaling group name>"
sys.exit(2)
asgName = paramList[1]
cmd = "/usr/local/bin/aws --profile nagiosro autoscaling describe-auto-scaling-groups --auto-scaling-group-names " + asgName
output = commands.getoutput(cmd)
jsondata = json.loads(output)
desiredCapacity = int(jsondata['AutoScalingGroups'][0]['DesiredCapacity'])
MinSize = int(jsondata['AutoScalingGroups'][0]['MinSize'])
MaxSize = int(jsondata['AutoScalingGroups'][0]['MaxSize'])
counterH = 0
instancesH = ""
counterUH = 0
instancesUH = ""
for item in jsondata['AutoScalingGroups'][0]['Instances']:
if item['HealthStatus'] == 'Healthy':
counterH += 1
instancesH += " " + item['InstanceId']
else:
counterUH += 1
instancesUH += " " + item['InstanceId']
if not instancesH:
instancesH = " none"
if not instancesUH:
instancesUH = " none"
msg = "Desired capacity " + str(desiredCapacity) + ". MinSize " + str(MinSize) + ". MaxSize " + str(MaxSize) + ". Healthy instances " + str(counterH) + ":" + instancesH + ". Unhealthy instances " + str(counterUH) + ":" + instancesUH
if counterH < desiredCapacity:
print "CRITICAL - " + msg
sys.exit(2)
elif counterUH > 0:
print "WARNING - " + msg
sys.exit(1)
else:
print "OK - " + msg
sys.exit(0)