Dashboards & Visualizations

Query to compare both row & column value for a server and get unique final status based on comparison.

Mallik657
Explorer

I have a sample data pushed to splunk as below: Help me with splunk query where I want only unique server names with final status as second column. compare both horizantally & vertically for each server second column status, if any of the second column value is No for that server then consider No as final status for that server, if all the second column values are Yes for a Server, then consider that server final status as Yes.

sample.csv:
ServerName,Status
Server1,Yes
Server1,No
Server1,Yes
Server2,No
Server2,No
Server3,Yes
Server3,Yes
Server4,Yes
Server5,No
Server6,Yes
Server6,No
Server6,Yes
Server6,No
Server7,Yes
Server7,Yes
Server7,Yes
Server7,Yes
Server8,No
Server8,No
Server8,No
Server8,No

Output should looks similar to below: 

ServerName,FinalStatus
Server1,No
Server2,No
Server3,Yes
Server4,Yes
Server5,No
Server6,No
Server7,Yes
Server8,No

Labels (3)
Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

It would help if you would explain "its not working" and show the output of the sample query.  However, I think I know what the problem is.  I left out a command in the query.

...
| eval FinalStatus = if(Status="Yes", 1, 0)
| eventstats min(FinalStatus) as FinalStatus by ServerName
| stats min(FinalStatus) as FinalStatus by ServerName
| eval FinalStatus = if(FinalStatus=1, "Yes", "No")
| table ServerName, FinalStatus
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

Mallik657
Explorer

Its not working & not giving required output . below is my sample query:

index=abc laas_appId=XYZ source="/opt/var/directory/sample.csv" | dedup _raw | table ServerName,Status | eval FinalStatus = if(Status="Yes", 1, 0) | eventstats min(FinalStatus) as FinalStatus by ServerName | eval FinalStatus = if(FinalStatus=1, "Yes", "No") | table ServerName, FinalStatus
0 Karma

richgalloway
SplunkTrust
SplunkTrust

It would help if you would explain "its not working" and show the output of the sample query.  However, I think I know what the problem is.  I left out a command in the query.

...
| eval FinalStatus = if(Status="Yes", 1, 0)
| eventstats min(FinalStatus) as FinalStatus by ServerName
| stats min(FinalStatus) as FinalStatus by ServerName
| eval FinalStatus = if(FinalStatus=1, "Yes", "No")
| table ServerName, FinalStatus
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

You should be able to do that using eventstats.

...
| eval FinalStatus = if(Status="Yes", 1, 0)
| eventstats min(FinalStatus) as FinalStatus by ServerName
| eval FinalStatus = if(FinalStatus=1, "Yes", "No")
| table ServerName, FinalStatus

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...