<?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 Use an external script to pass values to search query in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Use-an-external-script-to-pass-values-to-search-query/m-p/157052#M2151</link>
    <description>&lt;P&gt;We need to be able to use the results of an external command as inputs into a search query. &lt;/P&gt;

&lt;P&gt;Specifically, we want to run a Python script that queries our AD and exclude the members of a group from search results. The Python script is all set but the integration into the query is confusing.&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
[HRUserException]&lt;BR /&gt;&lt;BR /&gt;
external_cmd = my_script.py&lt;BR /&gt;&lt;BR /&gt;
external_type = python&lt;/P&gt;

&lt;P&gt;Script output:&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;value1&lt;BR /&gt;&lt;BR /&gt;
value2&lt;BR /&gt;&lt;BR /&gt;
value3&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;How can we integrate this so that the output is used as a NOT condition? Script and output can be modified too.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 08 May 2014 15:07:04 GMT</pubDate>
    <dc:creator>bxsplunkuser</dc:creator>
    <dc:date>2014-05-08T15:07:04Z</dc:date>
    <item>
      <title>Use an external script to pass values to search query</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Use-an-external-script-to-pass-values-to-search-query/m-p/157052#M2151</link>
      <description>&lt;P&gt;We need to be able to use the results of an external command as inputs into a search query. &lt;/P&gt;

&lt;P&gt;Specifically, we want to run a Python script that queries our AD and exclude the members of a group from search results. The Python script is all set but the integration into the query is confusing.&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
[HRUserException]&lt;BR /&gt;&lt;BR /&gt;
external_cmd = my_script.py&lt;BR /&gt;&lt;BR /&gt;
external_type = python&lt;/P&gt;

&lt;P&gt;Script output:&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;value1&lt;BR /&gt;&lt;BR /&gt;
value2&lt;BR /&gt;&lt;BR /&gt;
value3&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;How can we integrate this so that the output is used as a NOT condition? Script and output can be modified too.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 15:07:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Use-an-external-script-to-pass-values-to-search-query/m-p/157052#M2151</guid>
      <dc:creator>bxsplunkuser</dc:creator>
      <dc:date>2014-05-08T15:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Use an external script to pass values to search query</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Use-an-external-script-to-pass-values-to-search-query/m-p/157053#M2152</link>
      <description>&lt;P&gt;Assuming your script results yield one event per excluded user with a user field set to its login, you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=something NOT [HRUserException]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will take the results of the subsearch, for example these events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1: user=foo
2: user=bar
3: user=baz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and turn that into this search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( user="foo" ) OR ( user="bar" ) OR ( user="baz" ) )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The NOT in front of the subsearch will exclude those three users from the search, giving you this main search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=something NOT ( ( user="foo" ) OR ( user="bar" ) OR ( user="baz" ) )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your external command results don't have a user field yet you may need to &lt;CODE&gt;rex&lt;/CODE&gt; it out of the results first.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 17:27:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Use-an-external-script-to-pass-values-to-search-query/m-p/157053#M2152</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-08T17:27:49Z</dc:date>
    </item>
  </channel>
</rss>

