diff --git a/files/purge.py b/files/purge.py index bcf9c182f347e3d32cb6fc4ddcee8c328a643abb..215a7f896df6bef7147514a399ae7d3547d3bc19 100644 --- a/files/purge.py +++ b/files/purge.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ''' Purge ElasticSearch Data @@ -10,7 +10,7 @@ import json import pycurl from datetime import date from dateutil.relativedelta import relativedelta -from StringIO import StringIO +from io import BytesIO try: # python 3 from urllib.parse import urlencode @@ -28,7 +28,7 @@ args = parser.parse_args() def getIndex(): - buffer = StringIO() + buffer = BytesIO() c = pycurl.Curl() 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']) @@ -44,7 +44,7 @@ def purgeSingle(cat, day): post_data = {"query":{"bool":{"filter":{"range":{"@timestamp":{"lte":day.strftime('%Y-%m-%d')}}}}}} postfields = json.dumps(post_data) print(' Postfields: ' + postfields) - buffer = StringIO() + buffer = BytesIO() c = pycurl.Curl() 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']) @@ -52,9 +52,9 @@ def purgeSingle(cat, day): c.setopt(c.POSTFIELDS, postfields) c.perform() c.close() - print(' Delete: ' + buffer.getvalue()) + print(' Delete: ' + buffer.getvalue().decode('utf8')) - buffer = StringIO() + buffer = BytesIO() c = pycurl.Curl() 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']) @@ -62,7 +62,7 @@ def purgeSingle(cat, day): c.setopt(c.POSTFIELDS, '') c.perform() c.close() - print(' Purge: ' + buffer.getvalue()) + print(' Purge: ' + buffer.getvalue().decode('utf8')) return print('Index not found') @@ -74,7 +74,7 @@ def purgeDaily(cat, day): for index in cat: if index['index'].find(prefix) == 0 and index['index'] < range: print(' Index: ' + index['index']) - buffer = StringIO() + buffer = BytesIO() c = pycurl.Curl() c.setopt(c.URL, 'http://%s:%s@localhost:9200/%s' % (args.username, args.password, index['index'])) c.setopt(c.HTTPHEADER, ['Content-Type: application/json']) @@ -82,7 +82,7 @@ def purgeDaily(cat, day): c.setopt(c.CUSTOMREQUEST, 'DELETE') c.perform() c.close() - print(' Delete: ' + buffer.getvalue()) + print(' Delete: ' + buffer.getvalue().decode('utf8')) cat = getIndex() diff --git a/templates/search/haproxy.json b/templates/search/haproxy.json index 17a07a2cb09001a03ae67708790005629a39308a..324a7ee2469fb2182db8459e87db5b1b4ceac75a 100644 --- a/templates/search/haproxy.json +++ b/templates/search/haproxy.json @@ -11,6 +11,7 @@ "b_end", "c_ip", "status_code", + "sni", "http_request" ], "sort": [