Splunk Search

Display different values as different labels

wicke_s
Explorer

I am creating a splunk dashboard pie chart panel and the values I am displaying are too large (long strings) to be displayed in a small panel. Is it possible to display the chart values in a readable / concise labels?

For e.g., If the below is my sample query:

index=network sourcetype=logserver | stats dc(Field.ID) by Field.Message

 

If Field.Message is "All transfers were successful", I want to display just "Success" in the pie chart
If Field.Message is "Some transfers failed", I want to display just "Failed"

and so on..

 

What is the best way to achieve this? Thanks in advance

 

Labels (1)
0 Karma
1 Solution

dmarling
Builder

Hello @wicke_s,

The simplest method would be to create an eval that adjusted the output of the Field.Message so it matches your requirements:

index=network sourcetype=logserver 
| eval "Field.Message"=case('Field.Message'="All transfers were successful", "Success", 'Field.Message'="Some transfers failed", "Failed", 1=1, "Other")
| stats dc(Field.ID) by Field.Message

If you have more messages that are unaccounted for you can modify it to be a bit more generic using LIKE:

index=network sourcetype=logserver 
| eval "Field.Message"=case('Field.Message' LIKE "%successful%", "Success", 'Field.Message' LIKE "%failed%", "Failed", 1=1, "Other")
| stats dc(Field.ID) by Field.Message

Ultimately that eval will need to account for all of your use cases or you will end up with a large "Other" bucket.

If this comment/answer was helpful, please up vote it. Thank you.

View solution in original post

anilchaithu
Builder

@wicke_s 

you can change the field values in the query using the below logic. This will change the label in the pie chart 

index=network sourcetype=logserver | stats dc(Field.ID) by Field.Message | replace "All transfers were successful" with Success in Field.Message

dmarling
Builder

Hello @wicke_s,

The simplest method would be to create an eval that adjusted the output of the Field.Message so it matches your requirements:

index=network sourcetype=logserver 
| eval "Field.Message"=case('Field.Message'="All transfers were successful", "Success", 'Field.Message'="Some transfers failed", "Failed", 1=1, "Other")
| stats dc(Field.ID) by Field.Message

If you have more messages that are unaccounted for you can modify it to be a bit more generic using LIKE:

index=network sourcetype=logserver 
| eval "Field.Message"=case('Field.Message' LIKE "%successful%", "Success", 'Field.Message' LIKE "%failed%", "Failed", 1=1, "Other")
| stats dc(Field.ID) by Field.Message

Ultimately that eval will need to account for all of your use cases or you will end up with a large "Other" bucket.

If this comment/answer was helpful, please up vote it. Thank you.

wicke_s
Explorer

Thank you @dmarling , That worked. I have a follow up question about your "Other" bucket comment. What if not all the values of the Field.Message is known before hand? For e.g., Can we display

 

"All transfers were successful" as "Success"

"Some transfers failed" as "Failed"

and display all other Field.Message values as it is

0 Karma

dmarling
Builder

You sure can.  Just modify it slightly:

 

| eval "Field.Message"=case('Field.Message'="All transfers were successful", "Success", 'Field.Message'="Some transfers failed", "Failed", 1=1, 'Field.Message')
If this comment/answer was helpful, please up vote it. Thank you.

wicke_s
Explorer

@dmarling  Exactly what I was looking for, Thank you so much!!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...