Splunk Search

script for comparing cells

SridharS
Path Finder

Hi,
I have a search query which fetches the result

host            server1                 server1                                  
 _time           2015-09-15 11:48:42     2015-09-16 11:48:42
 app_version     2.0.1                   2.0.1
 RAM_size        6                       5

This is the comparison of status of a server for earliest=-1d@d and latest = now. Here I need to highlight the RAM_size since the value differs from previous day. I tried a java script form splunk 6.x dashboard examples. But I am not able to do any trick way. Is there a better way to do this

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {

            return _(['children[1]', 'children[2]']).contains(cell.field);
        },
        render: function($td, cell) {

            var value = parseFloat(cell.value);

            if(jQuery(this).children[1].innerHTML == jQuery(this).children[2].innerHTML )
                {
                    $td.addClass('range-cell').addClass('range-elevated');
                }
            }

    });
    mvc.Components.get('highlight').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).parents('tr').addClass(this.className);
            });
        });

        tableView.table.render();
    });
});
Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Since you're displaying each metrics in separate row, highlighting whole row would be a easier option to implement. Try these steps

1) Add another field, lets say 'result', which will 0 if metrics for both servers matches and 1 if they don't (like RAM_size field).
2) Lookup at the Splunk 6 dashboard example "Table Row Highlighting". Update the js to look at field 'result' and if it has value of 1, highlight the row
3) Use "fields" option in your table xml to show the required fields.

View solution in original post

0 Karma

somesoni2
Revered Legend

Since you're displaying each metrics in separate row, highlighting whole row would be a easier option to implement. Try these steps

1) Add another field, lets say 'result', which will 0 if metrics for both servers matches and 1 if they don't (like RAM_size field).
2) Lookup at the Splunk 6 dashboard example "Table Row Highlighting". Update the js to look at field 'result' and if it has value of 1, highlight the row
3) Use "fields" option in your table xml to show the required fields.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...