<?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: store search result to a javascript variable for dynamic displaying custom dashboard in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327298#M21213</link>
    <description>&lt;P&gt;PS: The token $tokCount$ set through the search needs to be displayed with CSS Styling in your HTML Panel. Something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;
          index=chartlike qualify=Me | stats count 
        &amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;-1h@h&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;done&amp;gt;
          &amp;lt;condition match="$job.resultCount$==0$"&amp;gt;
            &amp;lt;set token="tokCount"&amp;gt;0&amp;lt;/set&amp;gt;
          &amp;lt;/condition&amp;gt;
          &amp;lt;condition&amp;gt;
            &amp;lt;set token="tokCount"&amp;gt;$result.count$&amp;lt;/set&amp;gt;
          &amp;lt;/condition&amp;gt;
        &amp;lt;/done&amp;gt;
      &amp;lt;/search&amp;gt;

&amp;lt;row&amp;gt;
  &amp;lt;panel&amp;gt;
     &amp;lt;chart&amp;gt;
         ....
         Your Chart Code Here
         ....
     &amp;lt;/chart&amp;gt;
     &amp;lt;html&amp;gt;
        &amp;lt;div&amp;gt;
           &amp;lt;!-- Boton de "me gusta" --&amp;gt;
           &amp;lt;a class="like_chart" title="Me gusta" id="like_app_chart1"&amp;gt;
             &amp;lt;i class="fa fa-2x fa-thumbs-o-up fa-lg"/&amp;gt;
           &amp;lt;/a&amp;gt;
           &amp;lt;div style="font-weight:bold;color:green"&amp;gt;$tokCount$&amp;lt;/div&amp;gt;
          ....
          ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: To understand Search Event Handler and Token refer to the following documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_handlers"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_handlers&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jul 2017 05:23:16 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-07-22T05:23:16Z</dc:date>
    <item>
      <title>store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327294#M21209</link>
      <description>&lt;P&gt;Hi, I'm new to splunk and trying to create a custom dashboard using javascript. I want to store the result from a search to a variable in a javascript code so I can use it for displaying on a custom dashboard. So basically I need something like this:&lt;/P&gt;

&lt;P&gt;javascript file&lt;BR /&gt;
var x =  "search index=test qualify=Me | stats count", &lt;/P&gt;

&lt;P&gt;html&lt;/P&gt;

&lt;P&gt;P.D. I know there is some similare questions out there but i haven't been able to make them work for my particular case.&lt;BR /&gt;
Thanks in advance. &lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 19:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327294#M21209</guid>
      <dc:creator>jperezh</dc:creator>
      <dc:date>2017-07-21T19:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327295#M21210</link>
      <description>&lt;P&gt;@jperezh, you can do this directly via SimpleXML using Search Event Handler and tokens. Any specific reason for JavaScript?&lt;/P&gt;

&lt;P&gt;Following example uses done event handler to access search result field &lt;CODE&gt;count&lt;/CODE&gt; and assign to token to be used elsewhere in the dashboard. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;index=test qualify=Me 
   | stats count
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-1h@h&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;condition match="$job.resultCount$==0$"&amp;gt;
        &amp;lt;set token="tokCount"&amp;gt;0&amp;lt;/set&amp;gt;
      &amp;lt;/condition&amp;gt;
      &amp;lt;condition&amp;gt;
        &amp;lt;set token="tokCount"&amp;gt;$result.count$&amp;lt;/set&amp;gt;
      &amp;lt;/condition&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Following condition, &lt;CODE&gt;$job.resultCount$==0&lt;/CODE&gt;, is used to default the token to 0 in case no results are found.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 20:22:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327295#M21210</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-21T20:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327296#M21211</link>
      <description>&lt;P&gt;Thanks for answering. I've just try that but I don't get the value but the search string:  index=chartlike qualify=Me | stats count -1h@h now 0 $result.count$ . I thought of javascript because I implemented some facebook like buttons to qualify the charts and I want to get back the count of those buttons to display it beside the icons, I've mixed xml with html to make it.&lt;/P&gt;

