Splunk Search

Subsearch not returning results to parent query

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

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

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

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