diff --git a/lib/cuckoo/core/plugins.py b/lib/cuckoo/core/plugins.py index 86aa0a040d5..8fc94fd4f31 100644 --- a/lib/cuckoo/core/plugins.py +++ b/lib/cuckoo/core/plugins.py @@ -702,11 +702,11 @@ def __init__(self, task, results, reprocess=False): self.analysis_path = os.path.join(CUCKOO_ROOT, "storage", "analyses", str(task["id"])) self.cfg = reporting_cfg self.reprocess = reprocess + self.reporting_errors = 0 def process(self, module): """Run a single reporting module. @param module: reporting module. - @param results: results results from analysis. """ # Initialize current reporting module. try: @@ -734,7 +734,7 @@ def process(self, module): current.set_path(self.analysis_path) # Give it the analysis task object. current.set_task(self.task) - # Give it the the relevant reporting.conf section. + # Give it the relevant reporting.conf section. current.set_options(options) # Load the content of the analysis.conf file. current.cfg = AnalysisConfig(current.conf_path) @@ -753,14 +753,18 @@ def process(self, module): except CuckooDependencyError as e: log.warning('The reporting module "%s" has missing dependencies: %s', current.__class__.__name__, e) + self.reporting_errors += 1 except CuckooReportError as e: log.warning('The reporting module "%s" returned the following error: %s', current.__class__.__name__, e) + self.reporting_errors += 1 except Exception as e: log.exception('Failed to run the reporting module "%s": %s', current.__class__.__name__, e) + self.reporting_errors += 1 def run(self): """Generates all reports. - @raise CuckooReportError: if a report module fails. + + @return a count of the reporting module errors. """ # In every reporting module you can specify a numeric value that # represents at which position that module should be executed among @@ -778,6 +782,7 @@ def run(self): self.process(module) else: log.info("No reporting modules loaded") + return self.reporting_errors class GetFeeds: diff --git a/utils/process.py b/utils/process.py index fc5879485de..5b019fca31a 100644 --- a/utils/process.py +++ b/utils/process.py @@ -38,7 +38,15 @@ from lib.cuckoo.common.constants import CUCKOO_ROOT from lib.cuckoo.common.path_utils import path_delete, path_exists, path_mkdir from lib.cuckoo.common.utils import get_options -from lib.cuckoo.core.database import TASK_COMPLETED, TASK_FAILED_PROCESSING, TASK_REPORTED, Database, Task, init_database +from lib.cuckoo.core.database import ( + TASK_COMPLETED, + TASK_FAILED_PROCESSING, + TASK_FAILED_REPORTING, + TASK_REPORTED, + Database, + Task, + init_database, +) from lib.cuckoo.core.plugins import RunProcessing, RunReporting, RunSignatures from lib.cuckoo.core.startup import ConsoleHandler, check_linux_dist, init_modules @@ -137,9 +145,10 @@ def process( else: reprocess = report - RunReporting(task=task.to_dict(), results=results, reprocess=reprocess).run() + error_count = RunReporting(task=task.to_dict(), results=results, reprocess=reprocess).run() + status = TASK_REPORTED if error_count == 0 else TASK_FAILED_REPORTING with db.session.begin(): - db.set_status(task_id, TASK_REPORTED) + db.set_status(task_id, status) if auto: # Is ok to delete original file, but we need to lookup on delete_bin_copy if no more pendings tasks