<?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 do I dynamically update the parameters of a Python modular input? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262954#M3286</link>
    <description>&lt;P&gt;Yes, right now I'm using the api.cloudflare.com to index logs based on a range of times (grab last 5 minutes of data) and save into a json file that Splunk indexes.  This has become unreliable.&lt;/P&gt;

&lt;P&gt;Is your code leveraging the Python CloudFlare API modules?&lt;/P&gt;</description>
    <pubDate>Thu, 20 Oct 2016 20:35:47 GMT</pubDate>
    <dc:creator>cyndiback</dc:creator>
    <dc:date>2016-10-20T20:35:47Z</dc:date>
    <item>
      <title>How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262949#M3281</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I've got a Python modular input script that needs to persist a variable between runs. I'm trying to use the &lt;CODE&gt;update&lt;/CODE&gt; method of the input to change this variable from my &lt;CODE&gt;stream_events&lt;/CODE&gt; function, but the documentation is unclear as to how I should do this. I know it's possible using the Java SDK as demonstrated by the Carvoyant modular input, but I don't see any examples in Python.&lt;/P&gt;

&lt;P&gt;Here's what my code looks like now (doesn't throw any errors but also doesn't update the input).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class CloudflareInput(Script):
    def get_scheme(self):
        scheme = Scheme('Cloudflare Log Modular Input')
        scheme.description = 'Grab log events from a Cloudflare log server.'

        last_fetch_filename = Argument('last_log')
        last_fetch_filename.description = ("Name of the last file fetched "
                                           "from the server. Leave blank to "
                                           "fetch all available logs. This "
                                           "value will be updated "
                                           "automatically by the script as "
                                           "it runs so that we don't fetch "
                                           "duplicate logs.")
        last_fetch_filename.data_type = Argument.data_type_string
        last_fetch_filename.required_on_create = False
        last_fetch_filename.required_on_edit = False
        scheme.add_argument(last_fetch_filename)

        return scheme

    def stream_events(self, inputs, ew):
        for input_name, input_item in inputs.inputs.iteritems():
            input_item.update({'last_log': str(datetime.now())})

if __name__ == "__main__":
    sys.exit(CloudflareInput().run(sys.argv))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I make this update my input? Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 18:19:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262949#M3281</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2015-12-04T18:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262950#M3282</link>
      <description>&lt;P&gt;OK, I've discovered you have to call update on one of the service's inputs, not on a member of the inputs list passed to the stream_events function. So this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class CloudflareInput(Script):
    def get_scheme(self):
        scheme = Scheme('Cloudflare Log Modular Input')
        scheme.description = 'Grab log events from a Cloudflare log server.'

        last_fetch_filename = Argument('last_log')
        last_fetch_filename.description = ("Name of the last file fetched "
                                           "from the server. Leave blank to "
                                           "fetch all available logs. This "
                                           "value will be updated "
                                           "automatically by the script as "
                                           "it runs so that we don't fetch "
                                           "duplicate logs.")
        last_fetch_filename.data_type = Argument.data_type_string
        last_fetch_filename.required_on_create = False
        last_fetch_filename.required_on_edit = False
        scheme.add_argument(last_fetch_filename)

        return scheme

    def stream_events(self, inputs, ew):
        serv_inputs = self.service.inputs
        for input_item in serv_inputs:
            if ("cloudflare://"+input_item.name) in inputs.inputs:
                input_item.update(last_log=str(datetime.now()))

if __name__ == "__main__":
    sys.exit(CloudflareInput().run(sys.argv))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, calling "update" makes the modular input run again immediately, regardless of the time interval specified. Is there a way around this?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 20:45:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262950#M3282</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2015-12-04T20:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262951#M3283</link>
      <description>&lt;P&gt;Were you able to successfully bring in CloudFlare logs?&lt;/P&gt;</description>
      <pubDate>Sun, 16 Oct 2016 23:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262951#M3283</guid>
      <dc:creator>cyndiback</dc:creator>
      <dc:date>2016-10-16T23:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262952#M3284</link>
      <description>&lt;P&gt;Yes, we were. Are you facing a similar issue?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 23:53:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262952#M3284</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-10-17T23:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262953#M3285</link>
      <description>&lt;P&gt;So I recently wrote a modular input that needed to record its status between runs.&lt;BR /&gt;
The way I tackled it was to work out the checkpoint directory then create a file in that directory to store its current status (in stream_events)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;checkpoint_directory = str(self._input_definition.metadata['checkpoint_dir']) 
timestamp_progress_file = os.path.join(checkpoint_directory, self.stanza + '_last_timestamp.txt')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This file is then read/updated like any other file accessed through Python.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 18:56:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262953#M3285</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2016-10-18T18:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262954#M3286</link>
      <description>&lt;P&gt;Yes, right now I'm using the api.cloudflare.com to index logs based on a range of times (grab last 5 minutes of data) and save into a json file that Splunk indexes.  This has become unreliable.&lt;/P&gt;

&lt;P&gt;Is your code leveraging the Python CloudFlare API modules?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 20:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262954#M3286</guid>
      <dc:creator>cyndiback</dc:creator>
      <dc:date>2016-10-20T20:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically update the parameters of a Python modular input?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262955#M3287</link>
      <description>&lt;P&gt;We don't use the API to get our logs. We retrieve them via SFTP (using Paramiko) from logs.cloudflare.com.&lt;/P&gt;

&lt;P&gt;I'm guessing this process depends on the service plan you have with CloudFlare, but I don't really know.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 13:27:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-dynamically-update-the-parameters-of-a-Python-modular/m-p/262955#M3287</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-10-21T13:27:55Z</dc:date>
    </item>
  </channel>
</rss>

