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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...