<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JS script loaded before searches in a dashboard? in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643432#M16335</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/256743"&gt;@Razziat&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your Sample Dashboard code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KV&lt;/P&gt;</description>
    <pubDate>Mon, 15 May 2023 17:42:50 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2023-05-15T17:42:50Z</dc:date>
    <item>
      <title>JS script loaded before searches in a dashboard?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643403#M16331</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I am creating a dashboard in which I have a search that returns a multiple value field table.&lt;BR /&gt;I'm also using a JS script and a CSS script to make this table look better.&lt;BR /&gt;Each time I open/refresh the dashboard, I have the impression that the JS script loads before the searches finish loading. So I have to press the edit button to see the JS script applied to the table search.&lt;BR /&gt;Do you have a solution to fix this problem?&lt;/P&gt;
&lt;P&gt;Thanks in advance !&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 14:55:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643403#M16331</guid>
      <dc:creator>Razziat</dc:creator>
      <dc:date>2023-05-15T14:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: JS script loaded before searches in a dashboard?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643432#M16335</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/256743"&gt;@Razziat&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your Sample Dashboard code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KV&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 17:42:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643432#M16335</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-05-15T17:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: JS script loaded before searches in a dashboard?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643468#M16338</link>
      <description>&lt;P&gt;The pretty_print.js and the pretty_colors.css are used for the research named "MITRE matrix".&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form script="pretty_print.js" stylesheet="pretty_colors.css" version="1.1"&amp;gt;
  &amp;lt;label&amp;gt;Mitre Compliance&amp;lt;/label&amp;gt;
  &amp;lt;search id="basesearch2"&amp;gt;
    &amp;lt;query&amp;gt;
| inputlookup technique_mitre.csv
| lookup tactique_mitre.csv idTactique OUTPUT nomTactique idTactiqueMitre
| lookup security_mitre.csv idTechnique output item type
| lookup attack_group_mitre.csv idTechnique output nomGrpAtck
| fillnull value="toto" type nomGrpAtck
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="false"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Filtre la mitre matrix&amp;lt;/title&amp;gt;
      &amp;lt;input type="radio" token="filter_outil_alerte" searchWhenChanged="true"&amp;gt;
        &amp;lt;label&amp;gt;Filtre Outil/Alerte&amp;lt;/label&amp;gt;
        &amp;lt;choice value="*"&amp;gt;Tous&amp;lt;/choice&amp;gt;
        &amp;lt;choice value="outil"&amp;gt;Outil&amp;lt;/choice&amp;gt;
        &amp;lt;choice value="alerte"&amp;gt;Alerte&amp;lt;/choice&amp;gt;
        &amp;lt;choice value="ngp et/ou edr"&amp;gt;NGP et/ou EDR&amp;lt;/choice&amp;gt;
        &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
        &amp;lt;prefix&amp;gt;"&amp;lt;/prefix&amp;gt;
        &amp;lt;suffix&amp;gt;"&amp;lt;/suffix&amp;gt;
        &amp;lt;initialValue&amp;gt;*&amp;lt;/initialValue&amp;gt;
      &amp;lt;/input&amp;gt;
      &amp;lt;input type="multiselect" token="idGrpAtck"&amp;gt;
        &amp;lt;label&amp;gt;Liste des schémas d'attaques&amp;lt;/label&amp;gt;
        &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
        &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
        &amp;lt;valuePrefix&amp;gt;"&amp;lt;/valuePrefix&amp;gt;
        &amp;lt;valueSuffix&amp;gt;"&amp;lt;/valueSuffix&amp;gt;
        &amp;lt;fieldForLabel&amp;gt;nomGrpAtck&amp;lt;/fieldForLabel&amp;gt;
        &amp;lt;fieldForValue&amp;gt;nomGrpAtck&amp;lt;/fieldForValue&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| inputlookup attack_group_mitre.csv
| fields nomGrpAtck
| dedup nomGrpAtck&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;delimiter&amp;gt; &amp;lt;/delimiter&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;MITRE matrix&amp;lt;/title&amp;gt;
      &amp;lt;table id="mitrematrix"&amp;gt;
        &amp;lt;search base="basesearch2"&amp;gt;
          &amp;lt;query&amp;gt;| search type IN($filter_outil_alerte$)
