<?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 pulling Splunk Rest API in a python script in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/pulling-Splunk-Rest-API-in-a-python-script/m-p/381179#M6327</link>
    <description>&lt;P&gt;I would like to pull the Splunk REST API jobs/$someSEARCH owner and use it as a variable in a python script&lt;BR /&gt;
here is what I ahve so fare&lt;/P&gt;

&lt;P&gt;def getAuthor(argvals, settings):&lt;BR /&gt;
        try:&lt;BR /&gt;
                namespace  = settings.get("namespace", None)&lt;BR /&gt;
                sessionKey = settings['sessionKey']&lt;BR /&gt;
                ent = entity.getEntity('jobs', '| script python git', namespace=namespace, owner='nobody', sessionKey=sessionKey)&lt;BR /&gt;
                argvals ['author'] = ent['owner']&lt;BR /&gt;
        except Exception, e:&lt;BR /&gt;
                logger.error("Could not get the owner of the job. Error: %s" %(str(e)))&lt;BR /&gt;
        raise&lt;/P&gt;

&lt;P&gt;logger.basicConfig(format='%(asctime)s %(levelname)s %(message)s', filename=os.path.join(os.environ['SPLUNK_HOME'],'var','log','splunk','git.log'), filemode='a+', level=logger.INFO)&lt;/P&gt;

&lt;P&gt;keywords, argvals  = splunk.Intersplunk.getKeywordsAndOptions()&lt;/P&gt;

&lt;P&gt;em_message_fromArg = getarg(argvals, "message", "Commiting a with no message, please ask the owner about the change")&lt;/P&gt;

&lt;P&gt;settings = splunk.Intersplunk.getOrganizedResults()&lt;/P&gt;

&lt;P&gt;getAuthor(argvals, settings)&lt;/P&gt;

&lt;P&gt;with open('/opt/splunk/etc/apps/incident_response/bin/test.txt', 'a') as file:&lt;BR /&gt;
        file.write(author)&lt;BR /&gt;
What else could  I do?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 20:41:52 GMT</pubDate>
    <dc:creator>jmcclure8</dc:creator>
    <dc:date>2020-09-29T20:41:52Z</dc:date>
    <item>
      <title>pulling Splunk Rest API in a python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/pulling-Splunk-Rest-API-in-a-python-script/m-p/381179#M6327</link>
      <description>&lt;P&gt;I would like to pull the Splunk REST API jobs/$someSEARCH owner and use it as a variable in a python script&lt;BR /&gt;
here is what I ahve so fare&lt;/P&gt;

&lt;P&gt;def getAuthor(argvals, settings):&lt;BR /&gt;
        try:&lt;BR /&gt;
                namespace  = settings.get("namespace", None)&lt;BR /&gt;
                sessionKey = settings['sessionKey']&lt;BR /&gt;
                ent = entity.getEntity('jobs', '| script python git', namespace=namespace, owner='nobody', sessionKey=sessionKey)&lt;BR /&gt;
                argvals ['author'] = ent['owner']&lt;BR /&gt;
        except Exception, e:&lt;BR /&gt;
                logger.error("Could not get the owner of the job. Error: %s" %(str(e)))&lt;BR /&gt;
        raise&lt;/P&gt;

&lt;P&gt;logger.basicConfig(format='%(asctime)s %(levelname)s %(message)s', filename=os.path.join(os.environ['SPLUNK_HOME'],'var','log','splunk','git.log'), filemode='a+', level=logger.INFO)&lt;/P&gt;

&lt;P&gt;keywords, argvals  = splunk.Intersplunk.getKeywordsAndOptions()&lt;/P&gt;

&lt;P&gt;em_message_fromArg = getarg(argvals, "message", "Commiting a with no message, please ask the owner about the change")&lt;/P&gt;

&lt;P&gt;settings = splunk.Intersplunk.getOrganizedResults()&lt;/P&gt;

&lt;P&gt;getAuthor(argvals, settings)&lt;/P&gt;

&lt;P&gt;with open('/opt/splunk/etc/apps/incident_response/bin/test.txt', 'a') as file:&lt;BR /&gt;
        file.write(author)&lt;BR /&gt;
What else could  I do?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:41:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/pulling-Splunk-Rest-API-in-a-python-script/m-p/381179#M6327</guid>
      <dc:creator>jmcclure8</dc:creator>
      <dc:date>2020-09-29T20:41:52Z</dc:date>
    </item>
  </channel>
</rss>

