52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
import json
|
|
from time import sleep
|
|
|
|
es_headers = {'Content-Type': 'application/json'}
|
|
kibana_headers = {'Content-Type': 'application/json', 'kbn-xsrf': 'true'}
|
|
|
|
nginx_pattern = {
|
|
"index_patterns": ["wownero-block-data-*"],
|
|
"mappings": {
|
|
"properties": {
|
|
"datetime": {
|
|
"type": "date",
|
|
"format": "yyyy-MM-dd HH:mm:ss"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
remove_low_disk = {
|
|
"transient": {
|
|
"cluster.routing.allocation.disk.watermark.low": "30mb",
|
|
"cluster.routing.allocation.disk.watermark.high": "20mb",
|
|
"cluster.routing.allocation.disk.watermark.flood_stage": "10mb",
|
|
"cluster.info.update.interval": "1m"
|
|
}
|
|
}
|
|
|
|
def wait_for_es():
|
|
keep_trying = True
|
|
while keep_trying:
|
|
try:
|
|
requests.get('http://elasticsearch:9200/_cat/health', headers=es_headers)
|
|
keep_trying = False
|
|
except:
|
|
print('[!] Elasticsearch not ready yet....waiting')
|
|
sleep(15)
|
|
|
|
def load_index_settings():
|
|
# Publish index mappings and settings
|
|
print('[+] Adding index mapping and cluster settings')
|
|
r1 = requests.put('http://elasticsearch:9200/_template/wownero-block-data', headers=es_headers, data=json.dumps(nginx_pattern))
|
|
r2 = requests.put('http://elasticsearch:9200/_cluster/settings', headers=es_headers, data=json.dumps(remove_low_disk))
|
|
print(r1)
|
|
print(r2)
|
|
|
|
if __name__ == '__main__':
|
|
wait_for_es()
|
|
load_index_settings()
|