Commit b6d8a606 authored by Jürgen Haas's avatar Jürgen Haas

Improve some scripts

parent c7b05c6b
#!/bin/bash
if [[ "x$1" = "x" ]]; then
DATE=`date +%Y.%m.%d`
elasticsearch-remove-readonly .kibana_2
elasticsearch-remove-readonly .kibana_1
elasticsearch-remove-readonly ansible
elasticsearch-remove-readonly uptime
elasticsearch-remove-readonly logstash-$DATE
elasticsearch-remove-readonly heartbeat-6.6.1-$DATE
exit 0
fi
echo ""
echo "Unlock $1"
curl -X PUT http://127.0.0.1:9200/$1/_settings -H 'Content-Type: application/json' -d '{"index.blocks.read_only_allow_delete":null}'
......@@ -29,6 +29,7 @@ def getIndex():
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/_cat/indices?v&pretty&s=index&format=json')
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
......@@ -38,12 +39,13 @@ def getIndex():
def purgeSingle(cat, day):
for index in cat:
if index['index'] == args.index:
post_data = {"query":{"bool":{"filter":{"range":{"syslog_time":{"lte":day.strftime('%d/%b/%Y:00:00:00 +0000')}}}}}}
post_data = {"query":{"bool":{"filter":{"range":{"@timestamp":{"lte":day.strftime('%Y-%m-%d')}}}}}}
postfields = json.dumps(post_data)
print(' Postfields: ' + postfields)
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + args.index + '/_delete_by_query')
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.POSTFIELDS, postfields)
c.perform()
......@@ -53,6 +55,7 @@ def purgeSingle(cat, day):
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + args.index + '/_forcemerge?only_expunge_deletes=true')
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.POSTFIELDS, '')
c.perform()
......@@ -72,6 +75,7 @@ def purgeDaily(cat, day):
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + index['index'])
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CUSTOMREQUEST, 'DELETE')
c.perform()
......
......@@ -18,5 +18,6 @@
loop_var: index
- import_tasks: purge.yml
- import_tasks: readonly.yml
when: '"elasticsearch" not in excluded_roles'
---
# file: roles/elasticsearch/tasks/readonly.yml
- name: "Copy script"
copy:
src: 'elasticsearch-remove-readonly'
dest: '/usr/local/bin/elasticsearch-remove-readonly'
mode: '0755'
tags: 'cron'
- name: "Set Remove Readonly Crons"
cron:
name: 'Elasticsearch Remove Readonly'
hour: '5'
minute: '55'
job: '/usr/local/bin/elasticsearch-remove-readonly >>/var/log/elasticsearch/readonly.log 2>&1'
disabled: '{{ item.disabled|default(false) }}'
tags: 'cron'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment