Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 110 lines (93 sloc) 3.766 kB
0b0892f @jimbrowne New script volume-status-check (NAGIOS plugin)
authored
1 #!/usr/bin/env python
2 #
3 # Copyright 2012, 42Lines, Inc.
4 # Original Author: Jim Browne
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 import pynagios
19 from pynagios import Plugin, make_option, Response
20 import boto
21 from boto.ec2 import regions
22
23
24 class VolumeEventsCheck(Plugin):
25 region = make_option("--region",
26 help="Region to check (default: us-east-1)",
27 default=[],
28 action="append")
29 allregions = make_option("--all",
30 help="Check all regions",
31 action="store_true")
32
33 responses = []
34
35 def check(self):
36 boto_old = 1
37
38 # Boto 2.3.0 and later has volume status code
39 # Boto < 2.0 missing __version__, hence try/except
40 try:
41 if boto.__version__ >= '2.3.0':
42 boto_old = 0
43 except AttributeError:
44 pass
45
46 if boto_old:
47 message = "Boto version too old. Need 2.3.0 or later"
48 return Response(pynagios.UNKNOWN, message)
49
50 if not self.options.region:
51 self.options.region = ["us-east-1"]
52
53 if self.options.allregions:
54 regs = regions()
55 else:
56 regs = []
57 for ropt in self.options.region:
58 for r in regions():
59 if r.name == ropt:
60 regs.append(r)
61 break
62 else:
63 message = "Region %s not found." % ropt
64 return Response(pynagios.UNKNOWN, message)
65
66 for r in regs:
67 self.regioncheck(r)
68
69 if len(self.responses):
70 result = Response(pynagios.WARNING, ", ".join(self.responses))
71 else:
72 names = [r.name for r in regs]
73 result = Response(pynagios.OK, "Checked regions: " +
74 ", ".join(names))
75 return result
76
77 def regioncheck(self, region):
78
79 import re
80
81 ec2 = boto.connect_ec2(region=region)
82 reservations = ec2.get_all_instances()
83 #vfilter = { 'volume-status.status' : 'impaired' }
84 #stats = ec2.get_all_volume_status(filters=vfilter)
85 stats = ec2.get_all_volume_status()
86
87 for stat in stats:
88 if self.options.verbosity:
89 print "id %s status %s" % (stat.id, stat.volume_status)
90 if stat.events:
91 for event in stat.events:
92 if self.options.verbosity:
93 print event
94 message = stat.id
95 message += ":%s %s" % (event.type, event.description)
96 message += " nb %s" % (event.not_before)
97 self.responses.append(message)
98 if stat.actions:
99 for action in stat.actions:
100 if self.options.verbosity:
101 print action
102 message = stat.id
103 message += ":%s %s" % (action.type, action.description)
104 message += " code %s" % (action.code)
105 self.responses.append(message)
106
107 if __name__ == "__main__":
108 # Instantiate the plugin, check it, and then exit
109 VolumeEventsCheck().check().exit()
Something went wrong with that request. Please try again.