Skip to content

Commit cd6532e

Browse files
authored
Add timesketch-status to tsctl. (#3303)
1 parent c200f3d commit cd6532e

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

docs/guides/admin/admin-cli.md

+52
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,58 @@ Corresponding Timeline id: 3 in Sketch Id: 2
508508
Corresponding Sketch id: 2 Sketch name: asdasd
509509
```
510510
511+
### Timeline status
512+
513+
The `tsctl timeline-status` command allows to get or set a timeline status.
514+
This can be useful in the following scenarios:
515+
516+
* Monitoring processing In large-scale investigations, timelines can take a considerable amount of time to process.
517+
This feature allows administrators or automated scripts to monitor the processing status of timelines, ensuring that they are progressing as expected.
518+
519+
* Automated Status updates: Scripts can be used to automatically update the status of timelines based on the results of automated analysis or processing steps. For example, if an automated script detects a critical error during analysis, it can set the timeline status to "fail."
520+
521+
* Toubeshooting and Error handling:
522+
** Quickly identifying timelines with a "fail" status allows investigators to troubleshoot issues and re-process data if necessary.
523+
** By monitoring the status of timelines, administrators can identify potential bottlenecks or errors in the processing pipeline.
524+
** Set the status to `fail` is a task is stuck.
525+
526+
Usage:
527+
528+
```bash
529+
tsctl timeline-status [OPTIONS] TIMELINE_ID
530+
--action [get|set]
531+
Specify whether to get or set the timeline status.
532+
- "get": Retrieves the current status of the timeline.
533+
- "set": Sets the status of the timeline to the value specified by "--status".
534+
(Required)
535+
536+
--status [ready|processing|fail]
537+
The desired status to set for the timeline.
538+
This option is only valid when "--action" is set to "set".
539+
Valid options are:
540+
- "ready": Indicates that the timeline is ready for analysis.
541+
- "processing": Indicates that the timeline is currently being processed.
542+
- "fail": Indicates that the timeline processing failed.
543+
(Required when --action is set to set)
544+
```
545+
546+
Examples:
547+
```bash
548+
# Get the status of timeline with ID 123:
549+
tsctl timeline-status --action get 123
550+
551+
# Set the status of timeline with ID 456 to "ready":
552+
tsctl timeline-status --action set --status ready 456
553+
554+
# Set the status of timeline with ID 789 to "fail":
555+
tsctl timeline-status --action set --status fail 789
556+
557+
# Try to set a status without the action set to set.
558+
tsctl timeline-status --status fail 789
559+
# This will fail and display an error message.
560+
```
561+
562+
511563
### Sigma
512564
513565
#### List Sigma rules

timesketch/tsctl.py

+69-1
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def sketch_info(sketch_id):
574574
"created_at",
575575
"user_id",
576576
"description",
577+
"status",
577578
],
578579
]
579580

@@ -585,9 +586,9 @@ def sketch_info(sketch_id):
585586
t.created_at,
586587
t.user_id,
587588
t.description,
589+
t.status[0].status,
588590
]
589591
)
590-
591592
print_table(table_data)
592593

593594
print("Shared with:")
@@ -619,6 +620,73 @@ def sketch_info(sketch_id):
619620
print_table(status_table)
620621

621622

623+
@cli.command(name="timeline-status")
624+
@click.argument("timeline_id")
625+
@click.option(
626+
"--action",
627+
default="get",
628+
type=click.Choice(["get", "set"]),
629+
required=False,
630+
help="get or set timeline status.",
631+
)
632+
@click.option(
633+
"--status",
634+
required=False,
635+
type=click.Choice(["ready", "processing", "fail"]),
636+
help="get or set timeline status.",
637+
)
638+
def timeline_status(timeline_id, action, status):
639+
"""Get or set a timeline status
640+
641+
If "action" is "set", the given value of status will be written in the status.
642+
643+
Args:
644+
action: get or set timeline status.
645+
status: timeline status. Only valid choices are ready, processing, fail.
646+
"""
647+
if action == "get":
648+
timeline = Timeline.query.filter_by(id=timeline_id).first()
649+
if not timeline:
650+
print("Timeline does not exist.")
651+
return
652+
# define the table data
653+
table_data = [
654+
[
655+
"searchindex_id",
656+
"index_name",
657+
"created_at",
658+
"user_id",
659+
"description",
660+
"status",
661+
],
662+
]
663+
table_data.append(
664+
[
665+
timeline.searchindex_id,
666+
timeline.searchindex.index_name,
667+
timeline.created_at,
668+
timeline.user_id,
669+
timeline.description,
670+
timeline.status[0].status,
671+
]
672+
)
673+
print_table(table_data)
674+
elif action == "set":
675+
timeline = Timeline.query.filter_by(id=timeline_id).first()
676+
if not timeline:
677+
print("Timeline does not exist.")
678+
return
679+
# exit if status is not set
680+
if not status:
681+
print("Status is not set.")
682+
return
683+
timeline.set_status(status)
684+
db_session.commit()
685+
print(f"Timeline {timeline_id} status set to {status}")
686+
# to verify run:
687+
print(f"To verify run: tsctl timeline-status {timeline_id} --action get")
688+
689+
622690
@cli.command(name="validate-context-links-conf")
623691
@click.argument("path")
624692
def validate_context_links_conf(path):

0 commit comments

Comments
 (0)