MicrosoftSentinelConvertAlertsToTable

This script is used to convert alerts to a table.

python · Microsoft Sentinel

Details

IDMicrosoftSentinelConvertAlertsToTable
Languagepython
From Version5.5.0
Docker Imagedemisto/python3:3.12.13.10404775
Tagsdynamic-section

README

This script is used to convert alerts to a table.

Script Data


Name Description
Script Type python3
Tags dynamic-section
Cortex XSOAR Version 5.5.0

Inputs


There are no inputs for this script.

Outputs


There are no outputs for this script.

def test_format_alert():
    """
    Given:
        - An alert
    When:
         - calling format_alert function
    Then:
        - Validate the alert is formatted correctly
    """
    alert = {"name": "test", "kind": "test_kind", "type": "test_type", "properties": {"testProp": "test_value"}}
    expected = {"name": "test", "kind": "test_kind", "testProp": "test_value"}

    from MicrosoftSentinelConvertAlertsToTable import format_alert

    result = format_alert(alert)

    assert result == expected


CONTEXT_RESULTS = (
    '[{"name": "test", "kind": "test_kind", "properties": {"testProp": "test_value"}}, '
    '{"name": "test2", "kind": "test_kind2", "properties": {"testProp": "test_value2", '
    '"testProp2": "test_value3"}}]'
)

EXPECTED_TABLE = (
    "|Name|Kind|Test Prop|Test Prop 2|\n"
    "|---|---|---|---|\n"
    "| test | test_kind | test_value |  |\n"
    "| test2 | test_kind2 | test_value2 | test_value3 |\n"
)


def test_convert_to_table():
    """
    Given:
        - A list of alerts in string format
    When:
        - calling convert_to_table function
    Then:
        - Validate the table is created correctly
    """
    from MicrosoftSentinelConvertAlertsToTable import convert_to_table

    result = convert_to_table(CONTEXT_RESULTS)

    assert result.readable_output == EXPECTED_TABLE