From 93128620652ebeba35f4354c2eba48b8add11f20 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Fri, 27 Nov 2020 14:46:56 +0100
Subject: [PATCH] ansible-inventories/arocom#2937 Fix purge script to work with
 Python 3

---
 files/purge.py                | 18 +++++++++---------
 templates/search/haproxy.json |  1 +
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/files/purge.py b/files/purge.py
index bcf9c18..215a7f8 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 17a07a2..324a7ee 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": [
-- 
GitLab