Splunk Search

How to replace a value of a field with other varying field values?

arrangineni
Path Finder

I have a splunk query which gives below tabular results in snap. But I want to replace the values of "count" field for Status="N/A" with the "Diff" field values. Values are dynamic and changes everytime. My query looks like this, I am trying to bring totals using two search queries and appending with the main search which brings column totals.

Can you advise on this or any better query which populates the results in the similar tabular format.

index=work sourcetype="access_combined_wcookie" Mozilla | stats count by status | addcoltotals count labelfield=status label=N/A  
| append [search index=work sourcetype="access_combined_wcookie" | stats count | addcoltotals count labelfield=status label=Total2 | where isnotnull(status) ] 
| appendcols [search index=work sourcetype="access_combined_wcookie" Mozilla |stats count by status| stats sum(count) as Total1 ]
| appendcols [search index=work sourcetype="access_combined_wcookie" | stats count as Total2 ] 
| eval Diff=(Total2-Total1) 
| fields - Total1, Total2

Thanks in Advance
alt text

0 Karma
1 Solution

maciep
Champion

I think for your search, you could just add something like this at the end.

... | filldown Diff | eval count = if(status = "N/A",Diff,count)

But I think this search is doing a lot of work to get where you going. It's a little hard to determine exactly what you're trying to do, but it looks like a status count for Mozilla events, along with a count of non-Mozilla events with a status of "N/A", and then a total count of events called Total2?

So maybe something like this (not at all tested)?

index=work sourcetype="access_combined_wcookie"
| eval status = if(match(_raw,"(?i)mozilla"),"N/A",status)
| stats count by status
| addcoltotals count labelfield=status label="Total2"

View solution in original post

maciep
Champion

I think for your search, you could just add something like this at the end.

... | filldown Diff | eval count = if(status = "N/A",Diff,count)

But I think this search is doing a lot of work to get where you going. It's a little hard to determine exactly what you're trying to do, but it looks like a status count for Mozilla events, along with a count of non-Mozilla events with a status of "N/A", and then a total count of events called Total2?

So maybe something like this (not at all tested)?

index=work sourcetype="access_combined_wcookie"
| eval status = if(match(_raw,"(?i)mozilla"),"N/A",status)
| stats count by status
| addcoltotals count labelfield=status label="Total2"

arrangineni
Path Finder

Thanks a lot, it worked for me. Even the second query is bringing my results.

Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...