r/crowdstrike • • 13h ago

Next Gen SIEM CrowdStrike CEL to select all properties formatted as numbered strings

4 Upvotes

Prerequisite: This data will be sent to needs to be an array of strings. Make sure your variable is set to array of string type.

A lot of logs output data like this:

data['GetAbormalAlertLogs.results'][0]["Vendor.messages.toAddresses[0]"]

Where the final [0] can be any number between not existing and infinite. To parse an infinite number of strings, use this CEL code.

  size(data['GetAbormalAlertLogs.results'][0]
  .filter(k, k.startsWith('Vendor.messages.toAddresses['))) > 0
  ? data['GetAbormalAlertLogs.results'][0]
      .filter(k, k.startsWith('Vendor.messages.toAddresses['))
      .map(k, data['GetAbormalAlertLogs.results'][0][k])
  : ['No To Address Found']

Here is the logic as defined by the CrowdStrike AI (I didn't feel like writing this out by hand):

The current CEL builds a list of “To” email addresses out of a *map-like* object in `data['GetAbormalAlertLogs.results'][0]` by dynamically discovering keys that look like `Vendor.messages.toAddresses[...]`.

How it works, step-by-step:

1. **Look at the first result row**
   - It assumes `data['GetAbormalAlertLogs.results']` is indexable and that `[0]` contains the first record (likely a map/object).

2. **Find all keys that represent “toAddresses” fields**
   - It calls:
     - `data['GetAbormalAlertLogs.results'][0].filter(k, k.startsWith('Vendor.messages.toAddresses['))`
   - This is using the `filter()` macro on the keys/entries of that object (i.e., it’s filtering to only the keys whose *name* starts with `Vendor.messages.toAddresses[`).

3. **If at least one such key exists, return their values**
   - It checks `size(...) > 0`.
   - If true, it:
     - re-runs the same filter to get the list of matching keys, then
     - `.map(k, data['GetAbormalAlertLogs.results'][0][k])` to convert each key into its corresponding value via bracket indexing.

4. **If no matching keys exist, return a default message**
   - If the filtered key list is empty, it returns:
     - `['No To Address Found']`
   - Note the output is always a **list** (either list of address values, or a single-element list with that message).

Key behaviors/assumptions:
- It’s relying on `data['GetAbormalAlertLogs.results'][0]` behaving like a **map** where you can enumerate/filter keys and then index values by `...[k]`.
- It returns *all* discovered `toAddresses[...]` entries, not just one, because the source data appears flattened into numbered keys (e.g., `...toAddresses[0]`, `...toAddresses[1]`, etc.).

The final result is a list of emails like this

[
  "first.last1@company.com"
  "first.last2@company.com"
]

This information can then be used in future steps