Hello,
I'm trying to build a dashboard using Splunk 6.2 and I've hit a snag. I want to color a cell in a table depending on the value (numeric and non-numeric).
I've tried multiple answers provided in this forum as well as the dashboard example app, but haven't been able to make anything work.
The following is my dashboard xml
<dashboard script="app.js" stylesheet="app.css">
<label>Check_Dashboard</label>
<row>
<panel>
<table>
<searchString>index=eventm* sourcetype=healthcheck | head 3 | table CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy</searchString>
</table>
</panel>
</row>
<row>
<panel>
<table id="health">
<searchString>index=eventm* sourcetype=healthcheck | head 3 | fields CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy |stats by CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy</searchString>
</table>
</panel>
</row>
</dashboard>
And this is my app.js file modified a bit from the examples (I'm not well versed in javascripting):
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
// Row Coloring Example with custom, client-side range interpretation
var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
// Enable this custom cell renderer for both the active_hist_searches and the active_realtime_searches field
return _(['PrimaryRunning']).contains(cell.field);
},
render: function($td, cell) {
// Add a class to the cell based on the returned value
var value = parseFloat(cell.value);
// Apply interpretation for number of historical searches
if (cell.field === 'PrimaryRunning') {
if (value == YES ) {
$td.addClass('range-cell').addClass('range-severe');
}
else if (value == NO ) {
$td.addClass('range-cell').addClass('range-low');
}
}
// Apply interpretation for number of realtime searches
//if (cell.field === 'active_realtime_searches') {
/* if (value > 1) {
$td.addClass('range-cell').addClass('range-severe');
}
*/}
// Update the cell content
$td.text(value.toFixed(2)).addClass('numeric');
}
});
mvc.Components.get('health').getVisualization(function(tableView) {
// Add custom cell renderer, the table will re-render automatically.
tableView.addCellRenderer(new CustomRangeRenderer());
});
});
I've tried restarting after changing the app.js and app.css files. Nothing seems to be working.
Any help is much appreciated.
Thanks.
EDIT:
Here is the app.css file:
#highlight td.range-low {
color: #C0D9D9 !important;
}
#highlight td.range-elevated {
background-color: #ffc57a !important;
font-weight: bold;
}
#highlight td.range-severe {
background-color: #d59392 !important;
font-weight: bold;
}
... View more