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!

Splunk Forwarders and Forced Time Based Load Balancing

Splunk customers use universal forwarders to collect and send data to Splunk. A universal forwarder can send ...

NEW! Log Views in Splunk Observability Dashboards Gives Context From a Single Page

Today, Splunk Observability releases log views, a new feature for users to add their logs data from Splunk Log ...

Last Chance to Submit Your Paper For BSides Splunk - Deadline is August 12th!

Hello everyone! Don't wait to submit - The deadline is August 12th! We have truly missed the community so ...