Splunk Search

Remove results based on subsearch

RamMur
Explorer

I'm looking to get all failed event log based on a field , and then trying to find the success event log for the same field, so that i have a net failed even log to report. 

Basically, i'm trying to an alert that i can run every X hours , looking back X hours, and finds me ONLY the failed logs that havent succeeded yet . The failures are retried at regular intervals. In short, get all failed events and weed out the succeeded ones on later retries , so i only have the ones that is still failed. 

Trying something like below but i think there should be better way than this.. 


index=sample cf_org_name=orgname service=xyz sourceSystem!="aaa" errorCd="*-701" status=FAILED
|where jobNumber NOT IN [search index=sample cf_org_name=orgname service=xyz sourceSystem!="aaa" status=SUCCESS ]
|table _time accountNumber jobNumber letterId errorCd
|sort _time

TIA!!

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eventstats latest(status) as latest_status by jobNumber
| where latest_status="FAILED"

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

The Splunk way of doing this sort of task is to use stats, so you search both data sets, combine the bits you want based on the common field and then do conditional logic on the results, e.g.

index=sample cf_org_name=orgname service=xyz sourceSystem!="aaa" (errorCd="*-701" status=FAILED) OR status=SUCCESS
| stats min(eval(if(status="FAILED", _time, null()))) as _time values(status) as status count by  accountNumber jobNumber letterId errorCd
| where status="FAILED" AND mvcount(status)=1

which searches both failed and success events, and then combines them with stats, but retaining _time IFF the event is failed and split by the 4 fields. Without knowing your data, I don't know if letterId and errorCd have a 1:1 correlation with jobNumber, so you'll have to work out if that will work for you.

Then the final where condition will only look for events that have ONLY recorded a FAILED status.

Subsearches have their uses, but generally using NOT clauses is inefficient and a single search (no subsearches) is often a better approach.

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eventstats latest(status) as latest_status by jobNumber
| where latest_status="FAILED"
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...