Skip to content
Snippets Groups Projects
Commit c2090bfc authored by Jan Mach's avatar Jan Mach
Browse files

Fixed the netmngr module to work with latest whois library.

(Redmine issue: #3385)
parent 6fa14513
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,8 @@ import pyzenkit.jsonconf ...@@ -30,7 +30,8 @@ import pyzenkit.jsonconf
import pyzenkit.zenscript import pyzenkit.zenscript
import mentat.const import mentat.const
import mentat.storage import mentat.storage
import mentat.whois import mentat.datatype.internal
import mentat.datatype.mongodb
CONFIG_DATABASE = 'database' CONFIG_DATABASE = 'database'
...@@ -181,7 +182,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -181,7 +182,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
# comparisons. # comparisons.
processed_data = collections.defaultdict(dict) processed_data = collections.defaultdict(dict)
for network_data in whois_file_data.values(): for network_data in whois_file_data.values():
nwr = mentat.whois.NetworkRecord(network_data, source = whois_file_type) nwr = mentat.datatype.internal.t_network_record(network_data, source = whois_file_type)
nwrkey = str(nwr) nwrkey = str(nwr)
for abuse_group in network_data['resolved_abuses']: for abuse_group in network_data['resolved_abuses']:
processed_data[abuse_group][nwrkey] = nwr processed_data[abuse_group][nwrkey] = nwr
...@@ -196,13 +197,15 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -196,13 +197,15 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
for group_name in sorted(wi_file_data.keys()): for group_name in sorted(wi_file_data.keys()):
if not group_name in abuse_group_dict: 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)) 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, '_id': group_name,
'networks': wi_file_data[group_name].values() 'networks': wi_file_data[group_name].values()
}) })
pprint.pprint(abg) pprint.pprint(abg)
pprint.pprint(abg['networks'][0]['_id']) 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): def _groups_remove_extra(self, abuse_group_dict, wi_file_data, wi_file_type):
""" """
...@@ -230,7 +233,9 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -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)) 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)
pprint.pprint(abg['_id']) 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 # OPERATION CALLBACK IMPLEMENTATIONS
...@@ -270,8 +275,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -270,8 +275,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
# Check 01: The abuse group should have any related networks defined, # Check 01: The abuse group should have any related networks defined,
# otherwise it might be useless (with exception of '__UNKNOWN__' group). # otherwise it might be useless (with exception of '__UNKNOWN__' group).
# #
network_count = len(abuse_group['networks']) if not 'networks' in abuse_group or not len(abuse_group['networks']) > 0:
if not 'networks' in abuse_group or not network_count > 0:
self.logger.warning("'{}::{}' Abuse group does not have any networks defined, consider deletion".format(group_source, group_name)) self.logger.warning("'{}::{}' Abuse group does not have any networks defined, consider deletion".format(group_source, group_name))
continue continue
...@@ -290,7 +294,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -290,7 +294,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
# #
for network in abuse_group['networks']: for network in abuse_group['networks']:
try: try:
nwr = mentat.whois.NetworkRecord(network) nwr = mentat.datatype.internal.t_network_record(network)
nwrkey = str(nwr) nwrkey = str(nwr)
self.logger.debug("'{}::{}' Network record '{}::{}'".format(group_source, group_name, nwr['source'], nwrkey)) self.logger.debug("'{}::{}' Network record '{}::{}'".format(group_source, group_name, nwr['source'], nwrkey))
...@@ -335,7 +339,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript): ...@@ -335,7 +339,7 @@ class MentatNetmngrScript(pyzenkit.zenscript.ZenScript):
for abuse_group in self.collection.find(sort = [('_id', 1)]): for abuse_group in self.collection.find(sort = [('_id', 1)]):
group_name = abuse_group.get('_id') 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.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) self._groups_add_missing(abuse_group_dict, wi_file_data, wi_file_type)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment