ManageOOOusers
Adds or removes an analyst from the out-of-office list in XSOAR. When used with the AssignAnalystToIncidentOOO automation, prevents incidents from being assigned to an analyst who is out of office.
- Type
- python
- Pack
- ShiftManagement
Source
from CommonServerPython import * # noqa: F401
def _get_current_user():
current_username = demisto.executeCommand("getUsers", {"current": True})
if isError(current_username):
demisto.debug(f"failed to get current username - {get_error(current_username)}")
return None
else:
return current_username[0]["Contents"][0]["username"]
def main():
# get current time
now = datetime.now()
# args
list_name = demisto.getArg("listname")
username = demisto.getArg("username")
option = demisto.getArg("option")
days_off = now + timedelta(days=int(demisto.getArg("daysoff")))
off_until = days_off.strftime("%Y-%m-%d")
# update list name to start with 'OOO', so we can't overwrite other lists with this
if not list_name.startswith("OOO"):
list_name = f"OOO {list_name}"
current_user = _get_current_user()
if not current_user and not username:
return_error("Failed to get current user. Please set the username argument in the script.")
if not username:
# Current user was found, running script on it.
username = current_user
else:
# check if provided username is a valid xsoar user
users = demisto.executeCommand("getUsers", {})
if isError(users):
return_error(f"Failed to get users: {get_error(users)!s}")
users = users[0]["Contents"]
users = [x["username"] for x in users]
if username not in users:
return_error(message=f"{username} is not a valid user")
# get the out of office list, check if the list exists, if not create it:
ooo_list = demisto.executeCommand("getList", {"listName": list_name})[0]["Contents"]
if isError(ooo_list):
return_error(f"Failed to get users out of office: {get_error(ooo_list)!s}")
if "Item not found" in ooo_list:
demisto.results(demisto.executeCommand("createList", {"listName": list_name, "listData": "[]"}))
ooo_list = demisto.executeCommand("getList", {"listName": list_name})[0]["Contents"]
# check status of the list, and add/remove the user from it.
if not ooo_list:
list_data = []
else:
list_data = json.loads(ooo_list)
if option == "add":
# check if user is already in the list, and remove, to allow updating
list_data = [i for i in list_data if i["user"] != username]
list_data.append({"user": username, "offuntil": off_until, "addedby": current_user if current_user else "DBot"})
else:
# remove the user from the list.
list_data = [i for i in list_data if i["user"] != username]
set_list_res = demisto.executeCommand("setList", {"listName": list_name, "listData": json.dumps(list_data)})
if isError(set_list_res):
return_error(f"Failed to update the list {list_name}: {get_error(set_list_res)!s}")
# welcome back, or see ya later!
if option == "add":
demisto.results(f"Vacation mode engaged until {off_until}, enjoy the time off {username}")
else:
demisto.results(f"Welcome back {username}, it's like you never left!")
if __name__ in ("__builtin__", "builtins", "__main__"):
main()
README
Adds or removes an analyst from the out-of-office list in XSOAR. When used with the AssignAnalystToIncidentOOO automation, prevents incidents from being assigned to an analyst who is out of office.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | ooo, Shift Management |
| Cortex XSOAR Version | 5.5.0 |
Inputs
| Argument Name | Description |
|---|---|
| option | Add or remove an analyst from the out-of-office list. Possible values are “Add” and “Remove”. |
| daysoff | Number of days the analyst will be off. Default is 7. |
| listname | A list to use in place of the out-of-office list. If the name of the list that you pass does not begin with OOO, the script automatically prefixes OOO to the script name. For example, if you pass a list called newList, the script will automatically change the name to OOO newList. Default is “OOO List”. |
| username | The name of the analyst to add to the list. The default is the current analyst. Must be provided when running as part of a playbook. |
Outputs
There are no outputs for this script.