MicrosoftSentinelConvertRelationsToTable

This script is used to convert relations to a table.

python · Microsoft Sentinel

Details

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

README

This script is used to convert relations 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_relation():
    """
    Given:
        - A relation
    When:
         - calling format_relation function
    Then:
        - Validate the relation is formatted correctly
    """
    relation = {
        "name": "test",
        "properties": {
            "relatedResourceKind": "test_kind",
            "relatedResourceType": "test_type",
            "relatedResourceName": "test_name",
            "relatedResourceId": "test_id",
        },
    }
    expected = {
        "name": "test",
        "relatedResourceKind": "test_kind",
        "relatedResourceType": "test_type",
        "relatedResourceName": "test_name",
        "relatedResourceId": "test_id",
    }

    from MicrosoftSentinelConvertRelationsToTable import format_relation

    result = format_relation(relation)

    assert result == expected


CONTEXT_RESULTS = (
    '[{"name": "test", "properties": {"relatedResourceKind": "test_kind", "relatedResourceType": "test_type", '
    '"relatedResourceName": "test_name", "relatedResourceId": "test_id"}}, {"name": "test2", "properties": '
    '{"relatedResourceKind": "test_kind2", "relatedResourceType": "test_type2", '
    '"relatedResourceName": "test_name2", "relatedResourceId": "test_id2"}}]'
)

EXPECTED_TABLE = (
    "|Name|Related Resource Kind|Related Resource Type|Related Resource Name|Related Resource Id|\n"
    "|---|---|---|---|---|\n"
    "| test | test_kind | test_type | test_name | test_id |\n"
    "| test2 | test_kind2 | test_type2 | test_name2 | test_id2 |\n"
)


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

    result = convert_to_table(CONTEXT_RESULTS)

    assert result.readable_output == EXPECTED_TABLE