&lt;P&gt;this is my xml/html:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Blockquote&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;prueba&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel&amp;gt;
  &amp;lt;chart&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;sourcetype="csv"&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;option name="charting.chart"&amp;gt;line&amp;lt;/option&amp;gt;
    &amp;lt;option name="charting.drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
  &amp;lt;/chart&amp;gt;

    &amp;lt;html&amp;gt;
     &amp;lt;div&amp;gt;
          &amp;lt;!-- Boton de "me gusta" --&amp;gt;
          &amp;lt;a class="like_chart" title="Me gusta" id="like_app_chart1"&amp;gt;
            &amp;lt;i class="fa fa-2x fa-thumbs-o-up fa-lg"/&amp;gt;
          &amp;lt;/a&amp;gt;

        &amp;lt;search&amp;gt;
           &amp;lt;query&amp;gt;
             index=chartlike qualify=Me | stats count 
           &amp;lt;/query&amp;gt;
           &amp;lt;earliest&amp;gt;-1h@h&amp;lt;/earliest&amp;gt;
           &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
           &amp;lt;done&amp;gt;
             &amp;lt;condition match="$job.resultCount$==0$"&amp;gt;
               &amp;lt;set token="tokCount"&amp;gt;0&amp;lt;/set&amp;gt;
             &amp;lt;/condition&amp;gt;
             &amp;lt;condition&amp;gt;
               &amp;lt;set token="tokCount"&amp;gt;$result.count$&amp;lt;/set&amp;gt;
             &amp;lt;/condition&amp;gt;
           &amp;lt;/done&amp;gt;
         &amp;lt;/search&amp;gt;

          &amp;lt;!-- Boton de "no me gusta" --&amp;gt;
          &amp;lt;a class="like_chart" title="No me gusta" id="nolike_app_chart1"&amp;gt;
            &amp;lt;i class="fa fa-2x fa-thumbs-o-down fa-lg"/&amp;gt;
          &amp;lt;/a&amp;gt;

          &amp;lt;!-- boton de mostrar caja de comentarios --&amp;gt;
          &amp;lt;a class="comment" title="Comentar" id="comment_app_chart1"&amp;gt;
            &amp;lt;i class="fa fa-2x fa-comment-o fa-lg" aria-hidden="true"/&amp;gt;
          &amp;lt;/a&amp;gt;
          &amp;lt;!-- caja de comentarios --&amp;gt;
          &amp;lt;div class="comments" id="show_comment_chart1"&amp;gt;
          &amp;lt;div id="comment_chart1" contenteditable="true" placeholder="Comentario"/&amp;gt;
            &amp;lt;span id="error_app_chart1"&amp;gt;Máximo 140 caracteres&amp;amp;gt;&amp;lt;/span&amp;gt;
            &amp;amp;lt;br/&amp;amp;gt;
            &amp;lt;button type="button" class="comment_chart" id="send_comment_app_chart1"&amp;gt;Enviar&amp;lt;/button&amp;gt;
          &amp;lt;/div&amp;gt;

     &amp;lt;/div&amp;gt;
  &amp;lt;/html&amp;gt;
&amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Blockquote&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;P.D I would attach some screen captures but I don't have enough karma points.&lt;BR /&gt;
I've already try to insert a Splunk sigle value with the search result buy I can olny seem to put it into a new panel.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 22:05:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327296#M21211</guid>
      <dc:creator>jperezh</dc:creator>
      <dc:date>2017-07-21T22:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327297#M21212</link>
      <description>&lt;P&gt;@ jperezh, you have set the token in your search however, you have not displayed the same in either Splunk visualization or HTML panel. Based on your requirements &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Option 1&lt;/STRONG&gt; &lt;BR /&gt;
