<?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: RSyslog, Dynamic Filenames, and Host_Regex in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359765#M65633</link>
    <description>&lt;P&gt;I've progressed a little further on this, it fails to work when I use a wildcard "*" in the monitor stanza, and works perfectly when I use an absolute path / filename.&lt;/P&gt;

&lt;P&gt;This fails:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://var/log/splunk/websense/.*log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://var/log/splunk/websense/proxy01.log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This indexes host=proxy01&lt;/P&gt;

&lt;P&gt;However this means I would need a unique stanza for every single file I want to index, which doesn't make sense, surely this can be more dynamic.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2017 03:42:33 GMT</pubDate>
    <dc:creator>milesbrennan</dc:creator>
    <dc:date>2017-08-09T03:42:33Z</dc:date>
    <item>
      <title>RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359764#M65632</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;/P&gt;

&lt;P&gt;We're using Rsyslog to collect many of our appliance syslog streams, and then bringing them into Splunk on our heavy forwarder.&lt;/P&gt;

&lt;P&gt;However the issue we have is all "host" entries are using the heavy forwarder hostname, and not the syslog/appliance hostname.&lt;/P&gt;

&lt;P&gt;We've adjusted our Rsyslog configuration file to use dynamic filenames, with the following configuration:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#  vi /etc/rsyslog.d/splunk.conf
template (name="websense-proxy" type="string" string="/var/log/splunk/websense/%HOSTNAME%.log")
if $programname == "vendor=Forcepoint" and $msg contains "product=Security" then { action (type="omfile" dynafile="websense-proxy") stop }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works fine, and the log files are appearing correctly as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/var/log/splunk/websense/proxy01.log
/var/log/splunk/websense/proxy02.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However our "host_regex" does not work properly, and should be picking up the filename as the hostname (minus the file extention).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://var/log/splunk/websense/.*log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We've gone through the inputs.conf / host_regex documentation and several posts here, but can't get it working with Splunk properly.&lt;/P&gt;

&lt;P&gt;However it seems to be working fine in Regex101  -  &lt;A href="https://regex101.com/r/ayZak8/3"&gt;https://regex101.com/r/ayZak8/3&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In Splunk we're expecting to see host proxy01 and proxy02.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 22:49:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359764#M65632</guid>
      <dc:creator>milesbrennan</dc:creator>
      <dc:date>2017-08-08T22:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359765#M65633</link>
      <description>&lt;P&gt;I've progressed a little further on this, it fails to work when I use a wildcard "*" in the monitor stanza, and works perfectly when I use an absolute path / filename.&lt;/P&gt;

&lt;P&gt;This fails:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://var/log/splunk/websense/.*log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://var/log/splunk/websense/proxy01.log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This indexes host=proxy01&lt;/P&gt;

&lt;P&gt;However this means I would need a unique stanza for every single file I want to index, which doesn't make sense, surely this can be more dynamic.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 03:42:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359765#M65633</guid>
      <dc:creator>milesbrennan</dc:creator>
      <dc:date>2017-08-09T03:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359766#M65634</link>
      <description>&lt;P&gt;.* does not work this way in a monitor stanza.  As the documentation of inputs.conf says: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Note concerning wildcards and monitor:
* You can use wildcards to specify your input path for monitored input. Use
  "..." for recursive directory matching and "*" for wildcard matching in a
  single directory segment.
* "..." recurses through directories. This means that /foo/.../bar will match
  foo/bar, foo/1/bar, foo/1/2/bar, etc.
* You can use multiple "..." specifications in a single input path. For
  example: /foo/.../bar/...
* The asterisk (*) matches anything in a single path segment; unlike "...", it
  does not recurse. For example, /foo/*/bar matches the files /foo/bar,
  /foo/1/bar, /foo/2/bar, etc. However, it does not match /foo/1/2/bar.
  A second example: /foo/m*r/bar matches /foo/mr/bar, /foo/mir/bar,
  /foo/moor/bar, etc.
* You can combine "*" and "..." as needed: foo/.../bar/* matches any file in
  the bar directory within the specified path.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Therefore, this will work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [monitor://var/log/splunk/websense/*.log]
 index = proxy
 sourcetype = websense
 host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2017 13:34:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359766#M65634</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-08-09T13:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359767#M65635</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;

&lt;P&gt;will recommend to use slightly different method.&lt;BR /&gt;
have the rsyslog configured to have the host name in a directory path, example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/var/log/splunk/websense/&amp;lt;hostName&amp;gt;/*.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;now you can use the wonderful     &lt;CODE&gt;host_segment&lt;/CODE&gt; conf&lt;BR /&gt;
in this case, inputs.conf will look like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [monitor://var/log/splunk/websense/.../*.log]
  index = proxy
  sourcetype = websense
  host_segment = 5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and you are ready to rock and roll&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 13:44:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359767#M65635</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2017-08-09T13:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359768#M65636</link>
      <description>&lt;P&gt;@milesbrennan&lt;BR /&gt;
try below,&lt;BR /&gt;
    [monitor://var/log/splunk/websense/*.log]&lt;BR /&gt;
     index = proxy&lt;BR /&gt;
     sourcetype = websense&lt;BR /&gt;
     host_regex =/var/log/splunk/websense/(.+).log&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 14:00:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359768#M65636</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-08-09T14:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: RSyslog, Dynamic Filenames, and Host_Regex</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359769#M65637</link>
      <description>&lt;P&gt;I was able to get this working after changing monitor stanza to three "///"  i.e.&lt;/P&gt;

&lt;P&gt;This works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///var/log/splunk/websense-*log]
index = proxy
sourcetype = websense
host_regex = .*\-(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However using a directory continues to fail:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///var/log/splunk/websense/*log]
index = proxy
sourcetype = websense
host_regex = .*\/(.+)\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I'm forced to place all the logs into the main directory, I can't move them into their own "sourcetype" subdirectories - not a major issue, however it would be a little neater and help my OCD....   &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The main point however, is the host_regex is now working on the "*" wildcard, and hostnames are updating correctly in Splunk&lt;/P&gt;

&lt;P&gt;So in /etc/rsyslog.d/splunk.conf, we have the declarations like these, which makes the filtering more dynamic:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;template (name="fortigate"    type="string" string="/var/log/splunk/fortigate-%HOSTNAME%.log")
template (name="fortiweb"     type="string" string="/var/log/splunk/fortiweb-%HOSTNAME%.log")
template (name="fortiwebcef"  type="string" string="/var/log/splunk/fortiwebcef-%HOSTNAME%.log")
template (name="mfa"          type="string" string="/var/log/splunk/mfa-%HOSTNAME%.log")


if $msg contains "devid=FGT" then           { action (type="omfile" dynafile="fortigate") stop }
if $msg contains "device_id=FVVM" then      { action (type="omfile" dynafile="fortiweb") stop }
if $programname == "CEF" and $msg contains "FortiWeb" then       { action (type="omfile" dynafile="fortiwebcef") stop }
if $programname == "pfsvc" then             { action (type="omfile" dynafile="mfa") stop }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for all posts / answers.&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 00:46:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/RSyslog-Dynamic-Filenames-and-Host-Regex/m-p/359769#M65637</guid>
      <dc:creator>milesbrennan</dc:creator>
      <dc:date>2017-08-11T00:46:55Z</dc:date>
    </item>
  </channel>
</rss>

