Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update report filtering #1358

Merged
merged 8 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions turbinia/api/cli/turbinia_client/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ def get_jobs(ctx: click.Context) -> None:
@click.pass_context
@click.argument('request_id')
@click.option(
'--show_all', '-a', help='Shows all field regardless of priority.',
'--priority_filter', '-p', help='This sets what report sections are '
'shown in full detail in report output. Any tasks that have set a '
'report_priority value equal to or lower than this setting will be '
'shown in full detail, and tasks with a higher value will only have '
'a summary shown. To see all tasks report output in full detail, '
'set --priority_filter=100', is_flag=True, required=False)
@click.option(
'--show_all', '-a', help='Shows all fields including saved output paths.',
is_flag=True, required=False)
@click.option(
'--json_dump', '-j', help='Generates JSON output.', is_flag=True,
required=False)
def get_request(
ctx: click.Context, request_id: str, show_all: bool,
ctx: click.Context, request_id: str, priority_filter: int, show_all: bool,
json_dump: bool) -> None:
"""Gets Turbinia request status."""
client: api_client.ApiClient = ctx.obj.api_client
Expand All @@ -145,7 +152,7 @@ def get_request(
formatter.echo_json(api_response)
else:
report = formatter.RequestMarkdownReport(api_response).generate_markdown(
show_all=show_all)
priority_filter=priority_filter, show_all=show_all)
click.echo(report)
except exceptions.ApiException as exception:
log.error(
Expand Down
39 changes: 24 additions & 15 deletions turbinia/api/cli/turbinia_client/helpers/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def __init__(self, request_data: dict = None):
super().__init__()
self._request_data: dict = request_data

def generate_markdown(self, show_all=False, compact=False) -> str:
def generate_markdown(
self, priority_filter=None, show_all=False, compact=False) -> str:
"""Generate a markdown report."""
report: list[str] = []
task: dict = self._request_data
Expand All @@ -291,24 +292,30 @@ def generate_markdown(self, show_all=False, compact=False) -> str:
name = f'{task.get("name")} ({"LOW PRIORITY"})'

try:
report.append(self.heading2(name))
line = f"{self.bold('Evidence:'):s} {task.get('evidence_name')!s}"
report.append(self.bullet(line))
line = f"{self.bold('Status:'):s} {task.get('status')!s}"
report.append(self.bullet(line))
if show_all or priority <= MEDIUM_PRIORITY:
# Only show Task details if the Task has more priority than the
# priority_filter
if priority > priority_filter:
report.append(f'{self.heading2(name)}: {task.get("status")!s}')
else:
report.append(self.heading2(name))
line = f"{self.bold('Evidence:'):s} {task.get('evidence_name')!s}"
report.append(self.bullet(line))
line = f"{self.bold('Status:'):s} {task.get('status')!s}"
report.append(self.bullet(line))

report.append(self.bullet(f"Task Id: {task.get('id')!s}"))
report.append(
self.bullet(f"Executed on worker {task.get('worker_name')!s}"))
if show_all or priority <= HIGH_PRIORITY:

if task.get('report_data'):
if not compact:
report.append('')
report.append(self.heading3('Task Reported Data'))
report.extend(task.get('report_data').splitlines())
if not compact:
report.append('')
if show_all or priority <= CRITICAL_PRIORITY:

if show_all and priority <= priority_filter:
if not compact:
report.append('')
report.append(self.heading3('Saved Task Files:'))
Expand All @@ -318,6 +325,8 @@ def generate_markdown(self, show_all=False, compact=False) -> str:
report.append(self.bullet(self.code(path)))
if not compact:
report.append('')
else:
report.append('No saved files')
report.append('')
except TypeError as exception:
log.warning(f'Error formatting the Markdown report: {exception!s}')
Expand Down Expand Up @@ -433,7 +442,7 @@ def __init__(self, workers_status: dict, days: int):

def generate_markdown(self) -> str:
"""Generates a Markdown version of tasks per worker.

Returns:
markdown (str): Markdown version of tasks per worker.
"""
Expand Down Expand Up @@ -486,7 +495,7 @@ def __init__(self, statistics: dict):

def stat_to_row(self, task: str, stat_dict: dict):
"""Generates a row of the statistics table.

Args:
task (str): Name of the current task.
stat_dict (dict): Dictionary with information about current row.
Expand All @@ -502,8 +511,8 @@ def generate_data_frame(self) -> pandas.DataFrame:

Args:
markdown (bool): Bool defining if the tasks should be in markdown format.
Returns:

Returns:
data_frame (DataFrame): Statistics table in pandas DataFrame format.
"""
for stat_group, stat_dict in self._statistics.items():
Expand All @@ -520,7 +529,7 @@ def generate_data_frame(self) -> pandas.DataFrame:

def generate_markdown(self) -> str:
"""Generates a Markdown version of task statistics.

Returns:
markdown(str): Markdown version of task statistics.
"""
Expand All @@ -532,7 +541,7 @@ def generate_markdown(self) -> str:

def generate_csv(self) -> str:
"""Generates a CSV version of task statistics.

Returns:
csv(str): CSV version of task statistics.
"""
Expand Down
Loading