Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansible
Roles
elasticsearch
Commits
93128620
Commit
93128620
authored
4 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
ansible-inventories/arocom#2937 Fix purge script to work with Python 3
parent
50b4621c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
files/purge.py
+9
-9
9 additions, 9 deletions
files/purge.py
templates/search/haproxy.json
+1
-0
1 addition, 0 deletions
templates/search/haproxy.json
with
10 additions
and
9 deletions
files/purge.py
+
9
−
9
View file @
93128620
#!/usr/bin/env python
#!/usr/bin/env python
3
'''
Purge ElasticSearch Data
...
...
@@ -10,7 +10,7 @@ import json
import
pycurl
from
datetime
import
date
from
dateutil.relativedelta
import
relativedelta
from
StringIO
import
String
IO
from
io
import
Bytes
IO
try
:
# python 3
from
urllib.parse
import
urlencode
...
...
@@ -28,7 +28,7 @@ args = parser.parse_args()
def
getIndex
():
buffer
=
String
IO
()
buffer
=
Bytes
IO
()
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
=
String
IO
()
buffer
=
Bytes
IO
()
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
=
String
IO
()
buffer
=
Bytes
IO
()
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
=
String
IO
()
buffer
=
Bytes
IO
()
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
()
...
...
This diff is collapsed.
Click to expand it.
templates/search/haproxy.json
+
1
−
0
View file @
93128620
...
...
@@ -11,6 +11,7 @@
"b_end"
,
"c_ip"
,
"status_code"
,
"sni"
,
"http_request"
],
"sort"
:
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment