diff --git a/chaos_monkey/system_info/__init__.py b/chaos_monkey/system_info/__init__.py index dcedc89e4..a4e82a23a 100644 --- a/chaos_monkey/system_info/__init__.py +++ b/chaos_monkey/system_info/__init__.py @@ -1,4 +1,6 @@ import sys +import socket +import psutil from enum import IntEnum __author__ = 'uri' @@ -32,3 +34,25 @@ class SystemInfoCollector(object): return OperatingSystem.Windows else: return OperatingSystem.Linux + + +class InfoCollector(object): + """ + Generic Info Collection module + """ + def __init__(self): + self.info = {} + + def get_hostname(self): + self.info['hostname'] = socket.gethostname() + + def get_process_list(self): + processes = {} + for process in psutil.process_iter(): + processes[process.pid] = {"name": process.name(), + "pid": process.pid, + "ppid": process.ppid(), + "cmdline": " ".join(process.cmdline()), + "full_image_path": process.exe(), + } + self.info['process_list'] = processes diff --git a/chaos_monkey/system_info/linux_info_collector.py b/chaos_monkey/system_info/linux_info_collector.py index 40be691ea..e88773741 100644 --- a/chaos_monkey/system_info/linux_info_collector.py +++ b/chaos_monkey/system_info/linux_info_collector.py @@ -1,19 +1,18 @@ -import socket +from . import InfoCollector + __author__ = 'uri' -class LinuxInfoCollector(object): +class LinuxInfoCollector(InfoCollector): """ System information collecting module for Linux operating systems """ def __init__(self): - self.info = {} - - def collect(self): - self.info['hostname'] = socket.gethostname() + super(LinuxInfoCollector, self).__init__() def get_info(self): - self.collect() + self.get_hostname() + self.get_process_list() return self.info diff --git a/chaos_monkey/system_info/windows_info_collector.py b/chaos_monkey/system_info/windows_info_collector.py index d58700495..b979ee87b 100644 --- a/chaos_monkey/system_info/windows_info_collector.py +++ b/chaos_monkey/system_info/windows_info_collector.py @@ -1,18 +1,17 @@ -import socket +from . import InfoCollector + __author__ = 'uri' -class WindowsInfoCollector(object): +class WindowsInfoCollector(InfoCollector): """ System information collecting module for Windows operating systems """ def __init__(self): - self.info = {} - - def collect(self): - self.info['hostname'] = socket.gethostname() + super(WindowsInfoCollector, self).__init__() def get_info(self): - self.collect() + self.get_hostname() + self.get_process_list() return self.info