iot-security-check-servicenow

Close the XSOAR incident if the IoT ServiceNow ticket was closed. This command should be run in a Job.

python · IoT by Palo Alto Networks

Details

IDiot-security-check-servicenow
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Tagsiot

README

Close the XSOAR incident if the IoT ServiceNow ticket was closed. This command should be run in a Job.

Script Data


Name Description
Script Type python3
Tags iot
Cortex XSOAR Version 5.5.0

This script is run by a playbook ‘iot-check-service-playbook’, that is run by a recurring XSOAR job.

First of all, we are looping all the open XSOAR incidents based on two incident types:
“IoT Alert” and “IoT Vulnerability”

Then we are only interested of the ones with a customized instance field: ServiceNow table name, that tells us a
corresponding ServiceNow ticket was created. Looping each one of this incident, and query ServiceNow for the ticket
status. If the status is “Closed”, we are closing the XSOAR incident.

Used In


This script is used in the following playbooks and scripts.

  • PANW IoT ServiceNow Tickets Check

Inputs


There are no inputs for this script.

Outputs


There are no outputs for this script.

import demistomock as demisto
import iot_check_servicenow
from iot_check_servicenow import check_servicenow_and_close

_INCIDENTS = [
    {"id": 1, "status": 0, "type": "IoT Alert"},
    {
        "id": 2,
        "status": 1,
        "type": "IoT Vulnerability",
        "CustomFields": {"servicenowtablename": "incident", "servicenowrecordid": "snow_id"},
    },
]


def test_check_servicenow_and_close(monkeypatch):
    """
    Scenario: checking opened XSOAR IoT incidents.
    If there's a ServiceNow ticket created, query its status, then close it accordingly

    Given
    - An opened incident with a ServiceNow ticket created for this

    When
    - Closing this incident

    Then
    - Ensure the ServiceNow query command 'servicenow-get-record' is run
    - Ensure the close investigation is happening
    """
    monkeypatch.setattr(iot_check_servicenow, "get_opened_iot_incidents", lambda: _INCIDENTS)

    monkeypatch.setattr(
        demisto,
        "executeCommand",
        lambda command, args: {
            "servicenow-get-record": [
                {"Type": 1, "Contents": {"result": {"close_code": "Duplicate Ticket", "incident_state": "7"}}}
            ],
            "closeInvestigation": [{"Type": 1}],
        }.get(command),
    )

    assert check_servicenow_and_close() == "found 2 incidents, closed 1 incidents"