PrintToAlert
Prints a value to the specified alert's war-room. The alert must be in status "Under Investigation".
python · Common Scripts
Details
| ID | PrintToAlert |
|---|---|
| Language | python |
| From Version | 8.7.0 |
| Docker Image | demisto/python3:3.12.13.10116658 |
README
Prints a value to the specified alert’s war-room. The alert must be in status “Under Investigation”.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Cortex XSOAR Version | 8.7.0 |
Inputs
| Argument Name | Description |
|---|---|
| value | The value to print to the war-room of specified alert. |
| alert_id | The alert ID to print to. |
| mark_as_note | Whether to mark the printed war-room entry as a note. |
Outputs
There are no outputs for this script.
import demistomock as demisto import pytest from CommonServerPython import EntryType from pytest_mock import MockerFixture def test_print_to_alert(mocker: MockerFixture): """Tests print_to_alert_command when the executeCommand command succeeds. Checks that the addEntries command is called with the right arguments. """ from PrintToAlert import print_to_alert_command execute_command_mocker = mocker.patch.object( demisto, "executeCommand", return_value=[ { "Type": EntryType.NOTE, "Contents": "done", "HumanReadable": None, "EntryContext": None, } ], ) mocker.patch.object(demisto, "results") print_to_alert_command( current_alert_id="5", value="Hello", alert_id="4", ) # Right command is called assert execute_command_mocker.call_args[0][0] == "addEntries" # Right arguments are given assert execute_command_mocker.call_args[0][1] == { "entries": '[{"Type": 1, "ContentsFormat": "markdown", "Contents": "Entry from alert #5:\\nHello", "Note": false}]', "id": "4", "reputationCalcAsync": True, } assert demisto.results.call_args[0][0]["HumanReadable"] == "Successfully printed to alert 4." def test_print_to_alert_with_note(mocker: MockerFixture): """Tests print_to_alert_command when the executeCommand command succeeds. Checks that the addEntries command is called with the right arguments. Also tests mark_as_note=True argument of print_to_alert_command """ from PrintToAlert import print_to_alert_command execute_command_mocker = mocker.patch.object( demisto, "executeCommand", return_value=[ { "Type": EntryType.NOTE, "Contents": "done", "HumanReadable": None, "EntryContext": None, } ], ) mocker.patch.object(demisto, "results") print_to_alert_command(current_alert_id="5", value="Hello", alert_id="4", mark_as_note=True) # Right command is called assert execute_command_mocker.call_args[0][0] == "addEntries" # Right arguments are given assert execute_command_mocker.call_args[0][1] == { "entries": '[{"Type": 1, "ContentsFormat": "markdown", "Contents": "Entry from alert #5:\\nHello", "Note": true}]', "id": "4", "reputationCalcAsync": True, } assert demisto.results.call_args[0][0]["HumanReadable"] == "Successfully printed to alert 4." def test_print_to_alert_error(mocker: MockerFixture): """Tests print_to_alert_command when the executeCommand command fails. Checks that the system exists and an error message is returned. """ from PrintToAlert import print_to_alert_command error_message = "Something went wrong" mocker.patch.object( demisto, "executeCommand", return_value=[ { "Type": EntryType.ERROR, "Contents": error_message, "HumanReadable": None, "EntryContext": None, } ], ) mocker.patch.object(demisto, "results") with pytest.raises(SystemExit): print_to_alert_command( current_alert_id="5", value="Hello", alert_id="4", ) assert demisto.results.call_args[0][0] == { "Type": EntryType.ERROR, "ContentsFormat": "text", "Contents": error_message, "EntryContext": None, }