-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesdump.py
More file actions
55 lines (46 loc) · 1.45 KB
/
Copy pathesdump.py
File metadata and controls
55 lines (46 loc) · 1.45 KB
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
import os
import subprocess
import requests
config = {
"input":{
"host":"localhost",
"port":"9200",
"index":"elasticlogs"
},
"output":{
"host":"localhost",
"port":"9200",
"index":"bbm",
}
}
url = "http://%s:%s" % (config['input']['host'], config['input']['port'])
output_url = "http://%s:%s" % (config['output']['host'], config['output']['port'])
def exec_esdump():
ed_input = "--input=%s/%s" % (url, config['input']['index'])
ed_output = "--output=%s/%s" % (url, config['output']['index'])
subprocess.call(["elasticdump", ed_input, ed_output, "--type=data"])
return 0
def check_es_input():
try:
r = requests.get(url)
if r.status_code != 200:
print("Error hitting ElasticSearch on %s, response code was %i" % (url, r.status_code))
exit(1)
else:
print("Verified ElasticSearch server")
except:
print("Unable to hit ElasticSearch on %s" % url)
exit(1)
def check_index_exist():
try:
r = requests.get("%s/%s/_settings" % (url, config['input']['index']))
if r.status_code != 200:
print("Unable to get settings for index '%s', error code: %i" % (config.input.index, r.status_code))
exit(1)
except:
print("Unable to get ElasticSearch index on %s" % url)
exit(1)
if __name__ == '__main__':
check_es_input()
check_index_exist()
exec_esdump()