Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
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
Mentat
mentat-test
Commits
c2090bfc
Commit
c2090bfc
authored
7 years ago
by
Jan Mach
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the netmngr module to work with latest whois library.
(Redmine issue: #3385)
parent
6fa14513
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/mentat-netmngr.py
+13
-9
13 additions, 9 deletions
bin/mentat-netmngr.py
with
13 additions
and
9 deletions
bin/mentat-netmngr.py
+
13
−
9
View file @
c2090bfc
...
...
@@ -30,7 +30,8 @@ import pyzenkit.jsonconf
import
pyzenkit.zenscript
import
mentat.const
import
mentat.storage
import
mentat.whois
import
mentat.datatype.internal
import
mentat.datatype.mongodb
CONFIG_DATABASE
=
'
database
'
...
...
@@ -181,7 +182,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
# comparisons.
processed_data
=
collections
.
defaultdict
(
dict
)
for
network_data
in
whois_file_data
.
values
():
nwr
=
mentat
.
whois
.
N
etwork
R
ecord
(
network_data
,
source
=
whois_file_type
)
nwr
=
mentat
.
datatype
.
internal
.
t_n
etwork
_r
ecord
(
network_data
,
source
=
whois_file_type
)
nwrkey
=
str
(
nwr
)
for
abuse_group
in
network_data
[
'
resolved_abuses
'
]:
processed_data
[
abuse_group
][
nwrkey
]
=
nwr
...
...
@@ -196,13 +197,15 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
for
group_name
in
sorted
(
wi_file_data
.
keys
()):
if
not
group_name
in
abuse_group_dict
:
self
.
logger
.
warning
(
"'
{}
'
Inserting missing abuse group defined in loaded
'
{}
'
whois file
"
.
format
(
group_name
,
wi_file_type
))
abg
=
mentat
.
whois
.
AbuseGroup
({
abg
=
mentat
.
datatype
.
internal
.
AbuseGroup
({
'
_id
'
:
group_name
,
'
networks
'
:
wi_file_data
[
group_name
].
values
()
})
pprint
.
pprint
(
abg
)
pprint
.
pprint
(
abg
[
'
networks
'
][
0
][
'
_id
'
])
self
.
collection
.
insert_one
(
abg
.
export
())
abgm
=
mentat
.
datatype
.
mongodb
.
AbuseGroup
(
abg
)
self
.
collection
.
insert_one
(
abgm
)
def
_groups_remove_extra
(
self
,
abuse_group_dict
,
wi_file_data
,
wi_file_type
):
"""
...
...
@@ -230,7 +233,9 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
self
.
logger
.
warning
(
"'
{}
'
Abuse group network change according to loaded
'
{}
'
whois file: {}
"
.
format
(
group_name
,
wi_file_type
,
chl
))
pprint
.
pprint
(
abg
)
pprint
.
pprint
(
abg
[
'
_id
'
])
self
.
collection
.
update_one
({
'
_id
'
:
abg
[
'
_id
'
]},
{
'
$set
'
:
{
'
networks
'
:
abg
.
export
()[
'
networks
'
]}})
abgm
=
mentat
.
datatype
.
mongodb
.
AbuseGroup
(
abg
)
self
.
collection
.
update_one
({
'
_id
'
:
abg
[
'
_id
'
]},
{
'
$set
'
:
{
'
networks
'
:
abg
[
'
networks
'
]}})
#---------------------------------------------------------------------------
# OPERATION CALLBACK IMPLEMENTATIONS
...
...
@@ -270,8 +275,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
# Check 01: The abuse group should have any related networks defined,
# otherwise it might be useless (with exception of '__UNKNOWN__' group).
#
network_count
=
len
(
abuse_group
[
'
networks
'
])
if
not
'
networks
'
in
abuse_group
or
not
network_count
>
0
:
if
not
'
networks
'
in
abuse_group
or
not
len
(
abuse_group
[
'
networks
'
])
>
0
:
self
.
logger
.
warning
(
"'
{}::{}
'
Abuse group does not have any networks defined, consider deletion
"
.
format
(
group_source
,
group_name
))
continue
...
...
@@ -290,7 +294,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
#
for
network
in
abuse_group
[
'
networks
'
]:
try
:
nwr
=
mentat
.
whois
.
N
etwork
R
ecord
(
network
)
nwr
=
mentat
.
datatype
.
internal
.
t_n
etwork
_r
ecord
(
network
)
nwrkey
=
str
(
nwr
)
self
.
logger
.
debug
(
"'
{}::{}
'
Network record
'
{}::{}
'"
.
format
(
group_source
,
group_name
,
nwr
[
'
source
'
],
nwrkey
))
...
...
@@ -335,7 +339,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
for
abuse_group
in
self
.
collection
.
find
(
sort
=
[(
'
_id
'
,
1
)]):
group_name
=
abuse_group
.
get
(
'
_id
'
)
abuse_group_dict
[
group_name
]
=
mentat
.
whois
.
AbuseGroup
(
abuse_group
)
abuse_group_dict
[
group_name
]
=
mentat
.
datatype
.
internal
.
AbuseGroup
(
abuse_group
)
self
.
logger
.
info
(
"
Number of abuse groups in database:
'
{}
'"
.
format
(
len
(
abuse_group_dict
)))
self
.
_groups_add_missing
(
abuse_group_dict
,
wi_file_data
,
wi_file_type
)
...
...
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