mirror of https://github.com/mvt-project/mvt.git
Added optional file logging
This commit is contained in:
parent
cd87b6ed31
commit
dd230c2407
|
@ -16,6 +16,8 @@ class Command(object):
|
||||||
def __init__(self, target_path=None, results_path=None, ioc_files=[],
|
def __init__(self, target_path=None, results_path=None, ioc_files=[],
|
||||||
module_name=None, serial=None, fast_mode=False,
|
module_name=None, serial=None, fast_mode=False,
|
||||||
log=logging.getLogger(__name__)):
|
log=logging.getLogger(__name__)):
|
||||||
|
self.name = ""
|
||||||
|
|
||||||
self.target_path = target_path
|
self.target_path = target_path
|
||||||
self.results_path = results_path
|
self.results_path = results_path
|
||||||
self.ioc_files = ioc_files
|
self.ioc_files = ioc_files
|
||||||
|
@ -46,13 +48,25 @@ class Command(object):
|
||||||
|
|
||||||
def _store_timeline(self):
|
def _store_timeline(self):
|
||||||
if self.results_path:
|
if self.results_path:
|
||||||
if len(self.timeline) > 0:
|
return
|
||||||
save_timeline(self.timeline,
|
|
||||||
os.path.join(self.results_path, "timeline.csv"))
|
|
||||||
|
|
||||||
if len(self.timeline_detected) > 0:
|
if len(self.timeline) > 0:
|
||||||
save_timeline(self.timeline_detected,
|
save_timeline(self.timeline,
|
||||||
os.path.join(self.results_path, "timeline_detected.csv"))
|
os.path.join(self.results_path, "timeline.csv"))
|
||||||
|
|
||||||
|
if len(self.timeline_detected) > 0:
|
||||||
|
save_timeline(self.timeline_detected,
|
||||||
|
os.path.join(self.results_path, "timeline_detected.csv"))
|
||||||
|
|
||||||
|
def _add_log_file_handler(self, logger):
|
||||||
|
if not self.results_path:
|
||||||
|
return
|
||||||
|
|
||||||
|
fh = logging.FileHandler(os.path.join(self.results_path, "command.log"))
|
||||||
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
|
fh.setLevel(logging.DEBUG)
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -62,6 +76,7 @@ class Command(object):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._create_storage()
|
self._create_storage()
|
||||||
|
self._add_log_file_handler(self.log)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.init()
|
self.init()
|
||||||
|
@ -72,8 +87,13 @@ class Command(object):
|
||||||
if self.module_name and module.__name__ != self.module_name:
|
if self.module_name and module.__name__ != self.module_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
m = module(target_path=self.target_path, results_path=self.results_path, fast_mode=self.fast_mode,
|
module_logger = logging.getLogger(module.__module__)
|
||||||
log=logging.getLogger(module.__module__))
|
self._add_log_file_handler(module_logger)
|
||||||
|
|
||||||
|
m = module(target_path=self.target_path,
|
||||||
|
results_path=self.results_path,
|
||||||
|
fast_mode=self.fast_mode,
|
||||||
|
log=module_logger)
|
||||||
|
|
||||||
if self.iocs.total_ioc_count:
|
if self.iocs.total_ioc_count:
|
||||||
m.indicators = self.iocs
|
m.indicators = self.iocs
|
||||||
|
@ -93,3 +113,4 @@ class Command(object):
|
||||||
self.timeline_detected.extend(m.timeline_detected)
|
self.timeline_detected.extend(m.timeline_detected)
|
||||||
|
|
||||||
self._store_timeline()
|
self._store_timeline()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue