Splunk Search

tstats where clause with subsearch for time modifiers

ejwade
Contributor

I have a tstats search that isn't returning a count consistently. In the where clause, I have a subsearch for determining the time modifiers.

Here's the search:

 

| tstats 
    count 
    from datamodel=Vulnerabilities.Vulnerabilities
    where index=qualys_i
    [| search earliest=-4d@d index=_internal host="its-splunk7-hf.ucsd.edu" sourcetype="ta_QualysCloudPlatform*" host_detection ("Done loading detections" OR "Running now") 
    | stats `stime(_time)` `slist(_raw)` count by PID 
    | eval duration = last_seen - first_seen ,earliest = strftime(first_seen - 300, "%m/%d/%Y:%H:%M:%S") ,latest = strftime(last_seen + 300, "%m/%d/%Y:%H:%M:%S") 
    | where count > 1 AND duration < 82800 
    | sort -last_seen 
    | head 1 
    | return earliest latest ]

 

If I run the subsearch on its own...

 

earliest=-4d@d index=_internal host="its-splunk7-hf.ucsd.edu" sourcetype="ta_QualysCloudPlatform*" host_detection ("Done loading detections" OR "Running now") 
| stats `stime(_time)` `slist(_raw)` count by PID 
| eval duration = last_seen - first_seen ,earliest = strftime(first_seen - 300, "%m/%d/%Y:%H:%M:%S") ,latest = strftime(last_seen + 300, "%m/%d/%Y:%H:%M:%S") ``` Exclude results that ran over 23 hours or didn't finish ``` 
| where count > 1 AND duration < 82800 
| sort -last_seen 
| head 1 
| return earliest latest

 

I get the time modifiers accurately (e.g., earliest="11/05/2021:06:25:51" latest="11/05/2021:11:31:12").

When I inspect the job (of the first search), it is able to derive the same time modifiers (in phase0, phase1, and remoteSearch).

The issue - when I run the first search, my count is double. In other words, it's double counting each record. If I explicitly put the time modifiers in place of the subsearch, the count is accurate (not double).

Anyone run into this?

Labels (1)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...