Optimised imports and added some documentation

This commit is contained in:
Shay Nehmad 2020-01-19 18:14:59 +02:00
parent d52672f4d7
commit 9583956683
3 changed files with 10 additions and 4 deletions

View File

@ -1,8 +1,5 @@
from common.cloud.all_instances import get_all_cloud_instances from common.cloud.all_instances import get_all_cloud_instances
from common.cloud.aws.aws_instance import AwsInstance from common.cloud.environment_names import ON_PREMISE
from common.cloud.azure.azure_instance import AzureInstance
from common.cloud.environment_names import ON_PREMISE, AZURE, AWS
from common.cloud.instance import CloudInstance
from infection_monkey.system_info.system_info_collector import SystemInfoCollector from infection_monkey.system_info.system_info_collector import SystemInfoCollector

View File

@ -6,6 +6,14 @@ import infection_monkey.system_info.collectors
class SystemInfoCollector(Plugin, metaclass=ABCMeta): class SystemInfoCollector(Plugin, metaclass=ABCMeta):
"""
ABC for system info collection. See system_info_collector_handler for more info. Basically, to implement a new system info
collector, inherit from this class in an implementation in the infection_monkey.system_info.collectors class, and override
the 'collect' method. Don't forget to parse your results in the Monkey Island and to add the collector to the configuration
as well - see monkey_island.cc.services.processing.system_info_collectors for examples.
See the Wiki page "How to add a new System Info Collector to the Monkey?" for a detailed guide.
"""
def __init__(self, name="unknown"): def __init__(self, name="unknown"):
self.name = name self.name = name

View File

@ -21,6 +21,7 @@ class SystemInfoCollectorsHandler(object):
system_info_telemetry[collector.name] = collected_info system_info_telemetry[collector.name] = collected_info
successful_collections += 1 successful_collections += 1
except Exception as e: except Exception as e:
# If we failed one collector, no need to stop execution. Log and continue.
LOG.error("Collector {} failed. Error info: {}".format(collector.name, e)) LOG.error("Collector {} failed. Error info: {}".format(collector.name, e))
LOG.info("All system info collectors executed. Total {} executed, out of which {} collected successfully.". LOG.info("All system info collectors executed. Total {} executed, out of which {} collected successfully.".
format(len(self.collectors_list), successful_collections)) format(len(self.collectors_list), successful_collections))