Skip to content

Commit

Permalink
Count failures when running reporting modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoumis committed Nov 18, 2024
1 parent 8433f10 commit 3873a46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 8 additions & 3 deletions lib/cuckoo/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -778,6 +782,7 @@ def run(self):
self.process(module)
else:
log.info("No reporting modules loaded")
return self.reporting_errors


class GetFeeds:
Expand Down
15 changes: 12 additions & 3 deletions utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3873a46

Please sign in to comment.