<?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: python script is being called twice. in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109057#M1624</link>
    <description>&lt;P&gt;I found that when I use dedup command before this command this is being called twice. Looks like dedup command is also non-streaming command (It's a guess). I read about &lt;CODE&gt;require_preop&lt;/CODE&gt; but still not sure how to use this. Do you have any idea how to use this property?&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2011 19:07:52 GMT</pubDate>
    <dc:creator>asingla</dc:creator>
    <dc:date>2011-11-15T19:07:52Z</dc:date>
    <item>
      <title>python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109054#M1621</link>
      <description>&lt;P&gt;I am writing my own search command and writing a python scripts for that. To start with, I am reading the results and writing to a log file. I see the same results are being logged twice. I also printed the os.getpid() and see that was different in both the calls.&lt;/P&gt;

&lt;P&gt;I turned the streaming = true in commands.conf, I still see the script is being called twice but this time results were empty in one of the calls.&lt;/P&gt;

&lt;P&gt;Please let me know what should I do to fix this problem?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;
import sys, os, gzip, csv, time, traceback
import splunk.Intersplunk

def logger(string):
           log.write(string + "\n")
           return 0

log = open(os.path.join(os.environ["SPLUNK_HOME"], 'var', 'log', 'splunk','my_results.log'), 'a')
results = splunk.Intersplunk.getOrganizedResults()
logger("called" + str(os.getpid()))
logger((str(results))
splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2011 23:13:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109054#M1621</guid>
      <dc:creator>asingla</dc:creator>
      <dc:date>2011-11-14T23:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109055#M1622</link>
      <description>&lt;P&gt;Setting &lt;CODE&gt;streaming&lt;/CODE&gt; to &lt;CODE&gt;false&lt;/CODE&gt; is the way to prevent the command script from being called multiple times. Additionally Splunk will call the script twice for each run if the option &lt;CODE&gt;supports_getinfo&lt;/CODE&gt; is enabled. You can either disable this option or check if the call is a GETINFO or EXECUTE call.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
if isgetinfo:
    splunk.Intersplunk.outputInfo(False, False, True, False, None)
else:
    # ... output to file
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2011 09:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109055#M1622</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2011-11-15T09:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109056#M1623</link>
      <description>&lt;P&gt;It is still being called twice. I was thinking the default values for &lt;CODE&gt;streaming&lt;/CODE&gt; and &lt;CODE&gt;supports_getinfo&lt;/CODE&gt; are false but anyway I set them to false explicitly in the commands.conf.&lt;BR /&gt;
When I set &lt;CODE&gt;supports_getinfo&lt;/CODE&gt; to true in commands.conf, the script is being called 4 times. &lt;BR /&gt;
This is how my commands.conf file looks like.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
[updatestate]&lt;BR /&gt;
filename = update_state.py&lt;BR /&gt;
supports_getinfo = false&lt;BR /&gt;
streaming = false&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;PS: I am &lt;STRONG&gt;not&lt;/STRONG&gt; running the real time search on this if that matters.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109056#M1623</guid>
      <dc:creator>asingla</dc:creator>
      <dc:date>2020-09-28T10:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109057#M1624</link>
      <description>&lt;P&gt;I found that when I use dedup command before this command this is being called twice. Looks like dedup command is also non-streaming command (It's a guess). I read about &lt;CODE&gt;require_preop&lt;/CODE&gt; but still not sure how to use this. Do you have any idea how to use this property?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2011 19:07:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109057#M1624</guid>
      <dc:creator>asingla</dc:creator>
      <dc:date>2011-11-15T19:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109058#M1625</link>
      <description>&lt;P&gt;Hi,
Is there a solution for this? I too am facing the same problem. I want to post the results via http, so use a custom command. But looks like the custom command is getting multiple times with EXECUTE (isgetinfo false). How do I prevent this? I want the custom command to be invoked only when the entire result set is available.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2012 03:49:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109058#M1625</guid>
      <dc:creator>mridus</dc:creator>
      <dc:date>2012-04-26T03:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109059#M1626</link>
      <description>&lt;P&gt;streaming = false should do the trick i think.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 16:11:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109059#M1626</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2015-10-09T16:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109060#M1627</link>
      <description>&lt;P&gt;It doesn't fix this. Am facing similar issue. &lt;/P&gt;

&lt;P&gt;If you want just the log file then the latest of the splunk calls will have all the search events, so write the log file in write mode instead of append mode. That ways data won't be duplicated and you will have all the events.&lt;/P&gt;

&lt;P&gt;My issue is I need to invoke a shell script on another host when my python script is called, so this issue will cause the remote script to be executed twice as well.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 22:27:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109060#M1627</guid>
      <dc:creator>behlkush</dc:creator>
      <dc:date>2016-03-22T22:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109061#M1628</link>
      <description>&lt;P&gt;Hi, if you want, have a look at TA-xls ( &lt;A href="https://splunkbase.splunk.com/app/1832/"&gt;https://splunkbase.splunk.com/app/1832/&lt;/A&gt; ) ... while the results are not complete splunk says something like preview: 1 in line 7 on stdout. i think the wrapper i have bolted together will help you some. &lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 15:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109061#M1628</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-03-23T15:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109062#M1629</link>
      <description>&lt;P&gt;Hm, if the results are taking a while you might get intermediate results. On stdout in line 7 there is "preview: 1" indicating the search has not yet completed.&lt;/P&gt;

&lt;P&gt;Something like&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;sys.stdin = codecs.getreader('utf-8')(sys.stdin)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Check if line 7 is "preview:1"&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;if str(row).strip('[\']') ==&lt;BR /&gt;
"preview:1": &lt;BR /&gt;
     exit()&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Does this help with your problem?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 15:32:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109062#M1629</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-03-23T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: python script is being called twice.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109063#M1630</link>
      <description>&lt;P&gt;Thank you @dominiquevocat. This fixed my problem, never realized the preview in the header, my code now has this (in case it helps anyone else) to prevent the script running twice:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stdin_wrapper = Reader(sys.stdin)
buf, settings = read_input(stdin_wrapper, has_header = True)
if settings['preview'] == '1' or settings['preview'] == 1:
   sys.exit()
events = csv.DictReader(buf)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:07:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/python-script-is-being-called-twice/m-p/109063#M1630</guid>
      <dc:creator>worshamn</dc:creator>
      <dc:date>2018-01-10T15:07:09Z</dc:date>
    </item>
  </channel>
</rss>

