<?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: creating splunk search in python script in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305088#M3996</link>
    <description>&lt;P&gt;script is working. when I run it separately, but when i include this in the script its not working.&lt;/P&gt;

&lt;P&gt;what i have observed so far:&lt;BR /&gt;
I have created two python files 1. adaptive response which will take the payload from notable event and create ticket in HPSM. 2. while updating the ticket the ticket I need to get event_id by running search against notable with filter orig_sid. &lt;BR /&gt;
I am calling 2nd script from first script main function. and the second script is being called with the orig_id parameter and giving job_id in logging but not giving results. this is where I got stuck up.&lt;/P&gt;

&lt;P&gt;if I run second script alone by passing static values its working fine.&lt;/P&gt;

&lt;P&gt;please let me know your experiences if you guys have already  seen this before.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 17:02:52 GMT</pubDate>
    <dc:creator>thambisetty</dc:creator>
    <dc:date>2020-09-29T17:02:52Z</dc:date>
    <item>
      <title>creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305083#M3991</link>
      <description>&lt;P&gt;Hi Splunk,&lt;/P&gt;

&lt;P&gt;I am trying to create splunk search in my python script where the script is being used to create HPSM ticket.&lt;/P&gt;

&lt;P&gt;I have created HPSM action and added to correlation search adaptive response action and this executes python script and I need to find event_id for orig_sid (sid from splunk statndard input) before creating ticket and need to add event_id in request to create HPSM ticket. using this I have created method in the same script to run search to get event id for the same sid. search is returning void. if I run method in different python script its working fine.&lt;/P&gt;

&lt;P&gt;Here is my method which will create search in splunk(used both create and export)&lt;/P&gt;

&lt;P&gt;def run_search(sid):&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.debug("Entered with sid '%s'",sid)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #sid='scheduler_&lt;EM&gt;s785863&lt;/EM&gt;&lt;EM&gt;SplunkEnterpriseSecuritySuite&lt;/EM&gt;_RMD53eff93817270d051_at_1511794860_96'&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sid=sid&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #kwargs_export = {"earliest_time": "-24h","latest_time": "now","search_mode": "normal","output_mode":"json"}&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; searchquery_export = "search `notable`| search orig_sid=" + sid + " | table event_id"&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.debug("Search Query '%s'",searchquery_export)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; service = client.connect(username="splunk", password="*******&lt;STRONG&gt;*")&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.debug("Service connect %s",service)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #time.sleep(60)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #exportsearch_results = service.jobs.export(searchquery_export, **kwargs_export)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; job = service.jobs.create(searchquery_export,&lt;/STRONG&gt;{"exec_mode": "blocking"})&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.debug("Inner job SID '%s'", job)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result_stream = job.results()&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reader = results.ResultsReader(result_stream)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for item in reader:&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; logger.debug("Inner job Results '%s'", item)&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #query_results = exportsearch_results.read()&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #logger.debug("Notable Result '%s'", query_results )&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #return query_results&lt;BR /&gt;
If I use static sid , its working .&lt;/P&gt;

&lt;P&gt;Please help me out.&lt;BR /&gt;
Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:57:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305083#M3991</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2020-09-29T16:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305084#M3992</link>
      <description>&lt;P&gt;Try surrounding sid with  quotes&lt;BR /&gt;
i.e&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchquery_export = "search `notable`| search orig_sid=\"" + sid + "\" | table event_id"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I use searchAll/searchOne method of Splunk for executing  search from python script which is easier compare to creating job. Sharing it for your reference. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.search as splunkSearch

labels = splunkSearch.searchAll('| inputlookup abc_workload_mapping_lookup | search workload_d="%s" hostname = "*" | dedup type | table href type' % workload_uuid, sessionKey=session_key, namespace=app_name, owner='nobody')
    labelsList = []
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 06:43:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305084#M3992</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-11-28T06:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305085#M3993</link>
      <description>&lt;P&gt;Thanks for your answer.&lt;/P&gt;

&lt;P&gt;How did you get the session key?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 07:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305085#M3993</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2017-11-28T07:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305086#M3994</link>
      <description>&lt;P&gt;If it's python script, you need to set "passAuth" varriable in inputs.conf.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;passAuth = splunk-system-user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk will pass session key as argument to your python script which can be accessed with following line. &lt;/P&gt;

&lt;P&gt;sessionKey = sys.stdin.readline().strip()&lt;/P&gt;

&lt;P&gt;In case it's AR action,  you can access it from modaction.session_key.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 08:51:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305086#M3994</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-11-28T08:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305087#M3995</link>
      <description>&lt;P&gt;@thambisetty did you resolve your problem?  It will be helpful for all if you can provide your solution here .&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 10:03:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305087#M3995</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-12-01T10:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: creating splunk search in python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305088#M3996</link>
      <description>&lt;P&gt;script is working. when I run it separately, but when i include this in the script its not working.&lt;/P&gt;

&lt;P&gt;what i have observed so far:&lt;BR /&gt;
I have created two python files 1. adaptive response which will take the payload from notable event and create ticket in HPSM. 2. while updating the ticket the ticket I need to get event_id by running search against notable with filter orig_sid. &lt;BR /&gt;
I am calling 2nd script from first script main function. and the second script is being called with the orig_id parameter and giving job_id in logging but not giving results. this is where I got stuck up.&lt;/P&gt;

&lt;P&gt;if I run second script alone by passing static values its working fine.&lt;/P&gt;

&lt;P&gt;please let me know your experiences if you guys have already  seen this before.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:02:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/creating-splunk-search-in-python-script/m-p/305088#M3996</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2020-09-29T17:02:52Z</dc:date>
    </item>
  </channel>
</rss>

