Let’s try to understand first what we are going to do today. So we have a table like this,
index=_internal sourcetype="splunkd" | stats count by sourcetype
The above table is showing only the count of “splunkd” source type.
Now whenever the “count” field will have more than zero count table header color will be “Green”, if the count is zero then the header color will be “Yellow”.
Before going to the exact requirement let’s create a dropdown that can create the similar kind of scenario we want for the use case.
We have created a dropdown with “sourcetype” token and two static values “splunkd” and “invalid”. And we have passed the token within our panel.
I.e. whenever we will select “splunkd” it will show count, and if we select “invalid” it should show zero. It is the exact scenario we need for our use case.
Now currently if we select “invalid” its shows “No Results Found”, like this
To overcome this we need to modify our query a bit,
index=_internal sourcetype="$sourcetype$" |stats count by sourcetype | appendpipe [stats count | where count=0]
Now if we select “invalid” it will show like this,
Instead of showing “No results found”, its shows count=0. That is exactly what we want.
Now let’s move to our exact use case,
Click on “Edit” and go to “Source”.
Now do these following changes as shown below.
At the beginning [from line 12 to 13], we have created a new row where we have used a customized HTML code to set a color to the table header by taking the “.table th” component. We have used the “background-color” option to set colors and defined a token “th_color”.That particular token is set up from line 28 to 35, where we have used a couple of conditions that if the count is greater than zero it will pass “green” else it will pass “yellow”.
NOTE: We have created the dropdown to set an exact scenario we need for our use case. In your case, we can ignore creating the dropdown as we mentioned previously also.
Hope you all enjoyed this blog “Change Table Header Color Based on Values Present in the Table“. See you on to the next one.