Skip to content

Commit 7a6921a

Browse files
committed
fixing the syntax of the unassigned shards check to conform to pep8 syntax guidelines
1 parent c354f0d commit 7a6921a

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

check_es_unassigned_shards.py

+30-25
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,46 @@
99
except ImportError:
1010
import simplejson as json
1111

12-
class ESShardsCheck(NagiosCheck):
1312

14-
def __init__(self):
13+
class ESShardsCheck(NagiosCheck):
1514

16-
NagiosCheck.__init__(self)
15+
def __init__(self):
1716

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)
2018

19+
self.add_option('H', 'host', 'host', 'The cluster to check')
20+
self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200')
2121

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')
2525

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))
3234

33-
response_body = response.read()
35+
response_body = response.read()
3436

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",))
3941

40-
unassigned_shards = es_cluster_health['unassigned_shards']
42+
unassigned_shards = es_cluster_health['unassigned_shards']
4143

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")
4651

4752

4853
if __name__ == "__main__":
49-
ESShardsCheck().run()
54+
ESShardsCheck().run()

0 commit comments

Comments
 (0)