Skip to content

Commit

Permalink
add timeline rename functionality to timesketch cli tool (#3156)
Browse files Browse the repository at this point in the history
Co-authored-by: Janosch <[email protected]>
  • Loading branch information
jaegeral and jkppr authored Aug 21, 2024
1 parent 9d2ccde commit 8f00d11
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cli_client/python/timesketch_cli_client/commands/timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,36 @@ def describe_timeline(ctx, timeline_id):
click.echo(f"\tOriginal filename: {original_filename}")
click.echo(f"\tFile on disk: {file_on_disk}")
click.echo(f"\tError: {error_message}")


@timelines_group.command("rename")
@click.argument("timeline-id", type=int, required=True)
@click.argument("new-name", type=str, required=True)
@click.pass_context
def rename_timeline(ctx, timeline_id, new_name):
"""Rename a timeline.
Args:
ctx: Click CLI context object.
timeline-id: Timeline ID from argument.
new-name: New Timeline name
"""
sketch = ctx.obj.sketch
output = ctx.obj.output_format
timeline = sketch.get_timeline(timeline_id=timeline_id)
if not timeline:
click.echo("No such timeline")
return
timeline.lazyload_data()

# Set new name
timeline.name = new_name

# Print output depending on output settings
if output == "json":
click.echo(f"{timeline.resource_data}")
return
if output != "text":
click.echo(f'Unsupported output format: "{output}" - using "text" instead')
else:
click.echo(f"New name: {timeline.name}")
25 changes: 24 additions & 1 deletion docs/guides/user/cli-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,27 @@ It is also possible to provide a comma separated list of tags to remove. The fol
```bash
timesketch events remove_tag --timeline-id 4 --event-id k8P1MYcBkeTGnypeeKJL --tag foobar333,fooba123
200
```
```

## Timelines

### List timelines

To list all timelines in a given sketch use: `timelines list`.

```bash
timesketch --sketch 1 timelines list
1 foobar
2 foobar3
```

It is also possible to get all the output as JSON.

### Rename timeline

To rename a single timeline in a sketch, the command `timelines rename` can be used.

```bash
timesketch --sketch 1 timelines rename 1 foobar23
```

0 comments on commit 8f00d11

Please sign in to comment.