<?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: Retrieve configuration items from a custom python search command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65754#M16322</link>
    <description>&lt;P&gt;Thanks ziegfried, clear now.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Aug 2019 15:03:00 GMT</pubDate>
    <dc:creator>highsplunker</dc:creator>
    <dc:date>2019-08-09T15:03:00Z</dc:date>
    <item>
      <title>Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65751#M16319</link>
      <description>&lt;P&gt;I would like to get configuration items from within a custom search python command.&lt;/P&gt;

&lt;P&gt;I have created a setup which adds configuration items "host", "port" and "key" for making external REST calls.&lt;/P&gt;

&lt;P&gt;The external REST calls are made via a custom search command.&lt;BR /&gt;
I would like to use the host, port and key stored in the configuration file to form the REST endpoint URL so that the Application can be installed without users having to change my python scripts.&lt;/P&gt;

&lt;P&gt;Tried reviewing the splunk.admin class but it isn't obvious to me how to get to the configuration properties to retrieve the data I want. (I wish I was better at python).&lt;/P&gt;

&lt;P&gt;I know I can make a REST call back to Splunk from within the search but making REST calls to Splunk itself to get the properties via /services/properties/myapp/myappitem seems a bit wrong.&lt;/P&gt;

&lt;P&gt;Has anyone else tried to make use of splunk.admin to retrieve stored configuration?&lt;BR /&gt;
Is there any way to achieve this?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 09:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65751#M16319</guid>
      <dc:creator>domgkc</dc:creator>
      <dc:date>2012-12-17T09:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65752#M16320</link>
      <description>&lt;P&gt;There are multiple ways to access config items from with custom search commands. The easiest one is to use the &lt;CODE&gt;splunk.clilib.cli_common&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;from splunk.clilib import cli_common as cli
...
cfg = cli.getConfStanza('myconf','mystanza')
print cfg.get('myitem')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The alternative is to actually access the configuration via REST. You can setup the search command to retrieve an auth token via STDIN when it's called by setting &lt;CODE&gt;passauth = true&lt;/CODE&gt; in commands.conf (&lt;CODE&gt;enableheader&lt;/CODE&gt; has to be set to true as well). &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.entity, splunk.Intersplunk
...
settings = dict()
records = splunk.Intersplunk.readResults(settings = settings, has_header = True)
...
entity = splunk.entity.getEntity('/admin/conf-myconf','mystanza', namespace='myapp', sessionKey=settings['sessionKey'], owner='nobody')
print entity.get('myitem')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Retrieving the config via REST is the cleaner way IMO. It additionally gives you control over app/user namespace when reading the configuration.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 11:48:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65752#M16320</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2012-12-17T11:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65753#M16321</link>
      <description>&lt;P&gt;Cheers ziegfried, nice. You rock!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 23:08:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65753#M16321</guid>
      <dc:creator>domgkc</dc:creator>
      <dc:date>2012-12-17T23:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65754#M16322</link>
      <description>&lt;P&gt;Thanks ziegfried, clear now.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:03:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65754#M16322</guid>
      <dc:creator>highsplunker</dc:creator>
      <dc:date>2019-08-09T15:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65755#M16323</link>
      <description>&lt;P&gt;Hi ziegfried, thanks for the input. How do I use the &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cli.getConfStanza('myconf','mystanza')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to get the version of my custom Add-On TA?&lt;/P&gt;

&lt;P&gt;I tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cli.getMergedConf("app")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this gives me the version of another app installed on my setup. How do I mention my TA's app.conf folder?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 08:22:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65755#M16323</guid>
      <dc:creator>pbankar</dc:creator>
      <dc:date>2019-11-15T08:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve configuration items from a custom python search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65756#M16324</link>
      <description>&lt;P&gt;When using the add-on builder this code works for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def process_event(helper, *args, **kwargs):
    service = client.Service(
            token=helper.settings.get('session_key'), 
            owner='nobody',
            app='SplunkEnterpriseSecuritySuite')
    myitem = service.confs["myconf"]["mystanza"]["myitem"]
    helper.log_info("myitem={}".format(myitem))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jan 2020 12:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Retrieve-configuration-items-from-a-custom-python-search-command/m-p/65756#M16324</guid>
      <dc:creator>peter_krammer</dc:creator>
      <dc:date>2020-01-15T12:15:23Z</dc:date>
    </item>
  </channel>
</rss>