| search nomGrpAtck IN($idGrpAtck$)
| stats values(item) as item dc(item) as dis_count values(nomTechnique) as nomTechnique by idTactique idTechnique
| eval item=mvjoin(item, "=")
| strcat idTechnique "|" nomTechnique "|" item "|" dis_count nomTechnique
| streamstats count by idTactique
| xyseries count idTactique nomTechnique
| sort count
| table reconnaissance, resource-development, initial-access, execution, persistence, privilege-escalation, defense-evasion, credential-access, discovery, lateral-movement, collection, command-and-control, exfiltration, impact
| rename reconnaissance as "Reconnaissance", resource-development as "Resource Development", initial-access as "Initial Access", execution as "Execution", persistence as "Persistence", privilege-escalation as "Privilege Escalation", defense-evasion as "Defense Evasion", credential-access as "Credential Access", discovery as "Discovery", lateral-movement as "Lateral Movement", collection as "Collection", command-and-control as "Command and Control", exfiltration as "Exfiltration", impact as "Impact"
| fillnull value="NULL|NULL|NULL"&amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;50&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:09:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643468#M16338</guid>
      <dc:creator>Razziat</dc:creator>
      <dc:date>2023-05-16T07:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: JS script loaded before searches in a dashboard?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643506#M16344</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/256743"&gt;@Razziat&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JS will always load first. When the dashboard is getting loaded, Splunk JS Extension will be loaded just before the dashboard is ready for use.&lt;/P&gt;&lt;P&gt;Splunk JS Extension has 2 token models.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;default&lt;/STRONG&gt; token model&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;submitted&lt;/STRONG&gt; token model&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/visualizedata/convertsimplexml/tokenmodels/" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/developapps/visualizedata/convertsimplexml/tokenmodels/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You need to write your javascript code according to the requirements and these two models.&lt;/P&gt;&lt;P&gt;Eg, if you are customizing the TableView then you should declare the customization code in JS, which execute before the dashboard gets finished to load. And the same declared code will be executed on the basis of the lifecycle of that component (in this example, TableView). TableView is dependent on the SearchManager.&amp;nbsp; When searching is done then TableView is getting populated and will be displayed, at this point, our defined Custom JS logic will be executed and will change the Table Row/Cell.&lt;/P&gt;&lt;P&gt;Your XML code looks good to me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want your JS to be executed after dashboard loading then use below JS code and put your code in the SECTION.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'splunkjs/mvc',
    'underscore',
    'splunkjs/mvc/simplexml/ready!'
], function(
    mvc,
    _
) {
    console.log("HIe");
    $(document).ready(function () {
        /*Add Your code here.*/
    });
    
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For further help, you can share your sample JS here OR you can message it to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 15:15:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/643506#M16344</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-05-16T15:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: JS script loaded before searches in a dashboard?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/646105#M16514</link>
      <description>&lt;P&gt;The solution that you prposed didn't work for me.&lt;BR /&gt;Here is my JS script that I am using : (I post it here too for people who may have the same problem)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require.config({
    paths: {
      theme_utils: '../app/test-mitre/theme_utils',
      jquery_local: '../app/test-mitre/lib/js/jquery-3.6.0.min'
    }
  });
  
  require([
      'underscore',
      'jquery_local',
      'splunkjs/mvc',
      'splunkjs/mvc/tableview',
      'theme_utils',
      'splunkjs/mvc/simplexml/ready!'
  ], function(_, jquery, mvc, TableView, themeUtils) {
    
      jQuery.noConflict(); // remove jquery conflicts for splunk js sdk
      var $ = jQuery; // take dollar sign as a local variable
  
       // Row Coloring Example with custom, client-side range interpretation
  
      var isDarkTheme = themeUtils.getCurrentTheme &amp;amp;&amp;amp; themeUtils.getCurrentTheme() === 'dark';
  
      var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
          canRender: function(cell) {
          return _(["Reconnaissance", "Resource Development", "Initial Access", "Execution", "Persistence", "Privilege Escalation", "Defense Evasion", "Credential Access", "Discovery", "Lateral Movement", "Collection", "Command and Control", "Exfiltration", "Impact"]).contains(cell.field);
             },
          render: function($td, cell) {
              // Add a class to the cell based on the returned value
              var value_arr = cell.value.split("|");
              //var value_arr2 = cell.value.split("|");
              var technique_id = value_arr[0];
              var technique_name = value_arr[1];
              var alert_list = value_arr[2];
              var total_count = value_arr[3];
              var urgency_str = "None"

              var good_list = alert_list.replaceAll('=', '\n');
              var ttl = "Total: " + total_count + "\nAlert_list : " + good_list
                if(technique_id.includes('.')) {
                  $td.addClass('subtechnique');
              }
              else {
                if(technique_name=="NULL"){
                  $td.addClass('empty');
                  }
                else {
                  $td.addClass('technique');
                  }
              }
              $td.tooltip();
              $td.prop('title', ttl);
              if (total_count != "NULL") {
                  total =  parseFloat(total_count);
                  if(total &amp;gt;= 10){
                      $td.addClass('range-cell').addClass('range-compliance_high');
                  }
                    if(total &amp;gt;= 4){
                      $td.addClass('range-cell').addClass('range-compliance_mid');
                  }
                  if(total &amp;gt;= 1){
                      $td.addClass('range-cell').addClass('range-compliance_low');
                  }
                  if(total &amp;gt;= 0){
                      $td.addClass('range-cell').addClass('range-compliance_zero');
                  }
  
              }
              else if(total_count == "NULL"){
                  $td.addClass('range-cell').addClass('range-none');
              }
  
  
              if (isDarkTheme) {
                $td.addClass('dark');
              }
  
              // Update the cell content
             //$td.text(value.toFixed(2)).addClass('numeric');
  
              if (technique_name=="NULL"){
                  $td.text(" ");
              }
              else {
                  $td.text(technique_id + ": " + technique_name);
                  $td.addClass('add-border').addClass('text-align-center');
  
              }
          }
      });
  
      mvc.Components.get('mitrematrix').getVisualization(function(tableView) {
          // Add custom cell renderer, the table will re-render automatically.
          tableView.addCellRenderer(new CustomRangeRenderer());
      });
  
  });&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:54:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/JS-script-loaded-before-searches-in-a-dashboard/m-p/646105#M16514</guid>
      <dc:creator>Razziat</dc:creator>
      <dc:date>2023-06-07T12:54:33Z</dc:date>
    </item>
  </channel>
</rss>

