Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden Connectors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Warden
Warden Connectors
Commits
150ddb93
Commit
150ddb93
authored
9 years ago
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Python 2.6 compatibility changes
parent
744ba6c1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flowmon-ads/warden3_flowmon_ads_filer.py
+43
-12
43 additions, 12 deletions
flowmon-ads/warden3_flowmon_ads_filer.py
with
43 additions
and
12 deletions
flowmon-ads/warden3_flowmon_ads_filer.py
100755 → 100644
+
43
−
12
View file @
150ddb93
#!/usr/bin/python
#!/usr/bin/python
26
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011-2015 Cesnet z.s.p.o
# Use of this source is governed by a 3-clause BSD-style license, see LICENSE file.
import
os
import
sys
sys
.
path
.
append
(
'
/data/warden/libs
'
)
from
warden_client
import
read_cfg
,
format_time
from
warden_filer
import
SafeDir
import
json
import
csv
import
sys
from
time
import
strptime
,
mktime
from
uuid
import
uuid4
# Conversion/validation routines
def
isotime
(
t
):
return
strptime
(
t
,
"
%Y-%m-%d %H:%M:%S
"
)
if
t
else
None
if
not
t
:
return
None
return
strptime
(
t
,
"
%Y-%m-%d %H:%M:%S
"
)
def
intlist
(
il
):
return
[
int
(
i
.
strip
())
for
i
in
il
.
split
(
"
,
"
)]
if
il
else
[]
if
not
il
:
return
[]
return
[
int
(
i
.
strip
())
for
i
in
il
.
split
(
"
,
"
)]
def
strlist
(
sl
):
return
[
str
(
s
)
for
s
in
sl
.
split
(
"
,
"
)]
if
sl
else
[]
if
not
sl
:
return
[]
return
[
str
(
s
)
for
s
in
sl
.
split
(
"
,
"
)]
def
ip
(
s
):
return
s
.
strip
()
if
s
else
None
if
not
s
:
return
None
return
s
.
strip
()
def
iplist
(
sl
):
return
[
ip
(
s
)
for
s
in
sl
.
split
(
"
,
"
)]
if
sl
else
[]
if
not
sl
:
return
[]
return
[
ip
(
s
)
for
s
in
sl
.
split
(
"
,
"
)]
ads_fieldnames
=
{
...
...
@@ -68,7 +81,9 @@ ads_fieldnames = {
def
xlat_ads_field
(
key
,
val
):
type_
=
ads_fieldnames
[
key
][
"
type
"
]
sval
=
val
.
strip
()
if
val
is
not
None
else
""
sval
=
""
if
val
is
not
None
:
sval
=
val
.
strip
()
return
type_
(
sval
)
...
...
@@ -111,6 +126,8 @@ ads_types = {
def
xlat_ads_type
(
s
):
if
s
not
in
ads_types
.
keys
():
return
[]
return
ads_types
[
s
]
...
...
@@ -152,7 +169,9 @@ def gen_idea_from_ads(ads, anonymised_target):
source
=
{}
if
ads
[
"
Source
"
]:
srcip
=
ads
[
"
Source
"
]
key
=
"
IP4
"
if
not
'
:
'
in
srcip
else
"
IP6
"
key
=
"
IP6
"
if
not
'
:
'
in
srcip
:
key
=
"
IP4
"
source
[
key
]
=
[
srcip
]
if
ads
[
"
CapturedSource
"
]:
...
...
@@ -166,9 +185,16 @@ def gen_idea_from_ads(ads, anonymised_target):
if
ads
[
"
Protocol
"
]:
target
[
"
Proto
"
]
=
[
xlat_ads_proto
(
p
)
for
p
in
ads
[
"
Protocol
"
]]
tgtips
=
[
anonymised_target
]
if
anonymised_target
else
ads
[
"
Targets
"
]
if
anonymised_target
:
tgtips
=
[
anonymised_target
]
else
:
tgtips
=
ads
[
"
Targets
"
]
for
tgtip
in
tgtips
:
key
=
"
IP4
"
if
not
'
:
'
in
tgtip
else
"
IP6
"
if
not
'
:
'
in
tgtip
:
key
=
"
IP4
"
else
:
key
=
"
IP6
"
target
.
setdefault
(
key
,
[]).
append
(
tgtip
)
# Insert subnodes into event
...
...
@@ -191,9 +217,14 @@ def main():
row
[
k
]
=
xlat_ads_field
(
k
,
row
[
k
])
event
=
gen_idea_from_ads
(
row
,
anonymised_target
)
nf
=
sdir
.
newfile
()
with
nf
.
f
as
f
:
try
:
f
=
nf
.
f
data
=
json
.
dumps
(
event
)
f
.
write
(
data
)
except
IOError
,
e
:
f
.
close
()
else
:
f
.
close
()
nf
.
moveto
(
sdir
.
incoming
)
...
...
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