For the complete documentation index, see llms.txt. This page is also available as Markdown.

switch

Licenses

Requires any XSIAM license with the Data Pipeline add-on.

Important

Use the switch stage in a Data Pipeline filter to apply different fields stages to events based on conditions. Each event is evaluated against the case conditions in order, and the fields stages of the matching case determine which fields are kept or removed for that event.

Syntax

switch
    case <condition1>: (
        fields [-] <field1>, <field2>, ...
        [| fields [-] <field3>, ...]
    )
    [case <condition2>: (
        fields [-] <field1>, <field2>, ...
    ) ...]
    [default: (
        fields [-] <field1>, <field2>, ...
    )]

Parameters

Name
Type
Required
Description

case

clause

Yes

Defines a condition and the fields stages to apply to events that match it. You can define multiple case clauses.

<condition>

boolean

Yes

A logical expression, using the same syntax as the filter stage. Supports and, or, not, comparison operators, and supported functions.

default

clause

No

Defines the fields stages to apply to events that do not match any case condition. The default clause does not accept a condition.

fields

stage

Yes

One or more fields stages, separated by pipes (|) and enclosed in parentheses. Use - to exclude fields.

Returns

The switch stage returns each event with the fields selected or excluded by the fields stages of the matching case. Events that match no case are processed by the default clause. If there is no default clause, those events are returned unchanged.

Usage notes

  • The switch stage is available only in Data Pipeline filters. In a pipeline filter, it can be combined with the filter and fields stages, for example filter <condition> | fields <fields> | switch ....

  • case clauses are evaluated in the order they are defined. Only the first case whose condition evaluates to true is applied to an event.

  • Only the fields stage is allowed inside a case or default clause. Other stages, such as alter or filter, are not allowed.

  • Each case and default clause must contain at least one fields stage, and each fields stage must specify at least one field.

  • Wildcards (*) and the as clause are not allowed in a fields stage inside the switch stage.

  • System fields cannot be excluded, for example _time, _insert_time, _raw_log, _id, _vendor, _product, _tag, and the _collector_* fields. System field names are not case sensitive, so - _TIME is also rejected. You can still include system fields.

  • Only one default clause is allowed, and it cannot include a condition.

  • The switch, case, and default keywords are not case sensitive.

  • The functions that you can use in case conditions are the same as those supported in Data Pipeline filters. Array functions are not supported.

  • The in operator in a case condition accepts only a list of values, for example severity in ("HIGH", "MEDIUM"). Inner queries, such as in (dataset = ...), are not supported.

Examples

The examples use the following sample events:

severity
user
action
src_ip
debug_info
raw_payload

HIGH

alice

BLOCK

10.0.0.1

trace-01

{...}

MEDIUM

bob

ALLOW

10.0.0.2

trace-02

{...}

LOW

carol

ALLOW

10.0.0.3

trace-03

{...}

Example 1: Applying different field selections by severity

Goal: Keep only the key fields for high-severity events, remove the debugging field from medium-severity events, and remove the large fields from all other events.

XQL code:

Explanation: The HIGH event keeps only severity, user, action, and src_ip. The MEDIUM event keeps all fields except debug_info. The LOW event matches no case, so the default clause removes debug_info and raw_payload.

Output:

severity
user
action
src_ip
debug_info
raw_payload

HIGH

alice

BLOCK

10.0.0.1

MEDIUM

bob

ALLOW

10.0.0.2

{...}

LOW

carol

ALLOW

10.0.0.3

Example 2: Using multiple fields stages in a case

Goal: Select a set of fields and then exclude one of them within the same case.

XQL code:

Explanation: For the HIGH and MEDIUM events, the first fields stage keeps severity, user, and src_ip, and the second fields stage removes src_ip. The LOW event is processed by the default clause, which removes raw_payload.

Output:

severity
user
action
src_ip
debug_info
raw_payload

HIGH

alice

MEDIUM

bob

LOW

carol

ALLOW

10.0.0.3

trace-03

Example 3: Using switch without a default clause

Goal: Change only events that match a condition and leave all other events unchanged.

XQL code:

Explanation: Only the event where action is BLOCK has raw_payload removed. The other events match no case, and because there is no default clause, they are returned unchanged.

Output:

severity
user
action
src_ip
debug_info
raw_payload

HIGH

alice

BLOCK

10.0.0.1

trace-01

MEDIUM

bob

ALLOW

10.0.0.2

trace-02

{...}

LOW

carol

ALLOW

10.0.0.3

trace-03

{...}

Example 4: Combining switch with filter and fields

Goal: Drop low-severity events, remove a field from all remaining events, and then apply field selection by action.

XQL code:

Explanation: The filter stage drops the LOW event, and the fields stage removes debug_info from the remaining events. The switch stage then keeps only the key fields for the BLOCK event and removes raw_payload from the other event.

Output:

severity
user
action
src_ip
raw_payload

HIGH

alice

BLOCK

10.0.0.1

MEDIUM

bob

ALLOW

10.0.0.2

Example 5: Invalid switch stages

Goal: Identify syntax that the switch stage does not support.

XQL code:

Explanation: Each of these filters is rejected when you save or simulate the Data Pipeline filter.

Last updated

Was this helpful?