AssignAnalystToIncidentOOO

Assigns analysts who are not out of the office to the shift handover incident. Use the ManageOOOusers automation to add or remove analysts from the out-of-office list. This automation runs using the default Limited User role, unless you explicitly change the permissions. For more information, see the section about permissions here: For Cortex XSOAR 6 use the link https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/6.x/Cortex-XSOAR-Playbook-Design-Guide/Automations and for Cortex XSOAR 8 Cloud use the link https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/8/Cortex-XSOAR-Cloud-Documentation/Create-a-script.

python · Shift Management

Source

import random

from CommonServerPython import *


def main():
    # args
    list_name = demisto.getArg("listname")
    oncall = demisto.getArg("oncall")
    roles = demisto.getArg("roles")
    assign_all = argToBoolean(demisto.getArg("assignAll"))

    # get xsoar users
    userinfo = demisto.executeCommand("getUsers", {"roles": roles, "onCall": oncall})
    if is_error(userinfo):
        return_error(f"Failed to get users: {get_error(userinfo)!s}")

    # get OOO users
    ooo_list = demisto.executeCommand("GetUsersOOO", {"listname": list_name})
    if isError(ooo_list):
        return_error(f"Failed to get users out of office: {get_error(ooo_list)!s}")
    list_info = ooo_list[0].get("EntryContext").get("ShiftManagment.OOOUsers")
    list_info = [i["username"] for i in list_info]

    # Get Away Users
    away_users_response = demisto.executeCommand("GetAwayUsers", {})
    if is_error(away_users_response) or not away_users_response:
        return_error(f"Failed to get away users: {get_error(away_users_response)!s}")
    away_users: List[Dict] = away_users_response[0].get("EntryContext", {}).get("AwayUsers", [])
    away_user_names: List[str] = [away_user["username"] for away_user in away_users] if away_users else []
    # Build list of users that we can assign to
    userinfo = userinfo[0]["Contents"]

    non_OOO_list = [x["username"] for x in userinfo if x["username"] not in list_info and x["username"] not in away_user_names]

    # Assign user to the Incident, if there is anyone to assign
    if not non_OOO_list:
        return_error(message="No users to assign")

    elif assign_all:
        # set the first user to be the owner
        owner = non_OOO_list[0]
        non_OOO_list.pop(0)
        set_owner_res = demisto.executeCommand("setOwner", {"owner": owner})
        if isError(set_owner_res):
            return_error(f"Failed to set {owner} as owner: {get_error(set_owner_res)!s}")
        # set the rest of the users as participans
        for user in non_OOO_list:
            assign_res = demisto.executeCommand("AssignAnalystToIncident", {"username": user})
            if isError(assign_res):
                return_error(f"Failed to assign {user} to incident: {get_error(assign_res)!s}")

        if non_OOO_list:
            return_results(f'Done, assigned {owner} as owner and {", ".join(non_OOO_list)} as prticipans.')
        else:
            return_results(f"Done, assigned {owner} as owner.")
    else:
        rand_user = random.choice(non_OOO_list)
        set_owner_res = demisto.executeCommand("setOwner", {"owner": rand_user})
        if isError(set_owner_res):
            return_error(f"Failed to set {rand_user} as owner: {get_error(set_owner_res)!s}")
        return_results(f"Done, assigned {rand_user} as owner")


if __name__ in ("__builtin__", "builtins", "__main__"):
    main()

README

Assigns analysts who are not out of the office to the shift handover incident. Use the ManageOOOusers automation to add or remove analysts from the out-of-office list.

Permissions


This automation runs using the default Limited User role, unless you explicitly change the permissions.
For more information, see the section about permissions here: For Cortex XSOAR 6, see the https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/6.x/Cortex-XSOAR-Playbook-Design-Guide/Automations for Cortex XSOAR 8 Cloud, see the https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/8/Cortex-XSOAR-Cloud-Documentation/Create-a-script for Cortex XSOAR 8 On-prem, see the https://docs-cortex.paloaltonetworks.com/r/Cortex-XSOAR/8.7/Cortex-XSOAR-On-prem-Documentation/Create-a-script.

Script Data


Name Description
Script Type python3
Tags Shift Management, ooo
Cortex XSOAR Version 5.5.0

Used In


This script is used in the following playbooks and scripts.
Shift handover

Inputs


Argument Name Description
roles The list of roles from which to assign analysts to the shift handover incident. Can be an array or a comma-separated list. Leave empty to assign all analysts.
oncall Whether to randomly assign analysts who are on call for the shift handover. Possible values: “true” and “false”. Requires Cortex XSOAR v5.5 or later.
listname The name of the out-of-office list. Default is “OOO List”.
assignAll Whether to assign all on-call analysts to the shift handover incident. Set to “true” to assign all on-call analysts.

Outputs


There are no outputs for this script.