# How to query and validate Splunk logs in Service Suite

## Overview

The `<span class="editor-theme-code">splunk.js</span>` library provides a reusable integration layer between AIQ Service Suite and Splunk. It allows test scripts to query Splunk indexes using SPL (Search Processing Language), filter and retrieve log data, and assert on the results as part of a functional or end-to-end test validation flow.

Common use cases include:

- Asserting that an audit log event was written after a user action (e.g. login, purchase, payment)
- Validating specific field values in application logs (e.g. transaction status, HTTP response codes)
- Checking that no ERROR or FATAL log entries appeared after a critical scenario
- Waiting for async events to appear in Splunk before continuing a test
- Extracting values from Splunk and storing them in TheLocker for downstream test cases

**Prerequisite:**<span style="color: rgb(205, 200, 194); background-color: rgb(24, 26, 27);"> The </span>AIQ<span style="color: rgb(205, 200, 194); background-color: rgb(24, 26, 27);"> TestNode executing the script must have network access to the Splunk REST API on port </span>**8089**<span style="color: rgb(205, 200, 194); background-color: rgb(24, 26, 27);">. Verify security group / firewall rules before using this library.</span>

---

## Setup

#### 1. Add splunk.js to your repository  
  
splunk.js file: splunk.js 

Upload `<span class="editor-theme-code">splunk.js</span>` to your scenario repository. A recommended location is a shared folder so it can be reused across multiple scenarios:

your-repo/  
 shared/  
 splunk.js &lt;-- place it here  
 scenarios/  
 checkout-flow/  
 setup.js  
 script1.js

### 2. Configure DPL variables

Never hardcode Splunk credentials in scripts. Add the following variables to your DPL (Data Provider Library) or scenario data file:

<table id="bkmrk-dpl-variabledescript" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">DPL Variable

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Description

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Example

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">SPLUNK_HOST</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Hostname or IP of the Splunk instance

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.internal.mycompany.com</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">SPLUNK_TOKEN</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Splunk service account Bearer token

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">eyJrIjoiT...</span>`

</td></tr></tbody></table>

To generate a Bearer token in Splunk: **Settings → Tokens → New Token**. Use a dedicated service account, not a personal user.

<span style="color: rgb(205, 200, 194); background-color: rgb(24, 26, 27);">Do not commit credentials to the repository. Always use DPL variables or TheLocker for sensitive values.</span>

### 3. Include the library in your script

Use the Service Suite `<span class="editor-theme-code">include</span>` directive at the top of any script that needs Splunk access. The `<span class="editor-theme-code">{ds}</span>` token resolves to the root of your scenario's data source directory at runtime:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`

---

## Initialization

Call `<span class="editor-theme-code">splunk.init()</span>` once at the beginning of each script before making any queries:

`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">            $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">    </span>`*`<em class="editor-theme-code editor-theme-italic">// DPL variable</em>`*  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">port</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">            </span>``<span class="editor-theme-code">8089</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">           $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">   </span>`*`<em class="editor-theme-code editor-theme-italic">// DPL variable</em>`*  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">defaultIndex</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">    </span>``<span class="editor-theme-code">'app_logs'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">      </span>`*`<em class="editor-theme-code editor-theme-italic">// used when no index is specified in SPL</em>`*  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">defaultEarliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-15m'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">          </span>`*`<em class="editor-theme-code editor-theme-italic">// default look-back window for all searches</em>`*  
`<span class="editor-theme-code">});</span>`

### Full init options

<table id="bkmrk-optiondefaultdescrip" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Option

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Default

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Description

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">host</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">localhost</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Splunk hostname or IP

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">port</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">8089</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Splunk REST API port

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">scheme</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">https</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">https</span>` or `<span class="editor-theme-code">http</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">token</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">null</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Bearer token (preferred auth method)

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">username</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">null</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Basic auth username (alternative to token)

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">password</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">null</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Basic auth password (alternative to token)

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">defaultIndex</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">main</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fallback Splunk index

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">defaultEarliest</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">-15m</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Default time window start

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">defaultLatest</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">now</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Default time window end

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">defaultCount</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">1000</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Max rows returned per search

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">pollIntervalMs</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">2000</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">How often to poll for job completion (ms)

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">maxPollAttempts</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">30</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Max poll attempts before timeout (30 × 2s = 60s)

</td></tr></tbody></table>

---

## How HTTP calls work internally

The library uses native Service Suite HTTP commands throughout. No browser-style `<span class="editor-theme-code">fetch</span>` or external modules are used.

