Scheduled Commands - Use commands to schedule the future execution of other commands in playbook tasks. - Developer Guide - Cortex XSIAM - Cortex - Security Operations

Cortex XSIAM Developer Guide

Product
Cortex XSIAM
Creation date
2023-05-01
Last date published
2025-09-08
Category
Developer Guide
Abstract

Use commands to schedule the future execution of other commands in playbook tasks.

A command can schedule the future execution of another command. In playbook tasks using scheduled commands, the task does not proceed to the next task until it is done with all scheduled commands and there is no future execution scheduled. When a playbook waits for a command execution, it does not use a worker, since workers are only used at the time commands are executed.

You can use scheduled commands in a polling flow when a command cannot return the full result in a single execution (for example, when a remote process hasn't finished execution). Scheduled commands enable you to try the command again later and return the full results when available. Examples include Cortex XDRIR Endpoint Isolation and AutoFocus V2 Search Samples.

YAML prerequisite
  • Integration - in the integration YAML, under the command root, add polling: true.

  • Script - in the script YAML, in the root of the file, add polling: true

The polling_function decorator

The polling_function decorator can be used to avoid much of the code you would otherwise need to implement to write a polling function.

All functions implementing this decorator must always return a PollResult object.

Note

Args must be the first parameter in the function definition and call.

ScheduledCommand class

For scenarios the polling_function decorator does not cover, you can use the ScheduledCommand class for more advanced control over polling. ScheduledCommand is an optional class that enables scheduling commands via the command results.

Arg

Type

Description

command

str

The command that runs after next_run_in_seconds has passed.

next_run_in_seconds

int

How long to wait before executing the command.

The interval between each run is determined by next_run_in_seconds, however it will never be less than 10 seconds.

args (optional)

dict

Arguments to use when executing the command.

timeout_in_seconds (optional)

int

Number of seconds until the polling sequence timeouts.

When provided to CommandResults it transforms the result into a schedule result. After the next_run_in_seconds delay, the command will be executed. The scheduled command can return another schedule result that schedules another scheduled command and so on.

The schedule sequence completes when any one of three terminating actions occur:

  • Done: The integration finishes a schedule sequence by not returning a schedule result. Otherwise, the sequence continues as long as a schedule result is returned.

  • Error: The schedule sequence finishes with an error when a command in the sequence returns an error result.

  • Timeout (automatically handled): The schedule sequence finishes execution with a timeout error when the timeout is reached. Cortex XSIAM returns the timeout error entry automatically.