Splunk Search

How to display certain background colors for single value visualizations based on search results?

JoshuaJohn
Contributor

I am trying to make my search have 3 different background colors: Green if healthy, Yellow if warning, Red if critical. Right now all the code displays is the correct information without any colors. I took the query part out cause it was long and irrelevant

index="query"
| eval Level=if(Alert_Type="Critical",2,if(Alert_Type="Warning",1,0)) 
| eval key=Description.ID 
| stats dc(key) AS num max(Level) AS Level 
| eval count=if(Level=1,"Alert Level: Warning - Total Alerts: ".num,if(Level=2,"Alert Level: Critical - Total Alerts: ".num,"Alert Level: Healthy - Total Alerts: 0")) 
| eval Level=if(isnotnull(Level),Level,0) 
| eval myClassField=case(Level=2,"red",Level=1,"yellow",Level=0,"green") 
| table count Level myClassField 
| rename count AS "Health Summary"

Thanks for the help!

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

How about this

index="query"
| eval Level=if(Alert_Type="Critical",2,if(Alert_Type="Warning",1,0)) 
| eval key=Description.ID 
| stats dc(key) AS num max(Level) AS Level 
| eval  "Health Summary"=if(Level=1,"Alert Level: Warning - Total Alerts: ".num,if(Level=2,"Alert Level: Critical - Total Alerts: ".num,"Alert Level: Healthy - Total Alerts: 0")) | fillnull Level value=0 | rangemap field=Level severe=2-2 elevated=1-1 default=low
| table "Health Summary" range

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

How about this

index="query"
| eval Level=if(Alert_Type="Critical",2,if(Alert_Type="Warning",1,0)) 
| eval key=Description.ID 
| stats dc(key) AS num max(Level) AS Level 
| eval  "Health Summary"=if(Level=1,"Alert Level: Warning - Total Alerts: ".num,if(Level=2,"Alert Level: Critical - Total Alerts: ".num,"Alert Level: Healthy - Total Alerts: 0")) | fillnull Level value=0 | rangemap field=Level severe=2-2 elevated=1-1 default=low
| table "Health Summary" range
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...