Commit 44e3efc2 authored by Jürgen Haas's avatar Jürgen Haas

Make sure that purge script uses authentication

parent c3606d05
#!/usr/bin/env python3
#!/usr/bin/env python
'''
Purge ElasticSearch Data
......@@ -19,6 +19,8 @@ except ImportError:
from urllib import urlencode
parser = argparse.ArgumentParser(description='ElasticSearch Purge')
parser.add_argument('username')
parser.add_argument('password')
parser.add_argument('index')
parser.add_argument('retention')
parser.add_argument('mode')
......@@ -28,7 +30,7 @@ args = parser.parse_args()
def getIndex():
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/_cat/indices?v&pretty&s=index&format=json')
c.setopt(c.URL, 'http://%s:%s@localhost:9200/_cat/indices?v&pretty&s=index&format=json' % (args.username, args.password))
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.perform()
......@@ -44,7 +46,7 @@ def purgeSingle(cat, day):
print(' Postfields: ' + postfields)
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + args.index + '/_delete_by_query')
c.setopt(c.URL, 'http://%s:%s@localhost:9200/%s/_delete_by_query' % (args.username, args.password, args.index))
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.POSTFIELDS, postfields)
......@@ -54,7 +56,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.URL, 'http://%s:%s@localhost:9200/%s/_forcemerge?only_expunge_deletes=true' % (args.username, args.password, args.index))
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.POSTFIELDS, '')
......@@ -71,10 +73,10 @@ def purgeDaily(cat, day):
range = prefix + day.strftime('%Y.%m.%d')
for index in cat:
if index['index'].find(prefix) == 0 and index['index'] < range:
print(' Index: + index['index])
print(' Index: ' + index['index'])
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + index['index'])
c.setopt(c.URL, 'http://%s:%s@localhost:9200/%s' % (args.username, args.password, index['index']))
c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CUSTOMREQUEST, 'DELETE')
......
......@@ -22,7 +22,7 @@
name: Elasticsearch Purge {{ item.index }}
hour: 0
minute: 10
job: /usr/local/bin/elasticpurge.py {{ item.index }} {{ item.retention }} {{ item.mode }} >>/var/log/elasticsearch/purge.log 2>&1
job: /usr/local/bin/elasticpurge.py elastic {{ elasticsearch.users.elastic|default("") }} {{ item.index }} {{ item.retention }} {{ item.mode }} >>/var/log/elasticsearch/purge.log 2>&1
disabled: '{{ item.disabled|default(false) }}'
with_items: '{{ elasticsearch.purge }}'
tags:
......
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