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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...