<?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: If I have a python variable with some value, how do I pass that value to a Splunk search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189476#M54586</link>
    <description>&lt;P&gt;That's essentially correct, but, of course, the parameters must be identified in the format statement. Here is part of a search that I use in python. The parameters are passed witht he URL and inserted into the search. Just remember to escape your quotes. &lt;/P&gt;

&lt;P&gt;Passed parameters&lt;BR /&gt;
mac="002220030180"&lt;BR /&gt;
cName="LOC3652"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;service.login()
kwargs_normalsearch = {"exec_mode": "blocking"}
jobs = service.job

    job = jobs.create("
    | inputlookup Client_Info.csv 
    | search mac_addr=\"{0}\"
    | eval Client=\"{1}\" 
    | dedup Date 
    | eval Hours=MBs/MBHR
    | rename MBHR as MBs/HR...".format(mac, cName)  , **kwargs_normalsearch)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Mar 2015 15:02:01 GMT</pubDate>
    <dc:creator>kmattern</dc:creator>
    <dc:date>2015-03-19T15:02:01Z</dc:date>
    <item>
      <title>If I have a python variable with some value, how do I pass that value to a Splunk search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189474#M54584</link>
      <description>&lt;P&gt;I am new to Splunk so just want to know that if I have a python variable with some value, can I pass that value in a search query?&lt;BR /&gt;
If it is possible, how do I pass this python variable in a search?&lt;BR /&gt;
I am writing code in python using splunk-sdk for python.&lt;BR /&gt;
My requirement is something like this:&lt;/P&gt;

&lt;P&gt;application="Application Control"&lt;BR /&gt;
searchquery_export = ' search sourcetype=opsec  product=application | top src_ip '&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:15:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189474#M54584</guid>
      <dc:creator>ektasiwani</dc:creator>
      <dc:date>2020-09-28T19:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: If I have a python variable with some value, how do I pass that value to a Splunk search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189475#M54585</link>
      <description>&lt;P&gt;I'm new to Python, but I think something like this should do the job.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchquery_export = ' search sourcetype=opsec product={} | top src_ip '.format(application)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2015 14:17:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189475#M54585</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-03-19T14:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: If I have a python variable with some value, how do I pass that value to a Splunk search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189476#M54586</link>
      <description>&lt;P&gt;That's essentially correct, but, of course, the parameters must be identified in the format statement. Here is part of a search that I use in python. The parameters are passed witht he URL and inserted into the search. Just remember to escape your quotes. &lt;/P&gt;

&lt;P&gt;Passed parameters&lt;BR /&gt;
mac="002220030180"&lt;BR /&gt;
cName="LOC3652"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;service.login()
kwargs_normalsearch = {"exec_mode": "blocking"}
jobs = service.job

    job = jobs.create("
    | inputlookup Client_Info.csv 
    | search mac_addr=\"{0}\"
    | eval Client=\"{1}\" 
    | dedup Date 
    | eval Hours=MBs/MBHR
    | rename MBHR as MBs/HR...".format(mac, cName)  , **kwargs_normalsearch)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2015 15:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189476#M54586</guid>
      <dc:creator>kmattern</dc:creator>
      <dc:date>2015-03-19T15:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: If I have a python variable with some value, how do I pass that value to a Splunk search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189477#M54587</link>
      <description>&lt;P&gt;thank you very much guys for replying.&lt;BR /&gt;
This solution is working fine for me.&lt;/P&gt;

&lt;P&gt;'search sourcetype=opsec product=\"{0}\" | top src_ip '.format(application)&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 05:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-I-have-a-python-variable-with-some-value-how-do-I-pass-that/m-p/189477#M54587</guid>
      <dc:creator>ektasiwani</dc:creator>
      <dc:date>2015-03-20T05:23:00Z</dc:date>
    </item>
  </channel>
</rss>

