Commit 94c5658f authored by ale's avatar ale

fix expiration of old logs

parent c047e8dc
......@@ -32,8 +32,8 @@ class LogStore(object):
INDEX = 'logs'
BULK_SIZE = 400
def __init__(self, server_list):
self.conn = pyes.ES(server_list, timeout=10,
def __init__(self, server_list, timeout=60):
self.conn = pyes.ES(server_list, timeout=timeout,
autorefresh=True,
bulk_size=self.BULK_SIZE)
......@@ -71,6 +71,7 @@ class LogStore(object):
'type': 'string',
'index': 'analyzed',
'store': 'no',
'include_in_all': 'no',
},
},
}],
......@@ -86,27 +87,31 @@ class LogStore(object):
template)
log_mapping = {
'timestamp': {
'index': 'not_analyzed',
'type': 'long',
'store': 'no',
'include_in_all': 'no',
},
'host': {
'index': 'analyzed',
'index': 'not_analyzed',
'store': 'no',
'type': 'string'
'type': 'string',
'include_in_all': 'no',
},
'facility': {
'index': 'analyzed',
'index': 'not_analyzed',
'store': 'no',
'type': 'string',
'include_in_all': 'no',
},
'severity': {
'index': 'analyzed',
'index': 'not_analyzed',
'store': 'no',
'type': 'string',
'include_in_all': 'no',
},
'program': {
'index': 'analyzed',
'index': 'not_analyzed',
'store': 'no',
'type': 'string',
},
......@@ -179,7 +184,7 @@ class LogStore(object):
to_value=to_timestamp(timelimit))
f = pyes.filters.NumericRangeFilter(trange)
q = pyes.query.FilteredQuery(pyes.query.MatchAllQuery(), f)
self.conn.deleteByQuery(q)
self.conn.deleteByQuery([self.INDEX], ['log'], q)
self.conn.optimize(self.INDEX)
def _make_search(self, query_str, time_range, **search_args):
......
......@@ -120,7 +120,7 @@ Known commands:
parser.error('Please specify a command')
logging.basicConfig(level=logging.DEBUG)
lens = logstore.LogStore(opts.es_url)
lens = logstore.LogStore(opts.es_url, timeout=3600)
cmd, args = args[0], args[1:]
if cmd == 'daemon':
......
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