Splunk Search

How to merge results by column values?

Dzmitry
Explorer

Hi guys,

I have a search for the host with check_id statuses:

index="..." exec_mode="..." host="..."  check_id="..." | table check_id status

that returns a column with 'passed'/'failed' values

I'm looking for the solution to how to check the column for 'failed' statuses in it and merge all results based on such condition: if 'failed' in statuses then statuses='failed'

Table

check_id status
check1 Passed
check1 Passed
check1 Failed
check1 Passed

 

Expected result:

check_id status
check1 failed

 

Thank you in advance.

 

 

 

 

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Dzmitry,

you have to use the stats command instead table, something like this:

index="..." exec_mode="..." host="..."  check_id="..." 
| stats dc(status) AS status_count Values(status) AS status BY check_id 
| eval status=if(status_count=1 AND status="Passed","Passed","Failed")
| table check_id status

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @Dzmitry,

you have to use the stats command instead table, something like this:

index="..." exec_mode="..." host="..."  check_id="..." 
| stats dc(status) AS status_count Values(status) AS status BY check_id 
| eval status=if(status_count=1 AND status="Passed","Passed","Failed")
| table check_id status

Ciao.

Giuseppe

Dzmitry
Explorer

Hi Giuseppe
thank you for help!

May I ask one more question?
This part of the query usually returns 6 columns (  host, check_id, status, info, region, msg)

index="..." exec_mode="..." 

 then I use 

| stats dc(status) AS status_count Values(status) AS status BY check_id 
| eval status=if(status_count=1 AND status="Passed","Passed","Failed")
| table check_id status

the table has values 
after it I'd like count statuses by host_name  | stats count(status) BY host_name
however I get 'No results found.'

What am I doing wrong?
Thank you

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...