Splunk Dev

Is there any way to identify the status of the search job attached to a visualization inside "updateview" method

paramagurukarth
Builder

I am creating a custom visualization as given in this link

Visualization is working fine.

Only problem I am facing is the the animation I gave as getting triggered more than once. The reason is the "updateview" method is getting triggered for all intermediate results.

I just want to show the result only when the job got competed.

Is there any way to identify the status of the search job inside "updateview" method of SplunkVisualizationBase

Tags (2)
0 Karma
1 Solution

niketn
Legend

@paramagurukarthikeyan the behavior of Splunk Visualizations (in fact Splunk Search), is to keep returning results as they are processed. So ideally, visualizations should be created in a way that they show intermediate results as data keeps getting pulled in Splunk, rather than showing empty panel and waiting for search to complete (what if it takes 30 min.)?

One of the crude way to implement the behavior you are looking for is to use depends and rejects on a token that is unset in Search <progress> event handler and then set in <done> event handler.

Following is a run anywhere example of a long running search which shows a Spinner Wheel when the search is running and switches to Timechart when the search completes.

<dashboard>
  <label>Update View</label>
  <row>
    <panel> 
     <!-- HTML Panel for Spinner -->
     <html rejects="$displayViz$">
       <h2>Search is running!</h2>
       <!-- CSS Style to Create Spinner using animation -->
       <style>
         .loadSpinner {
           margin: 0 auto;
           border: 5px solid #FFF; /* White BG */
           border-top: 5px solid #3863A0; /* Blue */
           border-radius: 50%;
           width: 20px;
           height: 20px;
           animation: spin 1s linear infinite;
         }
         @keyframes spin {
           0% { transform: rotate(0deg); }
           100% { transform: rotate(360deg); }
         }
         <!-- CSS override to hide default Splunk Search Progress Bar -->
         #panel1 .progress-bar{
           visibility: hidden;
         }
       </style>
       <div class="loadSpinner"/>
     </html>
    </panel>
    <panel>
      <title>Display Chart Only When Search Completes</title>
      <chart depends="$displayViz$">
        <search>
          <query>index=_internal sourcetype=splunkd
| timechart span=1h count by log_level</query>
          <earliest>-30d@d</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
          <progress>
            <unset token="displayViz"></unset>
          </progress>
          <done>
            <set token="displayViz">true</set>
          </done>
        </search>
        <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
        <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
        <option name="charting.axisTitleX.visibility">visible</option>
        <option name="charting.axisTitleY.visibility">visible</option>
        <option name="charting.axisTitleY2.visibility">visible</option>
        <option name="charting.axisX.abbreviation">none</option>
        <option name="charting.axisX.scale">linear</option>
        <option name="charting.axisY.abbreviation">none</option>
        <option name="charting.axisY.scale">log</option>
        <option name="charting.axisY2.abbreviation">none</option>
        <option name="charting.axisY2.enabled">0</option>
        <option name="charting.axisY2.scale">inherit</option>
        <option name="charting.chart">line</option>
        <option name="charting.chart.bubbleMaximumSize">50</option>
        <option name="charting.chart.bubbleMinimumSize">10</option>
        <option name="charting.chart.bubbleSizeBy">area</option>
        <option name="charting.chart.nullValueMode">gaps</option>
        <option name="charting.chart.showDataLabels">none</option>
        <option name="charting.chart.sliceCollapsingThreshold">0.01</option>
        <option name="charting.chart.stackMode">default</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.drilldown">none</option>
        <option name="charting.layout.splitSeries">0</option>
        <option name="charting.layout.splitSeries.allowIndependentYRanges">0</option>
        <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
        <option name="charting.legend.mode">standard</option>
        <option name="charting.legend.placement">right</option>
        <option name="charting.lineWidth">2</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
      </chart>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@paramagurukarthikeyan the behavior of Splunk Visualizations (in fact Splunk Search), is to keep returning results as they are processed. So ideally, visualizations should be created in a way that they show intermediate results as data keeps getting pulled in Splunk, rather than showing empty panel and waiting for search to complete (what if it takes 30 min.)?

One of the crude way to implement the behavior you are looking for is to use depends and rejects on a token that is unset in Search <progress> event handler and then set in <done> event handler.

Following is a run anywhere example of a long running search which shows a Spinner Wheel when the search is running and switches to Timechart when the search completes.

<dashboard>
  <label>Update View</label>
  <row>
    <panel> 
     <!-- HTML Panel for Spinner -->
     <html rejects="$displayViz$">
       <h2>Search is running!</h2>
       <!-- CSS Style to Create Spinner using animation -->
       <style>
         .loadSpinner {
           margin: 0 auto;
           border: 5px solid #FFF; /* White BG */
           border-top: 5px solid #3863A0; /* Blue */
           border-radius: 50%;
           width: 20px;
           height: 20px;
           animation: spin 1s linear infinite;
         }
         @keyframes spin {
           0% { transform: rotate(0deg); }
           100% { transform: rotate(360deg); }
         }
         <!-- CSS override to hide default Splunk Search Progress Bar -->
         #panel1 .progress-bar{
           visibility: hidden;
         }
       </style>
       <div class="loadSpinner"/>
     </html>
    </panel>
    <panel>
      <title>Display Chart Only When Search Completes</title>
      <chart depends="$displayViz$">
        <search>
          <query>index=_internal sourcetype=splunkd
| timechart span=1h count by log_level</query>
          <earliest>-30d@d</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
          <progress>
            <unset token="displayViz"></unset>
          </progress>
          <done>
            <set token="displayViz">true</set>
          </done>
        </search>
        <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
        <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
        <option name="charting.axisTitleX.visibility">visible</option>
        <option name="charting.axisTitleY.visibility">visible</option>
        <option name="charting.axisTitleY2.visibility">visible</option>
        <option name="charting.axisX.abbreviation">none</option>
        <option name="charting.axisX.scale">linear</option>
        <option name="charting.axisY.abbreviation">none</option>
        <option name="charting.axisY.scale">log</option>
        <option name="charting.axisY2.abbreviation">none</option>
        <option name="charting.axisY2.enabled">0</option>
        <option name="charting.axisY2.scale">inherit</option>
        <option name="charting.chart">line</option>
        <option name="charting.chart.bubbleMaximumSize">50</option>
        <option name="charting.chart.bubbleMinimumSize">10</option>
        <option name="charting.chart.bubbleSizeBy">area</option>
        <option name="charting.chart.nullValueMode">gaps</option>
        <option name="charting.chart.showDataLabels">none</option>
        <option name="charting.chart.sliceCollapsingThreshold">0.01</option>
        <option name="charting.chart.stackMode">default</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.drilldown">none</option>
        <option name="charting.layout.splitSeries">0</option>
        <option name="charting.layout.splitSeries.allowIndependentYRanges">0</option>
        <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
        <option name="charting.legend.mode">standard</option>
        <option name="charting.legend.placement">right</option>
        <option name="charting.lineWidth">2</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
      </chart>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

paramagurukarth
Builder

Thank You....

0 Karma

niketn
Legend

@paramagurukarthikeyan, I have converted my comment to answer. If your issue is resolved please accept the answer to mark the question as answered!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

paramagurukarth
Builder

My Problem/Expectation is not solved. But you showed me why it is not possible

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 ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...