foreach
Use the foreach operator to iterate through a selection of fields and apply a subsearch to each field.
Syntax
|foreach <field-list> [ <subsearch> ]
<field-list>
|
A comma-separated list of fields to iterate through. The wildcard |
[ <subsearch> ]
|
A Subsearch can use a template value |
Usage
The foreach operator can be used to obtain results from across multiple fields in each row. This can be useful for calculating the sum or average of a selection of fields, for example.
Examples
Example 1: Iterate calculations across multiple tables.
|foreach test1, test2, test3 [ calc total = total + <<FIELD>> ]
Example 2: Apply operations to each table separately.
|foreach * [ calc <<FIELD>> = concat(<<FIELD>>, 'abc') ]
Example 3: Aggregates event counts by status, then counts those counts, then iterates over each of the cnt and cnt2 fields adding the current value of the field to cnt in each iteration.
ocsf | aggr count as cnt by status |aggr count as cnt2 by cnt | foreach cnt, cnt2 [ CALC cnt = cnt + <<FIELD>> ]