<table id="bkmrk-operationservice-sui" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Operation

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Service Suite command used

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Submit search job

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">createPost(url, body, "application/x-www-form-urlencoded")</span>` + `<span class="editor-theme-code">process(call)</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Poll job status

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">createGet(url)</span>` + `<span class="editor-theme-code">process(call)</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fetch results

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">createGet(url)</span>` + `<span class="editor-theme-code">process(call)</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Per-request auth header

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">call.addHeader("Authorization", "Bearer ...")</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Read response body

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">resp.toStringContent()</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Read HTTP status code

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">resp.status</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Sleep between polls

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">java.lang.Thread.sleep(ms)</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Base64 encode (Basic auth)

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Java.type("java.util.Base64").getEncoder().encodeToString(...)</span>`

</td></tr></tbody></table>

---

## API Reference

### Query methods

<table id="bkmrk-methodreturnsdescrip" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Method

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Returns

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Description

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.search(spl, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Array</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Run any SPL query and return all result rows

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.searchOne(spl, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Object|null</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Return only the first result row, or null if none

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.count(spl, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Number</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Return the number of matching events

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.getField(spl, field, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">String</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Return a single field value from the first row

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.getFields(spl, fields[], opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Object</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Return multiple field values from the first row

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.getAllValues(spl, field, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Array</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Return one field's value across all rows

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.waitForEvent(spl, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">Array</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Poll until at least one matching event appears

</td></tr></tbody></table>

All query methods accept an optional `<span class="editor-theme-code">opts</span>` object: `<span class="editor-theme-code">{ earliest, latest, count }</span>`. `<span class="editor-theme-code">waitForEvent</span>` also accepts `<span class="editor-theme-code">pollMs</span>` and `<span class="editor-theme-code">maxAttempts</span>`.

### Assertion methods

<table id="bkmrk-methoddescriptionspl" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Method

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Description

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertCount(rows, n, msg)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fails if row count ≠ n

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertAtLeast(rows, n, msg)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fails if fewer than n rows returned

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertFieldEquals(rows, field, value, msg)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fails if the field on row\[0\] ≠ expected value

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertFieldContains(rows, field, substring, msg)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fails if the field on row\[0\] does not contain the substring

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertNoErrors(index, earliest, msg)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Fails if any ERROR or FATAL entries exist in the time window

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.assertEventOccurred(spl, msg, opts)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Combined search + assertAtLeast(1) in one call

</td></tr></tbody></table>

### Utility methods

<table id="bkmrk-methoddescriptionspl-1" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Method

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Description

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">splunk.storeResult(rows, field, lockerKey)</span>`

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Store a field value from row\[0\] into TheLocker for downstream scripts via `<span class="editor-theme-code">_retrieve(lockerKey)</span>`

</td></tr></tbody></table>

---

## Usage Examples

### Example 1 — Assert a login audit event was written

