<?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: How to insert splunk spl search in a javascript in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294088#M18680</link>
    <description>&lt;P&gt;Hi @edoardo_vicendone,&lt;BR /&gt;
Can You Please try this javascript ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/simplexml/ready!"
], function(SearchManager) {

    // Create managers
    new SearchManager({
        id: "example-search",
        earliest_time: "-24h@h",
        latest_time: "now",
        preview: true,
        cache: false,
        search: "index=_internal | stats count by sourcetype" 
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is another example for iterating result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require(['jquery', 'splunkjs/mvc/simplexml/ready!'], function ($) {
    $(document).ready(function () {
        var SearchManager = require('splunkjs/mvc/searchmanager');

        var searchString = 'index=_internal | stats count'

        var mySearchManager = new SearchManager({
                id : "cacheSearch",
                earliest_time : "-24h",
                latest_time : "now",
                autostart : true,
                search : searchString,
                preview : true,
                cache : false
            });

        var myResults = mySearchManager.data("results"); // get the data from that search
        myResults.on("data", function () {
            resultArray = myResults.data().rows;
            $.each(resultArray, function (index, value) {
                console.log(value);
            });
        });
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For more information check SearchManager in this link.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/"&gt;http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 17:40:16 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2018-03-27T17:40:16Z</dc:date>
    <item>
      <title>How to insert splunk spl search in a javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294087#M18679</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;We would like to know if it is possible to embed a splunk spl search into a javascript.&lt;BR /&gt;
If yes can you please provide some example?&lt;/P&gt;

&lt;P&gt;Thanks a lot,&lt;BR /&gt;
Edoardo&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 16:45:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294087#M18679</guid>
      <dc:creator>edoardo_vicendo</dc:creator>
      <dc:date>2018-03-27T16:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert splunk spl search in a javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294088#M18680</link>
      <description>&lt;P&gt;Hi @edoardo_vicendone,&lt;BR /&gt;
Can You Please try this javascript ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/simplexml/ready!"
], function(SearchManager) {

    // Create managers
    new SearchManager({
        id: "example-search",
        earliest_time: "-24h@h",
        latest_time: "now",
        preview: true,
        cache: false,
        search: "index=_internal | stats count by sourcetype" 
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is another example for iterating result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require(['jquery', 'splunkjs/mvc/simplexml/ready!'], function ($) {
    $(document).ready(function () {
        var SearchManager = require('splunkjs/mvc/searchmanager');

        var searchString = 'index=_internal | stats count'

        var mySearchManager = new SearchManager({
                id : "cacheSearch",
                earliest_time : "-24h",
                latest_time : "now",
                autostart : true,
                search : searchString,
                preview : true,
                cache : false
            });

        var myResults = mySearchManager.data("results"); // get the data from that search
        myResults.on("data", function () {
            resultArray = myResults.data().rows;
            $.each(resultArray, function (index, value) {
                console.log(value);
            });
        });
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For more information check SearchManager in this link.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/"&gt;http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 17:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294088#M18680</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-03-27T17:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert splunk spl search in a javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294089#M18681</link>
      <description>&lt;P&gt;Hi @kamlesh_vaghela,&lt;/P&gt;

&lt;P&gt;Really thanks, this will help us a lot.&lt;BR /&gt;
We are currently facing some challange to set-up read only users in Splunk, that do not have access to any Search view, Alerts view, Datasets view etc... and for example only have access to dashboards.&lt;/P&gt;

&lt;P&gt;Our idea is to load a javascript in each dashboard that search in a lookup table we have previously parameterized. In that lookup table we have defined user/roles and which view they can see.  So based on the result of the search if that specific user/role cannot see the views we will then enable hideAppBar="true" hideFooter="true" etc..&lt;/P&gt;

&lt;P&gt;I'll keep you posted.&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;BR /&gt;
Edoardo&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 09:50:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294089#M18681</guid>
      <dc:creator>edoardo_vicendo</dc:creator>
      <dc:date>2018-03-28T09:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert splunk spl search in a javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294090#M18682</link>
      <description>&lt;P&gt;Hi @edoardo_vicendone,&lt;BR /&gt;
Thanks for explaining your requirement. Kindly let me know if any help required in any case.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 17:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294090#M18682</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-03-28T17:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert splunk spl search in a javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294091#M18683</link>
      <description>&lt;P&gt;Hi @kamlesh_vaghela,&lt;/P&gt;

&lt;P&gt;The script is mostly completed, but we have still one issue.&lt;BR /&gt;
We are trying to get the "value" out of the function so that we can then pass them to the dashboard but we are still unable to get it.&lt;/P&gt;

&lt;P&gt;We tried to search on internet and also tried several solutions but until now without success.&lt;BR /&gt;
Do you know how to get the results stored in the value variable out from the function in order to let them being directly accessable in the javascript?&lt;/P&gt;

&lt;P&gt;Thanks a lot,&lt;BR /&gt;
Edoardo&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 10:45:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-insert-splunk-spl-search-in-a-javascript/m-p/294091#M18683</guid>
      <dc:creator>edoardo_vicendo</dc:creator>
      <dc:date>2018-04-04T10:45:32Z</dc:date>
    </item>
  </channel>
</rss>

