Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
0468bfd1
Commit
0468bfd1
authored
Apr 19, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(netflow, flowd agg) store dates in utc, accept multiple filters in get_top_data
parent
3c2aad98
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
aggregate.py
src/opnsense/scripts/netflow/lib/aggregate.py
+10
-9
No files found.
src/opnsense/scripts/netflow/lib/aggregate.py
View file @
0468bfd1
...
@@ -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
.
utc
fromtimestamp
(
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
.
utc
fromtimestamp
(
timestamp
)
elif
type
(
timestamp
)
!=
datetime
.
datetime
:
elif
type
(
timestamp
)
!=
datetime
.
datetime
:
return
datetime
.
datetime
.
fromtimestamp
(
0
)
return
datetime
.
datetime
.
utc
fromtimestamp
(
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_filter
s
=
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment