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
e930cc47
Commit
e930cc47
authored
Apr 19, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(netflow, flowd agg) add last_seen (within timeslot) to aggregates
parent
09867b53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
aggregate.py
src/opnsense/scripts/netflow/lib/aggregate.py
+7
-4
No files found.
src/opnsense/scripts/netflow/lib/aggregate.py
View file @
e930cc47
...
...
@@ -121,10 +121,12 @@ class BaseFlowAggregator(object):
self
.
_update_cur
=
None
self
.
_known_targets
=
list
()
# construct update and insert sql statements
tmp
=
'update timeserie set octets = octets + :octets_consumed, packets = packets + :packets_consumed '
tmp
=
'update timeserie set last_seen = :flow_end, '
tmp
+=
'octets = octets + :octets_consumed, packets = packets + :packets_consumed '
tmp
+=
'where mtime = :mtime and
%
s '
self
.
_update_stmt
=
tmp
%
(
' and '
.
join
(
map
(
lambda
x
:
'
%
s = :
%
s'
%
(
x
,
x
),
self
.
agg_fields
)))
tmp
=
'insert into timeserie (mtime, octets, packets,
%
s) values (:mtime, :octets_consumed, :packets_consumed,
%
s)'
tmp
=
'insert into timeserie (mtime, last_seen, octets, packets,
%
s) '
tmp
+=
'values (:mtime, :flow_end, :octets_consumed, :packets_consumed,
%
s)'
self
.
_insert_stmt
=
tmp
%
(
','
.
join
(
self
.
agg_fields
),
','
.
join
(
map
(
lambda
x
:
':
%
s'
%
x
,
self
.
agg_fields
)))
# open database
self
.
_open_db
()
...
...
@@ -157,7 +159,8 @@ class BaseFlowAggregator(object):
# construct new aggregate table
sql_text
=
list
()
sql_text
.
append
(
'create table timeserie ( '
)
sql_text
.
append
(
' mtime timestamp'
)
sql_text
.
append
(
' mtime timestamp'
)
sql_text
.
append
(
', last_seen timestamp'
)
for
agg_field
in
self
.
agg_fields
:
sql_text
.
append
(
',
%
s varchar(255)'
%
agg_field
)
sql_text
.
append
(
', octets numeric'
)
...
...
@@ -348,7 +351,7 @@ class BaseFlowAggregator(object):
if
len
(
select_fields
)
>
0
:
# construct sql query to filter and select data
sql_select
=
'select
%
s'
%
','
.
join
(
select_fields
)
sql_select
+=
',
%
s as total
\n
'
%
value_sql
sql_select
+=
',
%
s as total
, max(last_seen) last_seen
\n
'
%
value_sql
sql_select
+=
'from timeserie
\n
'
sql_select
+=
'where mtime >= :start_time and mtime < :end_time
\n
'
for
filter_field
in
filter_fields
:
...
...
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