Commit 0468bfd1 authored by Ad Schellevis's avatar Ad Schellevis

(netflow, flowd agg) store dates in utc, accept multiple filters in get_top_data

parent 3c2aad98
...@@ -224,7 +224,7 @@ class BaseFlowAggregator(object): ...@@ -224,7 +224,7 @@ class BaseFlowAggregator(object):
# upsert data # upsert data
flow['octets_consumed'] = consume_perc * flow['octets'] flow['octets_consumed'] = consume_perc * flow['octets']
flow['packets_consumed'] = consume_perc * flow['packets'] flow['packets_consumed'] = consume_perc * flow['packets']
flow['mtime'] = datetime.datetime.fromtimestamp(start_time) flow['mtime'] = datetime.datetime.utcfromtimestamp(start_time)
self._update_cur.execute(self._update_stmt, flow) self._update_cur.execute(self._update_stmt, flow)
if self._update_cur.rowcount == 0: if self._update_cur.rowcount == 0:
self._update_cur.execute(self._insert_stmt, flow) self._update_cur.execute(self._insert_stmt, flow)
...@@ -256,9 +256,9 @@ class BaseFlowAggregator(object): ...@@ -256,9 +256,9 @@ class BaseFlowAggregator(object):
:return: datetime.datetime object :return: datetime.datetime object
""" """
if type(timestamp) in (int, float): if type(timestamp) in (int, float):
return datetime.datetime.fromtimestamp(timestamp) return datetime.datetime.utcfromtimestamp(timestamp)
elif type(timestamp) != datetime.datetime: elif type(timestamp) != datetime.datetime:
return datetime.datetime.fromtimestamp(0) return datetime.datetime.utcfromtimestamp(0)
else: else:
return timestamp return timestamp
...@@ -312,7 +312,7 @@ class BaseFlowAggregator(object): ...@@ -312,7 +312,7 @@ class BaseFlowAggregator(object):
# close cursor # close cursor
cur.close() cur.close()
def get_top_data(self, start_time, end_time, fields, value_field, data_filter=None, max_hits=100): def get_top_data(self, start_time, end_time, fields, value_field, data_filters=None, max_hits=100):
""" Retrieve top (usage) from this aggregation. """ Retrieve top (usage) from this aggregation.
Fetch data from aggregation source, groups by selected fields, sorts by value_field descending Fetch data from aggregation source, groups by selected fields, sorts by value_field descending
use data_filter to filter before grouping. use data_filter to filter before grouping.
...@@ -338,7 +338,8 @@ class BaseFlowAggregator(object): ...@@ -338,7 +338,8 @@ class BaseFlowAggregator(object):
# query filters, correct start_time for resolution # query filters, correct start_time for resolution
query_params['start_time'] = self._parse_timestamp((int(start_time/self.resolution))*self.resolution) query_params['start_time'] = self._parse_timestamp((int(start_time/self.resolution))*self.resolution)
query_params['end_time'] = self._parse_timestamp(end_time) query_params['end_time'] = self._parse_timestamp(end_time)
if data_filter: if data_filters:
for data_filter in data_filters.split(','):
tmp = data_filter.split('=')[0].strip() tmp = data_filter.split('=')[0].strip()
if tmp in self.agg_fields and data_filter.find('=') > -1: if tmp in self.agg_fields and data_filter.find('=') > -1:
filter_fields.append(tmp) filter_fields.append(tmp)
......
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