|
9 | 9 | except ImportError:
|
10 | 10 | import simplejson as json
|
11 | 11 |
|
12 |
| -class ESShardsCheck(NagiosCheck): |
13 | 12 |
|
14 |
| - def __init__(self): |
| 13 | +class ESShardsCheck(NagiosCheck): |
15 | 14 |
|
16 |
| - NagiosCheck.__init__(self) |
| 15 | + def __init__(self): |
17 | 16 |
|
18 |
| - self.add_option('H','host', 'host', 'The cluster to check') |
19 |
| - self.add_option('P','port', 'port', 'The ES port - defaults to 9200') |
| 17 | + NagiosCheck.__init__(self) |
20 | 18 |
|
| 19 | + self.add_option('H', 'host', 'host', 'The cluster to check') |
| 20 | + self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200') |
21 | 21 |
|
22 |
| - def check(self, opts, args): |
23 |
| - host = opts.host |
24 |
| - port = int(opts.port or '9200') |
| 22 | + def check(self, opts, args): |
| 23 | + host = opts.host |
| 24 | + port = int(opts.port or '9200') |
25 | 25 |
|
26 |
| - try: |
27 |
| - response = urllib2.urlopen(r'http://%s:%d/_cluster/health' %(host, port)) |
28 |
| - except urllib2.HTTPError, e: |
29 |
| - raise Status('unknown', ("API failure", None, "API failure:\n\n%s" % str(e))) |
30 |
| - except urllib2.URLError, e: |
31 |
| - raise Status('critical', (e.reason)) |
| 26 | + try: |
| 27 | + response = urllib2.urlopen(r'http://%s:%d/_cluster/health' |
| 28 | + % (host, port)) |
| 29 | + except urllib2.HTTPError, e: |
| 30 | + raise Status('unknown', ("API failure", None, |
| 31 | + "API failure:\n\n%s" % str(e))) |
| 32 | + except urllib2.URLError, e: |
| 33 | + raise Status('critical', (e.reason)) |
32 | 34 |
|
33 |
| - response_body = response.read() |
| 35 | + response_body = response.read() |
34 | 36 |
|
35 |
| - try: |
36 |
| - es_cluster_health = json.loads(response_body) |
37 |
| - except ValueError: |
38 |
| - raise Status('unknown', ("API returned nonsense",)) |
| 37 | + try: |
| 38 | + es_cluster_health = json.loads(response_body) |
| 39 | + except ValueError: |
| 40 | + raise Status('unknown', ("API returned nonsense",)) |
39 | 41 |
|
40 |
| - unassigned_shards = es_cluster_health['unassigned_shards'] |
| 42 | + unassigned_shards = es_cluster_health['unassigned_shards'] |
41 | 43 |
|
42 |
| - if es_cluster_health['unassigned_shards'] != unassigned_shards: |
43 |
| - raise Status('CRITICAL', "There are '%s' unassigned shards in the cluster" %unassigned_shards) |
44 |
| - else: |
45 |
| - raise Status('OK', "All shards in the cluster are currently assigned") |
| 44 | + if es_cluster_health['unassigned_shards'] != unassigned_shards: |
| 45 | + raise Status('CRITICAL', |
| 46 | + "There are '%s' unassigned shards in the cluster" |
| 47 | + % (unassigned_shards)) |
| 48 | + else: |
| 49 | + raise Status('OK', |
| 50 | + "All shards in the cluster are currently assigned") |
46 | 51 |
|
47 | 52 |
|
48 | 53 | if __name__ == "__main__":
|
49 |
| - ESShardsCheck().run() |
| 54 | + ESShardsCheck().run() |
0 commit comments