<?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 can I retrieve a value from local .conf file and use it inside a python script lookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/641444#M222223</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/76281"&gt;@RiccardoV&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Is there any documentation on library "splunk.clilib" or on module "cli_common" ? Also, can you please let me know if there is any method to write contents to the config file that we are reading through command line ?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 14:06:05 GMT</pubDate>
    <dc:creator>Snehalg176</dc:creator>
    <dc:date>2023-04-26T14:06:05Z</dc:date>
    <item>
      <title>How can I retrieve a value from local .conf file and use it inside a python script lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/49242#M11787</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;

&lt;P&gt;I have a value inside a local personalized .conf file (&lt;STRONG&gt;/Splunk/etc/apps/$app/local&lt;/STRONG&gt;), ie:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[stanza-name]
value-name = value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I retrieve this value and use it inside a python lookup script (stored in &lt;STRONG&gt;/Splunk/etc/apps/$app/bin&lt;/STRONG&gt;)?&lt;/P&gt;

&lt;P&gt;thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2013 08:27:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/49242#M11787</guid>
      <dc:creator>RiccardoV</dc:creator>
      <dc:date>2013-08-28T08:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I retrieve a value from local .conf file and use it inside a python script lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/49243#M11788</link>
      <description>&lt;P&gt;I find the answer looking into the google-maps splunk plugin.&lt;BR /&gt;
I recycle and modify a little that function:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import os
import sys
from splunk.clilib import cli_common as cli

def getSelfConfStanza(stanza):
    appdir = os.path.dirname(os.path.dirname(__file__))
    apikeyconfpath = os.path.join(appdir, "default", "file.conf")
    apikeyconf = cli.readConfFile(apikeyconfpath)
    localconfpath = os.path.join(appdir, "local", "file.conf")
    if os.path.exists(localconfpath):
        localconf = cli.readConfFile(localconfpath)
        for name, content in localconf.items():
            if name in apikeyconf:
                apikeyconf[name].update(content)
            else:
                apikeyconf[name] = content
return apikeyconf[stanza]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now you can access your configuration:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stanza = getSelfConfStanza("yourStanzaName")
value = stanza['yourValueKey']
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2013 15:44:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/49243#M11788</guid>
      <dc:creator>RiccardoV</dc:creator>
      <dc:date>2013-08-28T15:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I retrieve a value from local .conf file and use it inside a python script lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/641444#M222223</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/76281"&gt;@RiccardoV&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Is there any documentation on library "splunk.clilib" or on module "cli_common" ? Also, can you please let me know if there is any method to write contents to the config file that we are reading through command line ?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 14:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/641444#M222223</guid>
      <dc:creator>Snehalg176</dc:creator>
      <dc:date>2023-04-26T14:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I retrieve a value from local .conf file and use it inside a python script lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/641449#M222224</link>
      <description>&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;&lt;I&gt;&lt;SPAN&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233910"&gt;@Snehalg176&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;I’m a Community Moderator in the Splunk Community. Thanks for contributing as a member in the forum!&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;I&gt;&lt;SPAN&gt;This question was posted 10 years ago and might not get the attention you need for your own question to be answered. I suggest you please post a brand new question so your issue can get more visibility. To increase your chances of getting help from the community, follow&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunkbase/splunkbase/Answers/Questions" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;I&gt;&lt;SPAN&gt;these guidelines&lt;/SPAN&gt;&lt;/I&gt;&lt;/A&gt;&lt;I&gt;&lt;SPAN&gt;&amp;nbsp;in the Splunk Answers User Manual when creating your post.&lt;/SPAN&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 14:32:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-retrieve-a-value-from-local-conf-file-and-use-it/m-p/641449#M222224</guid>
      <dc:creator>SanjayReddy</dc:creator>
      <dc:date>2023-04-26T14:32:23Z</dc:date>
    </item>
  </channel>
</rss>

