Skip to content
Snippets Groups Projects
Commit 299799e1 authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Fix: Consider the source of a network when updating networks. (Redmine issue: #7618)

parent fad546b6
No related branches found
No related tags found
No related merge requests found
...@@ -382,7 +382,7 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript): ...@@ -382,7 +382,7 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript):
self._check_emails(abuse_group_dict, wi_file_data) self._check_emails(abuse_group_dict, wi_file_data)
self._groups_create_missing(abuse_group_dict, wi_file_data, wi_file_type, result, status_only) self._groups_create_missing(abuse_group_dict, wi_file_data, wi_file_type, result, status_only)
self._groups_remove_extra(abuse_group_dict, wi_file_data, wi_file_type, result, status_only) self._groups_remove_extra(abuse_group_dict, wi_file_data, wi_file_type, result, status_only)
self._groups_update_existing(abuse_group_dict, wi_file_data, result, status_only) self._groups_update_existing(abuse_group_dict, wi_file_data, wi_file_type, result, status_only)
return result return result
...@@ -558,13 +558,14 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript): ...@@ -558,13 +558,14 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript):
result['delete'][gkey].append(nkey) result['delete'][gkey].append(nkey)
self.logger.warning("'%s' Network '%s' was not found in loaded whois file, consider deletion.", gkey, nkey) self.logger.warning("'%s' Network '%s' was not found in loaded whois file, consider deletion.", gkey, nkey)
def _groups_update_existing(self, abuse_group_dict, wi_file_data, result, status_only): def _groups_update_existing(self, abuse_group_dict, wi_file_data, wi_file_type, result, status_only):
""" """
Update existing abuse groups and their appropriate whois records within Update existing abuse groups and their appropriate whois records within
the database. the database.
:param dict abuse_group_dict: Abuse groups and network records loaded from database. :param dict abuse_group_dict: Abuse groups and network records loaded from database.
:param dict wi_file_data: Abuse groups and network records loaded from reference whois file. :param dict wi_file_data: Abuse groups and network records loaded from reference whois file.
:param str wi_file_type: Value of ``__whois_type__`` meta attribute from reference whois file.
:param dict result: Structure containing processing log, will be appended to script runlog. :param dict result: Structure containing processing log, will be appended to script runlog.
:param bool status_only: Do not actually perform any database operations, just report status. :param bool status_only: Do not actually perform any database operations, just report status.
""" """
...@@ -576,16 +577,18 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript): ...@@ -576,16 +577,18 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript):
self._group_update_networks( self._group_update_networks(
abuse_group_dict[group_name], abuse_group_dict[group_name],
[network for networks in wi_file_data[name].values() for network in networks], [network for networks in wi_file_data[name].values() for network in networks],
wi_file_type,
result, result,
status_only) status_only)
self.sqlservice.session.commit() self.sqlservice.session.commit()
def _group_update_networks(self, group, networks, result, status_only): def _group_update_networks(self, group, networks, wi_file_type, result, status_only):
""" """
Update abuse group network list coming from given source. Update abuse group network list coming from given source.
:param mentat.datatype.sqldb.GroupModel group: Abuse group to be processed. :param mentat.datatype.sqldb.GroupModel group: Abuse group to be processed.
:param list networks: List of network records loaded from reference whois file. :param list networks: List of network records loaded from reference whois file.
:param str wi_file_type: Value of ``__whois_type__`` meta attribute from reference whois file.
:param dict result: Structure containing processing log, will be appended to script runlog. :param dict result: Structure containing processing log, will be appended to script runlog.
:param bool status_only: Do not actually perform any database operations, just report status. :param bool status_only: Do not actually perform any database operations, just report status.
""" """
...@@ -627,7 +630,7 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript): ...@@ -627,7 +630,7 @@ class MentatNetmngrScript(mentat.script.fetcher.FetcherScript):
group.networks[index].is_base = net['is_base'] group.networks[index].is_base = net['is_base']
for net in group.networks: for net in group.networks:
if not self._is_network_in(net, networks): if not self._is_network_in(net, networks) and wi_file_type in net.source:
nkey = '{}::{}'.format(net.network, net.source) nkey = '{}::{}'.format(net.network, net.source)
result['delete'].setdefault(gkey, []).append(nkey) result['delete'].setdefault(gkey, []).append(nkey)
if status_only: if status_only:
......
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