<?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: assign sourcetype based upon file name in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57268#M11188</link>
    <description>&lt;P&gt;There is. You will need to specify this in your props/transforms files any where indexing is being performed.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;props.conf&lt;BR /&gt;
[source::...regex_to_match_filename]&lt;BR /&gt;
TRANSFORMS-fs = force-sourcetype-st&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;transforms.conf&lt;BR /&gt;
[force-sourcetype-st]&lt;BR /&gt;
DEST_KEY = MetaData::Sourcetype&lt;BR /&gt;
SOURCE_KEY = MetaData::Source&lt;BR /&gt;
REGEX = YOUR_REGEX_TO_PULL_THE_FILENAME&lt;BR /&gt;
FORMAT = sourcetype::$1&lt;BR /&gt;
WRITE_META = true&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Referances&lt;BR /&gt;
&lt;CODE&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/admin/Transformsconf" target="test_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/admin/Transformsconf&lt;/A&gt;&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/admin/Propsconf" target="test_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/admin/Propsconf&lt;/A&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2013 13:12:52 GMT</pubDate>
    <dc:creator>alacercogitatus</dc:creator>
    <dc:date>2013-03-11T13:12:52Z</dc:date>
    <item>
      <title>assign sourcetype based upon file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57267#M11187</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Is there a way to dynamically assign sourcetype based upon input filename? &lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2013 12:58:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57267#M11187</guid>
      <dc:creator>a212830</dc:creator>
      <dc:date>2013-03-11T12:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: assign sourcetype based upon file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57268#M11188</link>
      <description>&lt;P&gt;There is. You will need to specify this in your props/transforms files any where indexing is being performed.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;props.conf&lt;BR /&gt;
[source::...regex_to_match_filename]&lt;BR /&gt;
TRANSFORMS-fs = force-sourcetype-st&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;transforms.conf&lt;BR /&gt;
[force-sourcetype-st]&lt;BR /&gt;
DEST_KEY = MetaData::Sourcetype&lt;BR /&gt;
SOURCE_KEY = MetaData::Source&lt;BR /&gt;
REGEX = YOUR_REGEX_TO_PULL_THE_FILENAME&lt;BR /&gt;
FORMAT = sourcetype::$1&lt;BR /&gt;
WRITE_META = true&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Referances&lt;BR /&gt;
&lt;CODE&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/admin/Transformsconf" target="test_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/admin/Transformsconf&lt;/A&gt;&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/admin/Propsconf" target="test_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/admin/Propsconf&lt;/A&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2013 13:12:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57268#M11188</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2013-03-11T13:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: assign sourcetype based upon file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57269#M11189</link>
      <description>&lt;P&gt;alacercogitatus's answer is certainly correct.  You can set the sourcetype at parsing time (typically on your indexer) with props and transforms.  For some problems this is the way to go.&lt;/P&gt;

&lt;P&gt;However, if you want the sourcetype set up from the beginning, so you can control things like the "CHARSET" (encoding),  NO_BINARY_CHECK and so on, then you can also control the sourcetype set at the input layer in tailing.  For this to work, you need to be willing to put configuration on your forwarder, and it would look something like&lt;/P&gt;

&lt;P&gt;props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::&amp;lt; pattern &amp;gt;]
sourcetype = what_you_want
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;lt; pattern &amp;gt; is whatever you need to match the file.  The simplest thing that gets everything you want and doesn't get false positives is kind of a local decision, but often it looks something like:&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
    [source::/var/log/my_app/*.log]&lt;BR /&gt;
    sourcetype = my_app&lt;BR /&gt;
&lt;/PRE&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;If you use both these techniques, then the value set at the input layer will be used until it is possibly modified by the props/transforms pass.  Usually though, you want to use one approach or the other for a particular dataset, lest you make things too confusing.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:29:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57269#M11189</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2020-09-28T13:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: assign sourcetype based upon file name</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57270#M11190</link>
      <description>&lt;P&gt;alacercogitatus's answer does work, though the separators for the MetaData keys are single colons, not double, i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DEST_KEY = MetaData:Sourcetype
SOURCE_KEY = MetaData:Source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After that it worked great!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 23:36:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/assign-sourcetype-based-upon-file-name/m-p/57270#M11190</guid>
      <dc:creator>mbonsack_splunk</dc:creator>
      <dc:date>2015-09-14T23:36:28Z</dc:date>
    </item>
  </channel>
</rss>

