<?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 you get a config from a scripted input? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103670#M21810</link>
    <description>&lt;P&gt;I settled on the cli config lib (for the same purpose -- scripted inputs).  No idea what the best practice is here, but I find this one to be &lt;EM&gt;very&lt;/EM&gt; easy to use.  I had a hard time understanding how to use readConf() myself... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.clilib.cli_common 

config = splunk.clilib.cli_common.getMergedConf('myconfig')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This just returns a normal python dict, so do whatever you want now.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2010 12:03:53 GMT</pubDate>
    <dc:creator>mw</dc:creator>
    <dc:date>2010-12-13T12:03:53Z</dc:date>
    <item>
      <title>How do you get a config from a scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103668#M21808</link>
      <description>&lt;P&gt;Digging around in the splunk python docs (via help(splunk...), splunk.bundle.getConf seems to be the best way to read a config, at least from a command. Unfortunately, it wants a sessionKey, which I'm not aware of existing when you're running from a scripted input.
   getConf(confName, sessionKey=None, namespace=None, owner=None, overwriteStanzas=False, hostPath=None)&lt;/P&gt;

&lt;P&gt;I'm getting this error:
 splunk.AuthenticationFailed: [HTTP 401] Client is not authenticated; None&lt;/P&gt;

&lt;P&gt;So, questions...
Is there a sessionKey around when running a scripted input?
Is there some other module for merging configs?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2010 07:24:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103668#M21808</guid>
      <dc:creator>vbumgarn</dc:creator>
      <dc:date>2010-12-11T07:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do you get a config from a scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103669#M21809</link>
      <description>&lt;P&gt;I figured this one out with a little help, so I thought I'd post the answer for all to see.&lt;/P&gt;

&lt;P&gt;Two things are required.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;In inputs.conf, enable passAuth in your scripted input stanza. I used passAuth = admin. This will send a token for that user to STDIN of your script.&lt;/LI&gt;
&lt;LI&gt;Read that STDIN and use it in the call to getConf. Match the user in the getConf call.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Code snippet:

    def main():
        #get the auth token
        sessionKey = sys.stdin.readline()
        #extract the APP name to use for namespace. 
        #Maybe there's a better way then getting it from the script path?
        namespace = re.findall('.*\/[\/]bin',sys.path[0])[0]&lt;/P&gt;
        conf = bundle.getConf('foo', sessionKey=sessionKey, namespace=namespace, owner='admin')
        value1 = conf['stanza']['value1']
        value2 = conf['stanza']['value2']

&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2010 07:33:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103669#M21809</guid>
      <dc:creator>vbumgarn</dc:creator>
      <dc:date>2010-12-11T07:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you get a config from a scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103670#M21810</link>
      <description>&lt;P&gt;I settled on the cli config lib (for the same purpose -- scripted inputs).  No idea what the best practice is here, but I find this one to be &lt;EM&gt;very&lt;/EM&gt; easy to use.  I had a hard time understanding how to use readConf() myself... &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.clilib.cli_common 

config = splunk.clilib.cli_common.getMergedConf('myconfig')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This just returns a normal python dict, so do whatever you want now.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2010 12:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-get-a-config-from-a-scripted-input/m-p/103670#M21810</guid>
      <dc:creator>mw</dc:creator>
      <dc:date>2010-12-13T12:03:53Z</dc:date>
    </item>
  </channel>
</rss>

