Splunk Search

Calculate the value of a field based on the values of other fields

alex_orl
Engager

I have a some fields like this:

**Group_servers|Name_server|Status**
    Group1| server1|OK                
    Group1| server2|OK  
    Group2| server1|OK  
    Group2| server1|No data  
    Group2| server1|Yellow
    Group2| server1|

I want to get the result as shown below

Group_servers|Status
        Group1|OK                
        Group1| No data 

Сonditions for the formation of status groups are as follows:
1. If at least one server in the group has the status "No data" or the field is empty, the status for the group is " No data"
2. If at least one server in the group has the "Yellow" status, the status for the group is " Yellow"
3. If all servers in the group have the status "OK", the status for the group is " OK"

0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@lex_orl

Can you please try this?

YOUR_SEARCH 
| stats values(Status) as Status by Group_servers | eval Status=case(Status="" OR Status="No data","No data",Status="Yellow","Yellow",mvdedup(Status)="OK","OK")

My Sample Search:

| makeresults 
| eval Group_servers="Group1,Group1,Group2,Group2,Group2,Group2",
    Name_server="server1,server2,server1,server1,server1,server1",
    Status="OK,OK,OK,No data,Yellow,",Group_servers=split(Group_servers,","),Name_server=split(Name_server,","),Status=split(Status,","),temp=mvzip(mvzip(Group_servers,Name_server),Status) 
| fields temp 
| mvexpand temp
| eval Group_servers=mvindex(split(temp,","),0),Name_server=mvindex(split(temp,","),1),Status=mvindex(split(temp,","),2)
| eval comment="Up to this is for data generation only"
| table Group_servers Name_server Status
| stats values(Status) as Status by Group_servers | eval Status=case(Status="" OR Status="No data","No data",Status="Yellow","Yellow",mvdedup(Status)="OK","OK")

Thanks

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Map status names to codes and take the lowest code.

... | eval statusCode = case(Status="No data", 1, Status="Yellow", 2, Status="OK", 3, 1=1, 99) | streamstats window=0 min(statusCode) by Group_servers | table Group_servers Status

---
If this reply helps you, Karma would be appreciated.
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@lex_orl

Can you please try this?

YOUR_SEARCH 
| stats values(Status) as Status by Group_servers | eval Status=case(Status="" OR Status="No data","No data",Status="Yellow","Yellow",mvdedup(Status)="OK","OK")

My Sample Search:

| makeresults 
| eval Group_servers="Group1,Group1,Group2,Group2,Group2,Group2",
    Name_server="server1,server2,server1,server1,server1,server1",
    Status="OK,OK,OK,No data,Yellow,",Group_servers=split(Group_servers,","),Name_server=split(Name_server,","),Status=split(Status,","),temp=mvzip(mvzip(Group_servers,Name_server),Status) 
| fields temp 
| mvexpand temp
| eval Group_servers=mvindex(split(temp,","),0),Name_server=mvindex(split(temp,","),1),Status=mvindex(split(temp,","),2)
| eval comment="Up to this is for data generation only"
| table Group_servers Name_server Status
| stats values(Status) as Status by Group_servers | eval Status=case(Status="" OR Status="No data","No data",Status="Yellow","Yellow",mvdedup(Status)="OK","OK")

Thanks

Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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