<?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: How to set the source in a collect command to a variable? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/518966#M87785</link>
    <description>&lt;P&gt;I dont see this as working :&lt;/P&gt;&lt;P&gt;I have transforms.conf and props.conf set as you stated above in my etc/system/local area.&lt;/P&gt;&lt;P&gt;my search is as follows :&lt;/P&gt;&lt;P&gt;index=xxx | eval myDynamicSource=source | collect index=xxx source=myDynamicSource&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i see the source still set to&amp;nbsp;myDynamicSource.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am i missing ?&lt;/P&gt;</description>
    <pubDate>Thu, 10 Sep 2020 22:53:56 GMT</pubDate>
    <dc:creator>frankfowler</dc:creator>
    <dc:date>2020-09-10T22:53:56Z</dc:date>
    <item>
      <title>How to set the source in a collect command to a variable?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/474834#M81549</link>
      <description>&lt;P&gt;I am working with the collect command an want to set the source to a variable, not a string. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myDynamicSource=index."-".sourcetype
| collect index=garbage source=myDynamicSource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, the source in the collect is always just the name of the variable even if I use no quotes, double quotes or single quotes.&lt;/P&gt;

&lt;P&gt;Any idea what I am missing?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
--Keith&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 15:12:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/474834#M81549</guid>
      <dc:creator>creiglow</dc:creator>
      <dc:date>2019-11-03T15:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to set the source in a collect command to a variable?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/474835#M81550</link>
      <description>&lt;P&gt;To my knowledge, collect operates on the entire Input, as in, it's not a streaming command. This is why if you cancel the search(with a collect statement at the end) before it has completed, none of the records are saved. So you cannot dynamically change the metadata directly on the collect, but you can do a workaround using props and transforms. here is how.&lt;/P&gt;

&lt;P&gt;your collect remains as is &lt;CODE&gt;| collect index=garbage source=myDynamicSource&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In transforms.conf, you have this. In this, you're extracting the value of myDynamicSource and assigning it to the metadata field source&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[setDynamicSource]
REGEX = (myDynamicSource)=(.+)
FORMAT = source::$2
DEST_KEY= MetaData:Source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In props.conf, you just apply the above transform to the source myDynamicSource&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::myDynamicSource]
TRANSFORMS-set_source = setDynamicSource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 23:53:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/474835#M81550</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-03T23:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to set the source in a collect command to a variable?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/518966#M87785</link>
      <description>&lt;P&gt;I dont see this as working :&lt;/P&gt;&lt;P&gt;I have transforms.conf and props.conf set as you stated above in my etc/system/local area.&lt;/P&gt;&lt;P&gt;my search is as follows :&lt;/P&gt;&lt;P&gt;index=xxx | eval myDynamicSource=source | collect index=xxx source=myDynamicSource&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i see the source still set to&amp;nbsp;myDynamicSource.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am i missing ?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 22:53:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-set-the-source-in-a-collect-command-to-a-variable/m-p/518966#M87785</guid>
      <dc:creator>frankfowler</dc:creator>
      <dc:date>2020-09-10T22:53:56Z</dc:date>
    </item>
  </channel>
</rss>

