-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathes-cluster-health
executable file
·71 lines (50 loc) · 1.4 KB
/
es-cluster-health
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
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# Copyright (c) 2014 Anchor Systems
# https://github.com/anchor/elasticsearch-scripts
"""
NAME
es-cluster-health - print the current state of /_cluster/health
SYNOPSIS
es-cluster-health [HOST[:PORT]]
DESCRIPTION
This command will always output JSON to standard output.
"""
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 9200
from esadmin import Connection
import json
import logging
import os
import sys
logger = logging.getLogger(__name__)
def usage(argv):
print >>sys.stderr, ("Usage:\n\t%s [HOST[:PORT]]\n" %
os.path.basename(argv[0]))
def main(argv=None):
if argv is None:
argv = sys.argv
host = DEFAULT_HOST
port = DEFAULT_PORT
try:
address = sys.argv[1]
except IndexError:
pass
else:
if address.find(":") == -1:
host = address
else:
host, port = address.split(":")
try:
port = int(port)
except ValueError:
usage(argv)
return 2
with Connection(host, port) as conn:
resp = conn.get('/_cluster/health')
print json.dumps(resp, ensure_ascii=True, indent=2,
sort_keys=True)
return 0
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO,
format='%(levelname)s:\t%(message)s')
sys.exit(main(sys.argv))