From 471fede2feec54e364b70d21e8b5ccc9f748548c Mon Sep 17 00:00:00 2001 From: urihershgc Date: Wed, 9 Dec 2015 16:33:44 +0200 Subject: [PATCH] GC-3598: #resolved added process list --- chaos_monkey/system_info/__init__.py | 24 +++++++++++++++++++ .../system_info/linux_info_collector.py | 13 +++++----- .../system_info/windows_info_collector.py | 13 +++++----- 3 files changed, 36 insertions(+), 14 deletions(-) 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