DSPMCreateSimpleSlackMessageBlock

This automation script overwrites the value of a specified list and sends a Slack notification to inform the user that they failed to respond to an incident notification in a timely manner. The notification includes a message indicating the end of the incident playbook and an invitation to reopen the incident if necessary.

python · DSPM

Details

IDDSPMCreateSimpleSlackMessageBlock
Languagepython
From Version6.10.0
Docker Imagedemisto/python3:3.12.13.10116658

README

This automation script overwrites the value of a specified list and sends a Slack notification to inform the user that they failed to respond to an incident notification in a timely manner. The notification includes a message indicating the end of the incident playbook and an invitation to reopen the incident if necessary.

Script Data


Name Description
Script Type python3
Cortex XSOAR Version 6.10.0

Inputs


Argument Name Description
message  

Outputs


Path Description Type
CustomSlackBlock   Unknown
import pytest
from CommonServerPython import CommandResults
from DSPMCreateSimpleSlackMessageBlock import create_slack_notification_block, main
from unittest.mock import patch


def test_create_slack_notification_block():
    # Arrange
    message = "Incident response timeout notification"
    incident_link = "https://example.com/incident/12345"

    # Act
    slack_block = create_slack_notification_block(message, incident_link)

    # Assert
    expected_block = {
        "blocks": [
            {"type": "section", "text": {"type": "mrkdwn", "text": message}},
            {"type": "section", "text": {"type": "mrkdwn", "text": f"*XSOAR Incident Link:* {incident_link}"}},
        ]
    }
    assert slack_block == expected_block


@pytest.fixture
def mock_demisto_args():
    return {"message": "Incident response timeout", "incidentLink": "https://example.com/incident/12345"}


@patch("DSPMCreateSimpleSlackMessageBlock.demisto")
def test_main(mock_demisto, mock_demisto_args):
    # Arrange
    mock_demisto.args.return_value = mock_demisto_args
    expected_output = CommandResults(
        outputs_prefix="slackBlock",
        outputs={
            "blocks": [
                {
                    "type": "section",
                    "text": {"type": "mrkdwn", "text": mock_demisto_args["message"]},
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": f"*XSOAR Incident Link:* {mock_demisto_args['incidentLink']}",
                    },
                },
            ]
        },
    )

    # Act
    with patch("DSPMCreateSimpleSlackMessageBlock.return_results") as mock_return_results:
        main()

        # Assert
        actual_output = mock_return_results.call_args[0][0]
        assert actual_output.outputs_prefix == expected_output.outputs_prefix
        assert actual_output.outputs == expected_output.outputs