<?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 host_regex  is not working extract host name from windows path in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63134#M180255</link>
    <description>&lt;P&gt;All,&lt;/P&gt;

&lt;P&gt;I'm trying to use host_regex to extract host names for input&lt;/P&gt;

&lt;P&gt;Background:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;All logs are copied to a windows
fileshare (installing agents on the
servers are out of scope&lt;/LI&gt;
&lt;LI&gt;it would
make life easier) logs are in
different folder (split due as they
all have different timezones -
servers cannot use UTC/GMT)&lt;/LI&gt;
&lt;LI&gt;logs are in the following locations and format:&lt;BR /&gt;
C:\foo\bar\Splunk\EET\fihel01srv001-Mon.log&lt;BR /&gt;
C:\foo\bar\Splunk\CET\frpar01srv001-Mon.log&lt;BR /&gt;
C:\foo\bar\Splunk\WET\uklon01srv001-Mon.log&lt;BR /&gt;
etc...&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Aim&lt;BR /&gt;&lt;BR /&gt;
to get:&lt;BR /&gt;&lt;BR /&gt;
fihel01srv001&lt;BR /&gt;&lt;BR /&gt;
frpar01srv001&lt;BR /&gt;&lt;BR /&gt;
uklon01srv001&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;Attempted:&lt;BR /&gt;&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;the following (unoptimised) search works :&lt;BR /&gt;
index=test | rex field=source ".*?(?&lt;HOSTNAME&gt;[a-z]+[0-9]+[a-z]+[0-9]+)-.+\.log$"&lt;BR /&gt;&lt;/HOSTNAME&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;but...&lt;BR /&gt;&lt;BR /&gt;
when putting this into inputs.conf, it doesn't work&lt;BR /&gt;&lt;BR /&gt;
host field is set to the server that is indexing the logs&lt;BR /&gt;&lt;BR /&gt;
ie: host=splunkserver&lt;/P&gt;

&lt;P&gt;inputs.conf:&lt;BR /&gt;
[monitor://C:\foo\bar\Splunk\WET\&lt;EM&gt;.log]&lt;BR /&gt;
disabled = false&lt;BR /&gt;
followTail = 0&lt;BR /&gt;
index = test&lt;BR /&gt;
sourcetype = testlogs&lt;BR /&gt;
crcSalt=&lt;SOURCE&gt;&lt;BR /&gt;
host_regex = ".&lt;/SOURCE&gt;&lt;/EM&gt;?([a-z]+[0-9]+[a-z]+[0-9]+)-.+\.log$"&lt;/P&gt;

&lt;P&gt;BTW: also open to other alternative solutions...&lt;/P&gt;</description>
    <pubDate>Fri, 13 Sep 2013 09:57:47 GMT</pubDate>
    <dc:creator>splunked38</dc:creator>
    <dc:date>2013-09-13T09:57:47Z</dc:date>
    <item>
      <title>host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63134#M180255</link>
      <description>&lt;P&gt;All,&lt;/P&gt;

&lt;P&gt;I'm trying to use host_regex to extract host names for input&lt;/P&gt;

&lt;P&gt;Background:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;All logs are copied to a windows
fileshare (installing agents on the
servers are out of scope&lt;/LI&gt;
&lt;LI&gt;it would
make life easier) logs are in
different folder (split due as they
all have different timezones -
servers cannot use UTC/GMT)&lt;/LI&gt;
&lt;LI&gt;logs are in the following locations and format:&lt;BR /&gt;
C:\foo\bar\Splunk\EET\fihel01srv001-Mon.log&lt;BR /&gt;
C:\foo\bar\Splunk\CET\frpar01srv001-Mon.log&lt;BR /&gt;
C:\foo\bar\Splunk\WET\uklon01srv001-Mon.log&lt;BR /&gt;
etc...&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Aim&lt;BR /&gt;&lt;BR /&gt;
to get:&lt;BR /&gt;&lt;BR /&gt;
fihel01srv001&lt;BR /&gt;&lt;BR /&gt;
frpar01srv001&lt;BR /&gt;&lt;BR /&gt;
uklon01srv001&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;Attempted:&lt;BR /&gt;&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;the following (unoptimised) search works :&lt;BR /&gt;
index=test | rex field=source ".*?(?&lt;HOSTNAME&gt;[a-z]+[0-9]+[a-z]+[0-9]+)-.+\.log$"&lt;BR /&gt;&lt;/HOSTNAME&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;but...&lt;BR /&gt;&lt;BR /&gt;
when putting this into inputs.conf, it doesn't work&lt;BR /&gt;&lt;BR /&gt;
host field is set to the server that is indexing the logs&lt;BR /&gt;&lt;BR /&gt;
ie: host=splunkserver&lt;/P&gt;

&lt;P&gt;inputs.conf:&lt;BR /&gt;
[monitor://C:\foo\bar\Splunk\WET\&lt;EM&gt;.log]&lt;BR /&gt;
disabled = false&lt;BR /&gt;
followTail = 0&lt;BR /&gt;
index = test&lt;BR /&gt;
sourcetype = testlogs&lt;BR /&gt;
crcSalt=&lt;SOURCE&gt;&lt;BR /&gt;
host_regex = ".&lt;/SOURCE&gt;&lt;/EM&gt;?([a-z]+[0-9]+[a-z]+[0-9]+)-.+\.log$"&lt;/P&gt;

&lt;P&gt;BTW: also open to other alternative solutions...&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2013 09:57:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63134#M180255</guid>
      <dc:creator>splunked38</dc:creator>
      <dc:date>2013-09-13T09:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63135#M180256</link>
      <description>&lt;P&gt;Per &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/admin/inputsconf" target="_blank"&gt;Splunk inputs.conf doc&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;the host_regex extracts from the path, not the filename.&lt;/P&gt;

&lt;P&gt;Alternate solution. Put each server log in it's own folder and use host_regex or easier use host_segment.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:46:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63135#M180256</guid>
      <dc:creator>antlefebvre</dc:creator>
      <dc:date>2020-09-28T14:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63136#M180257</link>
      <description>&lt;P&gt;I'm not sure how many slashes, but this might work for your host_regex in inputs.conf&lt;/P&gt;

&lt;P&gt;\\\\\([a-z]+[0-9]+[a-z]+[0-9]+)-.+.log$"&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2013 13:41:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63136#M180257</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2013-09-13T13:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63137#M180258</link>
      <description>&lt;P&gt;Actually, the path &lt;EM&gt;includes&lt;/EM&gt; the file name, you can test this by using the following regex: (.+)&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2013 09:08:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63137#M180258</guid>
      <dc:creator>splunked38</dc:creator>
      <dc:date>2013-09-16T09:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63138#M180259</link>
      <description>&lt;P&gt;Sorry, this doesn't work, even without the quotes. Using the regex (.+), the path is prefixed with 'source:' therefore the regex will fail. The solution below.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2013 09:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63138#M180259</guid>
      <dc:creator>splunked38</dc:creator>
      <dc:date>2013-09-16T09:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: host_regex  is not working extract host name from windows path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63139#M180260</link>
      <description>&lt;P&gt;ok, the answer is...remove the quotes!&lt;/P&gt;

&lt;P&gt;The following works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; host_regex =_*?([a-z]+[0-9]+[a-z]+[0-9]+)-.+\\.log$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2013 09:10:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/host-regex-is-not-working-extract-host-name-from-windows-path/m-p/63139#M180260</guid>
      <dc:creator>splunked38</dc:creator>
      <dc:date>2013-09-16T09:10:23Z</dc:date>
    </item>
  </channel>
</rss>

