GetTasksWithSections

Groups all tasks for a specific incident according to the task headers (titles).

python · Cortex REST API

Details

IDGetTasksWithSections
Languagepython
From Version6.0.0
Docker Imagedemisto/python3:3.12.13.10404775
TagsUtility

README

Groups all tasks for a specific incident according to the task headers (titles).

Script Data


Name Description
Script Type python3
Tags Utility
Cortex XSOAR Version 6.0.0

Inputs


Argument Name Description
investigation_id Incident ID to create the task table.

Outputs


Path Description Type
Tasks The entire task object Unknown
Tasks.id Task ID string
Tasks.name Task name string
Tasks.section Task section path string
Tasks.type Task type (regular, condition, title, playbook, start) string
Tasks.owner Task owner string
Tasks.state Task state (inprogress, Completed, WillNotBeExecuted, Error, Waiting, Blocked, and empty string for not started) string
Tasks.scriptId Task related script (empty if manual) string
Tasks.startDate Task start date unknown
Tasks.completedDate Task completed date unknown
Tasks.dueDate Task due date (SLA) unknown
Tasks.parentPlaybookID Task parent playbook ID (if the task is part of a sub-playbook) unknown
Tasks.completedBy Name of the user who completed the task string
import json

from GetTasksWithSections import find_start_task, get_tasks_and_readable, traverse_tasks


def load_json(file):
    with open(file) as f:
        return json.load(f)


tasks = load_json("test_data/tasks_example.json")


def test_find_start_task():
    """
    Given:
        tasks from `/investigation/{incident_id}/workplan` endpoint
    When:
        Needed to find the start task in order to traverse the tasks
    Then:
        Get a task which it's type is `start`
    """
    start_task = find_start_task(tasks)
    assert start_task.get("type") == "start"


def test_traverse_tasks():
    """
    Given:
        tasks from `/investigation/{incident_id}/workplan` endpoint
    When:
        Needed to traverse the tasks to construct nested task dictionary
    Then:
        The results will be in a nested form, without skipped or condition tasks (playbook tasks are included)`
    """
    start_task = find_start_task(tasks)
    nested_task_results = {}
    traverse_tasks(tasks, start_task, nested_task_results)
    expected_results = {
        "Start": {"1", "2", "7"},
        "Section 1": {"Section 2": {"5", "8"}, "Section 4": {"13"}},
        "Section 3": {"10"},
    }

    for k1, v1 in nested_task_results.items():
        if "tasks" in v1:
            actual_result = {task.get("id") for task in v1.get("tasks")}
        else:
            actual_result = {k2: {task.get("id") for task in v2.get("tasks")} for k2, v2 in v1.items()}
        assert actual_result == expected_results[k1]
    all_tasks, _ = get_tasks_and_readable(nested_task_results)
    assert {task.get("id") for task in all_tasks} == {"1", "2", "5", "7", "8", "10", "13"}