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!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...