Skip to content

Commit

Permalink
Update client logs commands (#1534)
Browse files Browse the repository at this point in the history
* Add system hostname logs commands
* Add api logs command
  • Loading branch information
jleaniz authored Aug 16, 2024
1 parent a6ba665 commit 19326b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
38 changes: 38 additions & 0 deletions turbinia/api/cli/turbinia_client/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from turbinia_api_lib.api import turbinia_jobs_api
from turbinia_api_lib.api import turbinia_request_results_api
from turbinia_api_lib.api import turbinia_evidence_api
from turbinia_api_lib.api import turbinia_logs_api
from turbinia_client.core import groups
from turbinia_client.helpers import formatter

Expand Down Expand Up @@ -553,3 +554,40 @@ def get_task_report(ctx: click.Context, task_id: str) -> None:
log.error(
f'Received status code {exception.status} '
f'when calling get_request_report: {exception.body}')


@groups.logs_group.command('system')
@click.pass_context
@click.argument('hostname')
@click.option(
'--num_lines', '-n', help='Maximum number of log lines to retrieve.',
required=False, is_flag=False, default=500)
def get_logs(ctx: click.Context, hostname: str, num_lines: int) -> None:
"""Gets Turbinia system logs."""
client: api_client.ApiClient = ctx.obj.api_client
api_instance = turbinia_logs_api.TurbiniaLogsApi(client)
try:
api_response = api_instance.get_turbinia_logs(hostname, num_lines)
click.echo(api_response)
except exceptions.ApiException as exception:
log.error(
f'Received status code {exception.status} '
f'when calling get_turbinia_logs: {exception.body}')


@groups.logs_group.command('api')
@click.pass_context
@click.option(
'--num_lines', '-n', help='Maximum number of log lines to retrieve.',
required=False, is_flag=False, default=500)
def get_api_server_logs(ctx: click.Context, num_lines: int) -> None:
"""Gets Turbinia system logs."""
client: api_client.ApiClient = ctx.obj.api_client
api_instance = turbinia_logs_api.TurbiniaLogsApi(client)
try:
api_response = api_instance.get_api_server_logs(num_lines)
click.echo(api_response)
except exceptions.ApiException as exception:
log.error(
f'Received status code {exception.status} '
f'when calling get_turbinia_logs: {exception.body}')
6 changes: 6 additions & 0 deletions turbinia/api/cli/turbinia_client/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def report_group():
"""Get reports for Tasks or Requests."""


@click.group('logs')
def logs_group():
"""Get Turbinia logs."""


@click.group('submit')
@click.pass_context
def setup_submit(ctx: click.Context):
try:
Expand Down
1 change: 1 addition & 0 deletions turbinia/api/cli/turbinia_client/turbiniacli_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def main():
cli.add_command(groups.result_group)
cli.add_command(groups.status_group)
cli.add_command(groups.report_group)
cli.add_command(groups.logs_group)
cli.add_command(version)
try:
cli.main()
Expand Down

0 comments on commit 19326b2

Please sign in to comment.