<?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: Help with custom search command (wait) needed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437338#M124537</link>
    <description>&lt;P&gt;Hello David,&lt;/P&gt;

&lt;P&gt;sorry, it took a while because we had some issues with our python 2.7 installation, where we were not able to get the splunk-sdk running so we had to workaround it pointing to the python 3.5.&lt;BR /&gt;
The code for waiting command is quite simple, googled and assembled from Splunk examples :-). &lt;BR /&gt;
Please see below.&lt;/P&gt;

&lt;P&gt;Kind Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append("/usr/local/lib/python3.5/site-packages/splunk_sdk-1.6.6-py2.7.egg")
import time
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration

@Configuration()
class MyCommand(StreamingCommand):
        def stream(self,records):
                time.sleep(60)
                for record in records:
                        yield record

if __name__ == "__main__":
        dispatch(MyCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Aug 2019 06:36:18 GMT</pubDate>
    <dc:creator>damucka</dc:creator>
    <dc:date>2019-08-14T06:36:18Z</dc:date>
    <item>
      <title>Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437333#M124532</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I need to apply 60 sec delay between two SPL commands, which start and collect the DB trace per dbxquery. &lt;BR /&gt;
In between, there should be 60 sec time. As I did not find anything corresponding, I wrote the simplest possible .py script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import time
time.sleep(60)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and call it like | sleep60. It waits 60 sec, but then throws an error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;08-09-2019 15:05:56.331 INFO  UserManager - Unwound user context: d038423 -&amp;gt; NULL
08-09-2019 15:05:56.332 INFO  PipelineComponent - Process delayed by 59.062 seconds, perhaps system was suspended?
08-09-2019 15:05:56.332 ERROR dispatchRunner - RunDispatch::runDispatchThread threw error: Error in 'sleep60' command: External search command exited unexpectedly.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I am thinking that the .py will not be as easy as that perhaps. Of course I expect that all the variables from before the command execution will still be visible, etc.&lt;BR /&gt;
Any idea why I get this error and how a simple delay script should look like?&lt;/P&gt;

&lt;P&gt;Kind Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 13:12:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437333#M124532</guid>
      <dc:creator>damucka</dc:creator>
      <dc:date>2019-08-09T13:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437334#M124533</link>
      <description>&lt;P&gt;Hi @damucka, &lt;/P&gt;

&lt;P&gt;You're always doing cool stuff! &lt;/P&gt;

&lt;P&gt;Try making the .py append a column to the results saying "60 seconds ok" That would make your debugging way easier.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 14:59:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437334#M124533</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-09T14:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437335#M124534</link>
      <description>&lt;P&gt;Any updates Kamil ?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Aug 2019 07:35:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437335#M124534</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-10T07:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437336#M124535</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;

&lt;P&gt;If you mean that in my python code I should do sth to append the result, then I am afraid I would ask for help with this. I mean I can start googling, but you would know for sure how this should go. You can see on the above example of my .py how simple it is and if I now have to import pip splunk-sdk, use the input / output classes to produce the result in python ... I am not sure if I want to begin with this unless it is absolutely necessary.&lt;BR /&gt;
Or you would just tell me how the code should look like :-).&lt;BR /&gt;
Unless you mean the appendcols in SPL, from where my sleep60 is called, but this I would not know how it should help here either.&lt;BR /&gt;
Sorry for my ignorance.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;</description>
      <pubDate>Sat, 10 Aug 2019 14:30:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437336#M124535</guid>
      <dc:creator>damucka</dc:creator>
      <dc:date>2019-08-10T14:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437337#M124536</link>
      <description>&lt;P&gt;Hey Kamil,&lt;/P&gt;

&lt;P&gt;Have a look here :&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Search/Customsearchcommandshape"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Search/Customsearchcommandshape&lt;/A&gt;&lt;BR /&gt;
It's a good example that shows you how a custom command takes and input and applies a logic to it. &lt;/P&gt;

&lt;P&gt;In your case your logic should be :&lt;BR /&gt;
1-Data goes in.&lt;BR /&gt;
2-Wait 60 seconds.&lt;BR /&gt;
3-output the same data (+ comment to indicate wait is complete--- optional).&lt;BR /&gt;
In your case above in the question your output gives nothing, hence the error. &lt;/P&gt;</description>
      <pubDate>Sat, 10 Aug 2019 16:10:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437337#M124536</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-10T16:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437338#M124537</link>
      <description>&lt;P&gt;Hello David,&lt;/P&gt;

&lt;P&gt;sorry, it took a while because we had some issues with our python 2.7 installation, where we were not able to get the splunk-sdk running so we had to workaround it pointing to the python 3.5.&lt;BR /&gt;
The code for waiting command is quite simple, googled and assembled from Splunk examples :-). &lt;BR /&gt;
Please see below.&lt;/P&gt;

&lt;P&gt;Kind Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append("/usr/local/lib/python3.5/site-packages/splunk_sdk-1.6.6-py2.7.egg")
import time
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration

@Configuration()
class MyCommand(StreamingCommand):
        def stream(self,records):
                time.sleep(60)
                for record in records:
                        yield record

if __name__ == "__main__":
        dispatch(MyCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Aug 2019 06:36:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437338#M124537</guid>
      <dc:creator>damucka</dc:creator>
      <dc:date>2019-08-14T06:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437339#M124538</link>
      <description>&lt;P&gt;Awesome ! Great work Kamil &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 06:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437339#M124538</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-14T06:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with custom search command (wait) needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437340#M124539</link>
      <description>&lt;P&gt;PS: Please accept the answer to close this post.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 06:52:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-custom-search-command-wait-needed/m-p/437340#M124539</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-14T06:52:30Z</dc:date>
    </item>
  </channel>
</rss>

