Skip to content

Commit

Permalink
[CLI+APIclient] Change timeline color for a given timeline (#3159)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaegeral authored Aug 22, 2024
1 parent 5d25ece commit 809ad2d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api_client/python/timesketch_api_client/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def color(self):
self._color = timeline["objects"][0]["color"]
return self._color

@color.setter
def color(self, color):
"""Change the color of the timeline."""
self._color = color
self._commit()

@property
def data_sources(self):
"""Property that returns the timeline data sources."""
Expand Down
29 changes: 28 additions & 1 deletion cli_client/python/timesketch_cli_client/commands/timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def list_timelines(ctx):


@timelines_group.command("describe")
@click.argument("timeline-id", type=int, required=False)
@click.argument("timeline-id", type=int, required=True)
@click.pass_context
def describe_timeline(ctx, timeline_id):
"""Show details for a timeline.
Expand All @@ -62,6 +62,7 @@ def describe_timeline(ctx, timeline_id):
click.echo(f"Status: {timeline.status}")
lines_indexed = timeline.resource_data.get("meta").get("lines_indexed", 0)
click.echo(f"Event count: {lines_indexed or 0}")
click.echo(f"Color: {timeline.color}")

for timeline_object in timeline.resource_data.get("objects", None):
name = timeline_object.get("name", "no name")
Expand Down Expand Up @@ -136,3 +137,29 @@ def delete_timeline(ctx, timeline_id):

click.echo("Deleted")
return


@timelines_group.command("color")
@click.argument("timeline-id", type=int, required=True)
@click.argument("color", type=str, required=True)
@click.pass_context
def timeline_change_color(ctx, timeline_id, color):
"""Change the color of a timeline (in HEX color code)
Args:
ctx: Click CLI context object.
timeline-id: Timeline ID from argument to be modified.
color: Hex value of color to be used for the timeline
"""
sketch = ctx.obj.sketch
timeline = sketch.get_timeline(timeline_id=timeline_id)
if not timeline:
click.echo("No such timeline")
return
if not (len(color) == 4 or len(color) == 6):
click.echo("Color must be hex without leading # e.g. AAAA or AABB11")
return
timeline.lazyload_data()
timeline.color = color

return
65 changes: 64 additions & 1 deletion docs/guides/user/cli-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,25 @@ timesketch --sketch 1 timelines list

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

### Describe a timeline

The command `timelines describe` will provide several variables, names and settings for a given timeline.

```
timesketch --sketch 1 --output-format text timelines describe 2
Name: foobar3
Index: 41dde394812d44c1ac1784997d05efed
Status: ready
Event count: 260454
Color: AAAAAA
Name: foobar3
Created: 2024-08-20T14:57:59.047015
Datasources:
Original filename: win7-x86.plaso
File on disk: /tmp/4c3c1c5c351b4db285453bff0ecad51e
Error:
```

### Rename timeline

To rename a single timeline in a sketch, the command `timelines rename` can be used.
Expand All @@ -538,4 +557,48 @@ As of August 2024, the API method to delete a timeline does only mark the refere
timesketch --sketch 1 timelines delete 1
Confirm to mark the timeline deleted:: 1 foobar23? [y/N]: y
Deleted
```
```

### Change timeline color

The color is an important setting for a timeline when using the WebUI. To change the color using the CLI `timelines color` can be used.

Before:
```bash
timesketch --sketch 1 --output-format text timelines describe 2
Name: foobar3
Index: 41dde394812d44c1ac1784997d05efed
Status: ready
Event count: 260454
Color: AAAAAA
Name: foobar3
Created: 2024-08-20T14:57:59.047015
Datasources:
Original filename: win7-x86.plaso
File on disk: /tmp/4c3c1c5c351b4db285453bff0ecad51e
Error:
```

Using it:

```bash
timesketch --sketch 1 timelines color 2 BBBBBB
```

After:

```bash
timesketch --sketch 1 --output-format text timelines describe 2
Name: foobar3
Index: 41dde394812d44c1ac1784997d05efed
Status: ready
Event count: 260454
Color: BBBBBB
Name: foobar3
Created: 2024-08-20T14:57:59.047015
Datasources:
Original filename: win7-x86.plaso
File on disk: /tmp/4c3c1c5c351b4db285453bff0ecad51e
Error:
```

0 comments on commit 809ad2d

Please sign in to comment.