diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index f00fbc22c..84633cc81 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -122,6 +122,7 @@ class ReportService: formatted_nodes = [] + # TODO Figure out and improve nodes = \ [NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \ + [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in diff --git a/monkey/monkey_island/cc/utils.py b/monkey/monkey_island/cc/utils.py index 9c49eba2c..3e03d18b9 100644 --- a/monkey/monkey_island/cc/utils.py +++ b/monkey/monkey_island/cc/utils.py @@ -7,6 +7,11 @@ import struct import ipaddress from netifaces import interfaces, ifaddresses, AF_INET +try: + from functools import lru_cache +except ImportError: + from backports.functools_lru_cache import lru_cache + __author__ = 'Barak' @@ -46,9 +51,13 @@ else: # name of interface is (namestr[i:i+16].split('\0', 1)[0] finally: return result -# End of local ips function +# The local IP addresses list should not change often. Therefore, we can cache the result and never call this function +# more than once. This stopgap measure is here since this function is called a lot of times during the report +# generation. +# This means that if the interfaces of the Island machines change, the Island process needs to be restarted. +@lru_cache(maxsize=1) def local_ip_addresses(): ip_list = [] for interface in interfaces(): @@ -57,6 +66,7 @@ def local_ip_addresses(): return ip_list +@lru_cache(maxsize=1) def get_subnets(): subnets = [] for interface in interfaces(): diff --git a/monkey/monkey_island/requirements.txt b/monkey/monkey_island/requirements.txt index e6d81e6aa..92a118b07 100644 --- a/monkey/monkey_island/requirements.txt +++ b/monkey/monkey_island/requirements.txt @@ -26,3 +26,4 @@ mongoengine mongomock requests dpath +backports