After executing a login API call, verify that Splunk captured the corresponding audit entry:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">         $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">        $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">defaultIndex</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'audit'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> testUser </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">TEST_USERNAME</span>``<span class="editor-theme-code">;</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertEventOccurred(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=audit action=login userId="'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> testUser </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'" result=SUCCESS'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'Login audit event must appear in Splunk after successful authentication'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-5m'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ Login audit event confirmed in Splunk'</span>``<span class="editor-theme-code">);</span>`

### Example 2 — Validate field values on a specific transaction

Retrieve a transaction log by its ID and assert that its status and currency fields are correct:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">  $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">_retrieve(</span>``<span class="editor-theme-code">'LAST_TXN_ID'</span>``<span class="editor-theme-code">);</span>``<span class="editor-theme-code">  </span>`*`<em class="editor-theme-code editor-theme-italic">// value stored by an upstream test case</em>`*  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> rows </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> splunk</span>``<span class="editor-theme-code">.search(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=payments txnId="'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'" | head 1'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-10m'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertAtLeast(</span>``<span class="editor-theme-code">rows</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">1</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'Transaction '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">' must appear in Splunk'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertFieldEquals(</span>``<span class="editor-theme-code">rows</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'status'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">   </span>``<span class="editor-theme-code">'APPROVED'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'Transaction must be APPROVED'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertFieldEquals(</span>``<span class="editor-theme-code">rows</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'currency'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'USD'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code">      </span>``<span class="editor-theme-code">'Currency must be USD'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ Transaction '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">' validated — status=APPROVED, currency=USD'</span>``<span class="editor-theme-code">);</span>`

### Example 3 — No-error assertion after a critical flow

After running a checkout scenario, assert that no ERROR or FATAL entries were written to the application log index during the test window:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">         $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">        $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">defaultIndex</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'app_logs'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertNoErrors(</span>``<span class="editor-theme-code">'app_logs'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-10m'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'No ERROR or FATAL log entries expected after checkout flow'</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ No errors found in Splunk after checkout flow'</span>``<span class="editor-theme-code">);</span>`

### Example 4 — Wait for an async event

Some flows write to Splunk with a delay (e.g. payment processors, message queues). Use `<span class="editor-theme-code">waitForEvent</span>` to poll rather than failing immediately:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">  $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">_retrieve(</span>``<span class="editor-theme-code">'LAST_TXN_ID'</span>``<span class="editor-theme-code">);</span>`  
*`<em class="editor-theme-code editor-theme-italic">// Poll every 3 seconds, up to 10 times (30s total)</em>`*  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> rows </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> splunk</span>``<span class="editor-theme-code">.waitForEvent(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=payments event=PAYMENT_CONFIRMED txnId="'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> txnId </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'"'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>`  
`<span class="editor-theme-code">    </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">    </span>``<span class="editor-theme-code">'-5m'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">    </span>``<span class="editor-theme-code">pollMs</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">      </span>``<span class="editor-theme-code">3000</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">    </span>``<span class="editor-theme-code">maxAttempts</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">10</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.assertFieldEquals(</span>``<span class="editor-theme-code">rows</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'processorCode'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'00'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'Processor must return approval code 00'</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ Async payment confirmation found in Splunk'</span>``<span class="editor-theme-code">);</span>`

### Example 5 — Extract a value and store it in TheLocker

Retrieve a generated value from Splunk and make it available to downstream test cases:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">  $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> testUser </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">TEST_USERNAME</span>``<span class="editor-theme-code">;</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> rows </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> splunk</span>``<span class="editor-theme-code">.search(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=sessions userId="'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> testUser </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'" | sort -_time | head 1'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-5m'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.storeResult(</span>``<span class="editor-theme-code">rows</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'sessionId'</span>``<span class="editor-theme-code">,</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'SPLUNK_SESSION_ID'</span>``<span class="editor-theme-code">);</span>`  
*`<em class="editor-theme-code editor-theme-italic">// Downstream scripts: var sid = _retrieve('SPLUNK_SESSION_ID');</em>`*  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ Session ID extracted from Splunk and stored in TheLocker'</span>``<span class="editor-theme-code">);</span>`

### Example 6 — SPL aggregation: validate counts across all hosts

Use a `<span class="editor-theme-code">| stats</span>` pipe to check that no host served 5xx errors on a specific endpoint:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">  $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> rows </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> splunk</span>``<span class="editor-theme-code">.search(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=api endpoint="/checkout" | stats count(eval(status>=500)) as server_errors by host | where server_errors=0'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-30m'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> rows</span>``<span class="editor-theme-code">.</span>``<span class="editor-theme-code">length</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">' host(s) had zero 5xx errors on /checkout in the last 30 minutes'</span>``<span class="editor-theme-code">);</span>`

### Example 7 — getAllValues: check for unexpected HTTP status codes

Retrieve all HTTP status codes from recent API calls and fail if any 5xx appears:

/\*\*  
*`<em class="editor-theme-code editor-theme-italic"> * @aiq</em>`*.servicesworkbench  
*`<em class="editor-theme-code editor-theme-italic"> */</em>`*  
`<span class="editor-theme-code">include(</span>``<span class="editor-theme-code">'{ds}/shared/splunk.js'</span>``<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">splunk</span>``<span class="editor-theme-code">.init({</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">host</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code">  $</span>``<span class="editor-theme-code">SPLUNK_HOST</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">token</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> $</span>``<span class="editor-theme-code">SPLUNK_TOKEN</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> statuses </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> splunk</span>``<span class="editor-theme-code">.getAllValues(</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'index=api endpoint="/api/order" | head 200'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'status'</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">{</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">earliest</span>``<span class="editor-theme-code">:</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">'-5m'</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">}</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">var</span>``<span class="editor-theme-code"> badStatuses </span>``<span class="editor-theme-code">=</span>``<span class="editor-theme-code"> statuses</span>``<span class="editor-theme-code">.filter(</span>``<span class="editor-theme-code">function</span>``<span class="editor-theme-code">(</span>``<span class="editor-theme-code">s</span>``<span class="editor-theme-code">)</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">{</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">return</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">parseInt(</span>``<span class="editor-theme-code">s</span>``<span class="editor-theme-code">)</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">>=</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">500</span>``<span class="editor-theme-code">;</span>`  
`<span class="editor-theme-code">});</span>`  
`<span class="editor-theme-code">assert(</span>``<span class="editor-theme-code">badStatuses</span>``<span class="editor-theme-code">.</span>``<span class="editor-theme-code">length</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">===</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">0</span>``<span class="editor-theme-code">,</span>`  
`<span class="editor-theme-code">  </span>``<span class="editor-theme-code">'Found '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> badStatuses</span>``<span class="editor-theme-code">.</span>``<span class="editor-theme-code">length</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">' 5xx response(s) on /api/order: '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> badStatuses</span>``<span class="editor-theme-code">.join(</span>``<span class="editor-theme-code">', '</span>``<span class="editor-theme-code">)</span>`  
`<span class="editor-theme-code">);</span>`  
`<span class="editor-theme-code">log(</span>``<span class="editor-theme-code">'✓ All '</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> statuses</span>``<span class="editor-theme-code">.</span>``<span class="editor-theme-code">length</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">+</span>``<span class="editor-theme-code"> </span>``<span class="editor-theme-code">' /api/order responses were below 500'</span>``<span class="editor-theme-code">);</span>`

---

## Error handling

All library methods throw a descriptive error on failure. These surface directly in the AIQ test report with context including the HTTP status code, Splunk SID, field name, or assertion mismatch. No additional `<span class="editor-theme-code">try/catch</span>` is required — let errors propagate so the scenario fails with a clear message.

---

## Common issues

<table id="bkmrk-symptomlikely-causef" style="border: 0.666667px solid rgb(57, 62, 64); margin: 24px 0px 0px; border-collapse: collapse; width: 760px; table-layout: fixed; font-size: 1em; height: 1px;"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr style="box-sizing: border-box; height: 46.75px;"><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Symptom

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Likely cause

</th><th class="align-left" style="background-color: rgb(32, 35, 36); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 0px; text-align: left; vertical-align: top; box-sizing: border-box; min-width: 48px; font-weight: 400; position: relative;">Fix

</th></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">HTTP 401 on job creation

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Invalid or expired token

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Regenerate the token in Splunk Settings → Tokens

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Connection refused / timeout

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">TestNode cannot reach Splunk port 8089

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Check EC2 security groups and firewall rules

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">`<span class="editor-theme-code">assertAtLeast</span>` fails even though event exists

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Log ingestion lag — event not yet indexed

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Use `<span class="editor-theme-code">splunk.waitForEvent()</span>` instead of `<span class="editor-theme-code">splunk.search()</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Search times out

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Broad query or slow Splunk cluster

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Narrow the SPL time window or add more filters; increase `<span class="editor-theme-code">maxPollAttempts</span>`

</td></tr><tr style="box-sizing: border-box;"><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Field not found error

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Field name differs from what Splunk extracts

</td><td class="align-left" style="background-color: rgb(24, 26, 27); border-width: 0.666667px 0px 0px 0.666667px; border-style: solid; border-color: rgb(221, 222, 225); border-image: none; padding: 8px; text-align: left; box-sizing: border-box; min-width: 48px; font-weight: 400; vertical-align: top;">Run the same SPL in the Splunk UI and verify field names in the results table

</td></tr></tbody></table>

---

## Best practices

- **Always use DPL variables** for `<span class="editor-theme-code">SPLUNK_HOST</span>` and `<span class="editor-theme-code">SPLUNK_TOKEN</span>`. Never hardcode connection details in scripts.
- **Keep time windows short** (e.g. `<span class="editor-theme-code">-5m</span>` or `<span class="editor-theme-code">-10m</span>`) to keep searches fast and assertions specific to the current test run.
- **Use** `<span class="editor-theme-code">| head N</span>` in SPL to cap result sizes when you only need a few rows.
- **Prefer** `<span class="editor-theme-code">waitForEvent</span>` over a fixed sleep for async flows — it stops as soon as the event appears.
- **Use** `<span class="editor-theme-code">assertNoErrors</span>` as a blanket post-scenario health check in addition to specific field assertions.
- **Use** `<span class="editor-theme-code">storeResult</span>` to pass Splunk values into TheLocker rather than re-querying Splunk in every downstream script.
- **Call** `<span class="editor-theme-code">splunk.init()</span>` **once per script** at the top, before any other `<span class="editor-theme-code">splunk.*</span>` call.