Splunk Search

Subsearch not returning results to parent query

donamj
New Member

Hi everybody,

I am trying to write a query which fetches the start and end time of an event log error and use that time period to get the total loss due to the error. Fetching the start and end time is done using a subsearch and the parent query uses this data to find the total loss

Tried running the parent query independently(by hardcoding the subsearch result) and the subsearch query independently and they work fine. However when I tried to merge them together, splunk does not return any results.

sourcetype="source" "Error Log" | stats min(_time) as MySTime max(_time) as MyETime | Eval MyStartTime = strftime(MySTime, "%Y-%m-%d %H:%M:%S") |EVAL MyEndTime = strftime(MyETime, "%Y-%m-%d %H:%M:%S") | fields MyStartTime, MyEndTime, Total [Search earliest="6/12/2013:00:00:00" latest="6/12/2013:06:00:00" sourcetype="source-2" ACTION_TYPE=5 | EVAL Amount = (QUANTITY * PRODUCT_PRICE) | stats Sum(Amount) as Total | where strftime(ACTION_TIME, "%Y-%m-%d %H:%M:%S") >= "2013-06-12 00:00:00" |fields + Total |Return Total]

Can someone please help us urgently.

0 Karma

dart
Splunk Employee
Splunk Employee

Your query is set up to run the subsearch, and return the Total into the fiedls command of the other search. i.e. it's running

sourcetype="source" "Error Log" | stats min(_time) as MySTime max(_time) as MyETime | Eval MyStartTime = strftime(MySTime, "%Y-%m-%d %H:%M:%S") |EVAL MyEndTime = strftime(MyETime, "%Y-%m-%d %H:%M:%S") | fields MyStartTime, MyEndTime, Total <Result of the Subsearch>

Which is not what you are trying to do. I think you are trying to get a start and end time using this search :

sourcetype="source" "Error Log" | stats min(_time) as MySTime max(_time) as MyETime | Eval MyStartTime = strftime(MySTime, "%Y-%m-%d %H:%M:%S") |EVAL MyEndTime = strftime(MyETime, "%Y-%m-%d %H:%M:%S") | fields MyStartTime, MyEndTime

Then run this search over that timerange:

earliest="6/12/2013:00:00:00" latest="6/12/2013:06:00:00" sourcetype="source-2" ACTION_TYPE=5 | EVAL Amount = (QUANTITY * PRODUCT_PRICE) | stats Sum(Amount) as Total | where strftime(ACTION_TIME, "%Y-%m-%d %H:%M:%S") >= "2013-06-12 00:00:00" |fields + Total

Which you would do like so:

[search sourcetype="source" "Error Log" | stats min(_time) as MySTime max(_time) as MyETime | Eval earliest = strftime(MySTime, "%Y-%m-%d %H:%M:%S") |EVAL latest = strftime(MyETime, "%Y-%m-%d %H:%M:%S") | table earliest latest ] sourcetype="source-2" ACTION_TYPE=5 | EVAL Amount = (QUANTITY * PRODUCT_PRICE) | stats Sum(Amount) as Total | where strftime(ACTION_TIME, "%Y-%m-%d %H:%M:%S") >= "2013-06-12 00:00:00" |fields + Total

Does that work for you?

0 Karma

donamj
New Member

Tried that and it is not returning any result.
Just noticed that 'Inspect' command is showing up the 'Total' from the subsearch but its not displayed in SPLUNK output.

0 Karma

linu1988
Champion

From this i am assuming the Total is a field from the search not evaluated. When you do the search for only for Total, why do you make the stats? Try the calculation after the SubSearch. See if the subsearch returns any matching result. Thanks.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...