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 turbinia client with new logs commands #1534

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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