Hi vganjare. I tried your solution but the table shows empty if i apply the javascript and css to the dashboard.
Splunk Query
sourcetype=ret | rex "popularityIndex=(\")(?P<PI>[^>]+)(\")" | search PI=* | rex "<!--(?P<Channel_Name>[^-]+)" | eval Channel_Name = substr(Channel_Name, 0, len(Channel_Name)-18) | dedup Channel_Name | table Channel_Name PI| rename PI as "Popularity Index" Channel_Name as "Channel" | sort "Popularity Index" | appendcols [search sourcetype=shmapplogs "getMS3SAS ended for - deviceId" | bucket span=1d _time | stats count by _time channelId | sort count desc | lookup youview_channels.csv service_id_truncated AS channelId OUTPUT channel_name_letter | streamstats count AS position by _time | fields channel_name_letter position _time | convert timeformat="%d-%b-%Y" ctime(_time) As Time | chart max(position) over channel_name_letter by Time | rename channel_name_letter as "Channel"] | eval Channel = "NO_HIGHLIGHT_"+Channel
Javascript
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 true;
},
render: function($td, cell) {
// Add a class to the cell based on the returned value
// Apply interpretation for number of historical searches
//var tdPosition = $td.parent().children().index($td[0]);
var value = cell.value;
var isHighlight = (value.search('NO_HIGHLIGHT_') == -1);
//console.log(tdposition + value);
//alert(tdposition + value);
if (isHighlight) {
var value = parseInt(value);
if ((value > 0) && (value <= 50)) {
$td.addClass('range-cell').addClass('range-severe');
}
else if ((value > 50) && (value <= 100)) {
$td.addClass('range-cell').addClass('range-elevated');
}
else if ((value > 100) && (value <= 150)) {
$td.addClass('range-cell').addClass('range-low');
}
else {
$td.addClass('range-cell').addClass('range-empty');
}
}
else {
value = value.replace('NO_HIGHLIGHT_','');
}
// Update the cell content
$td.text(value);
}
});
mvc.Components.get('rettable').getVisualization(function(tableView) {
// Add custom cell renderer
tableView.table.addCellRenderer(new CustomRangeRenderer());
// tableView.on('rendered', function() {
// Apply class of the cells to the parent row in order to color the whole row
// tableView.$el.find('td.range-cell').each(function() {
// $(this).addClass(this.className);
// });
//});
// Force the table to re-render
tableView.table.render();
});
});
CSS
#rettable td.range-low {
color: #C0D9D9;
}
#rettable td.range-elevated {
background-color: #ffc57a !important;
font-weight: bold;
}
#rettable td.range-severe {
background-color: #d59392 !important;
font-weight: bold;
}
#rettable td.range-empty {
color: #C0D9D9;
}
Source Code
<panel>
<table id="rettable">
<title>RET Statistics</title>
<search>
<query>sourcetype=ret | rex "popularityIndex=(\")(?P<PI>[^>]+)(\")" | search PI=* | rex "<!--(?P<Channel_Name>[^-]+)" | eval Channel_Name = substr(Channel_Name, 0, len(Channel_Name)-18) | dedup Channel_Name | table Channel_Name PI| rename PI as "Popularity Index" Channel_Name as "Channel" | sort "Popularity Index" | appendcols [search sourcetype=shmapplogs "getMS3SAS ended for - deviceId" | bucket span=1d _time | stats count by _time channelId | sort count desc | lookup youview_channels.csv service_id_truncated AS channelId OUTPUT channel_name_letter | streamstats count AS position by _time | fields channel_name_letter position _time | convert timeformat="%d-%b-%Y" ctime(_time) As Time | chart max(position) over channel_name_letter by Time | rename channel_name_letter as "Channel"] | eval Channel = "NO_HIGHLIGHT_"+Channel</query>
<earliest>$time.earliest$</earliest>
<latest>$time.latest$</latest>
</search>
<option name="wrap">undefined</option>
<option name="rowNumbers">undefined</option>
<option name="drilldown">row</option>
<option name="dataOverlayMode">none</option>
<option name="count">10</option>
</table>
</panel>
... View more