Seems like you are looking for Splunk Custom Visualization called Status Indicator which shows value icon and color based on data (&lt;A href="https://splunkbase.splunk.com/app/3119/"&gt;https://splunkbase.splunk.com/app/3119/&lt;/A&gt;) . &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Option 2&lt;/STRONG&gt;&lt;BR /&gt;
If you do not want to use Status Indicator and stick to HTML to apply CSS Style to show thumbs up or down based on value you can also check out &lt;STRONG&gt;Custom Decorations&lt;/STRONG&gt; examples in the &lt;STRONG&gt;Splunk 6.x Dashboard Examples App&lt;/STRONG&gt;. Or check out the following blog: &lt;A href="https://www.splunk.com/blog/2015/06/25/shiny-icons.html"&gt;https://www.splunk.com/blog/2015/06/25/shiny-icons.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 05:19:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327297#M21212</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-22T05:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327298#M21213</link>
      <description>&lt;P&gt;PS: The token $tokCount$ set through the search needs to be displayed with CSS Styling in your HTML Panel. Something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;
          index=chartlike qualify=Me | stats count 
        &amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;-1h@h&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;done&amp;gt;
          &amp;lt;condition match="$job.resultCount$==0$"&amp;gt;
            &amp;lt;set token="tokCount"&amp;gt;0&amp;lt;/set&amp;gt;
          &amp;lt;/condition&amp;gt;
          &amp;lt;condition&amp;gt;
            &amp;lt;set token="tokCount"&amp;gt;$result.count$&amp;lt;/set&amp;gt;
          &amp;lt;/condition&amp;gt;
        &amp;lt;/done&amp;gt;
      &amp;lt;/search&amp;gt;

&amp;lt;row&amp;gt;
  &amp;lt;panel&amp;gt;
     &amp;lt;chart&amp;gt;
         ....
         Your Chart Code Here
         ....
     &amp;lt;/chart&amp;gt;
     &amp;lt;html&amp;gt;
        &amp;lt;div&amp;gt;
           &amp;lt;!-- Boton de "me gusta" --&amp;gt;
           &amp;lt;a class="like_chart" title="Me gusta" id="like_app_chart1"&amp;gt;
             &amp;lt;i class="fa fa-2x fa-thumbs-o-up fa-lg"/&amp;gt;
           &amp;lt;/a&amp;gt;
           &amp;lt;div style="font-weight:bold;color:green"&amp;gt;$tokCount$&amp;lt;/div&amp;gt;
          ....
          ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: To understand Search Event Handler and Token refer to the following documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_handlers"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_handlers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 05:23:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327298#M21213</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-22T05:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327299#M21214</link>
      <description>&lt;P&gt;I suggest you download the &lt;CODE&gt;Splunk 6.x Dashboard Examples&lt;/CODE&gt; app and poke around in it; it has many examples of this kind of thing:&lt;BR /&gt;
&lt;A href="https://splunkbase.splunk.com/app/1603/"&gt;https://splunkbase.splunk.com/app/1603/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 18:59:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327299#M21214</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-22T18:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327300#M21215</link>
      <description>&lt;P&gt;Thank you very much, Indeed I was missing the way to display the token. Just another question, If I need 3 tokens, one for like, one for dislike and another for comments, can I put the 3 queries inside the same search tag or do I need to create one search tag for each query?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 12:56:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327300#M21215</guid>
      <dc:creator>jperezh</dc:creator>
      <dc:date>2017-07-24T12:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327301#M21216</link>
      <description>&lt;P&gt;@jperezh, as far as you can get the query to return results (or fields) in single row, you can access them all through &lt;CODE&gt;$result.&amp;lt;fieldName&amp;gt;$&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If you can provide your query for like, dislike and other with field name and sample data, we can help you further.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 14:11:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327301#M21216</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-24T14:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327302#M21217</link>
      <description>&lt;P&gt;My queries are: &lt;/P&gt;

&lt;P&gt;likes:&lt;BR /&gt;
index="chartlike" "qualify=me" | stats count  &lt;/P&gt;

&lt;P&gt;dislikes:&lt;BR /&gt;
index="chartlike" "qualify=no" | stats count  &lt;/P&gt;

&lt;P&gt;comments:&lt;BR /&gt;
index="chartlike" comments | stats count  &lt;/P&gt;

&lt;P&gt;The data is the result of a javascript code that makes an entry to the index whenever one of the buttons is clicked. That's already working. When I put those queries on the search bar I get the value I need but when i put them in the html code the value displayed is always 0.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:32:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327302#M21217</guid>
      <dc:creator>jperezh</dc:creator>
      <dc:date>2017-07-24T15:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: store search result to a javascript variable for dynamic displaying custom dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327303#M21218</link>
      <description>&lt;P&gt;UPDATE: I think the problem is that the query  doesn't have an all time specification, so it only displays the lastest of all.&lt;/P&gt;

&lt;P&gt;So I only modify this part of the xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;earliest&amp;gt;-1h@h&amp;lt;/earliest&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And that did it, its displaying the whole amount of likes and dislikes.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 18:33:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/store-search-result-to-a-javascript-variable-for-dynamic/m-p/327303#M21218</guid>
      <dc:creator>jperezh</dc:creator>
      <dc:date>2017-07-24T18:33:15Z</dc:date>
    </item>
  </channel>
</rss>

