<?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: Why does regex to extract host from path work in regex101, while it's not working in Splunk? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447710#M126879</link>
    <description>&lt;P&gt;@saurabhkharkar , I'm trying to extract host from log name into "host" field in data input monitoring via host_regex, not in search &lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 15:04:55 GMT</pubDate>
    <dc:creator>mlevsh</dc:creator>
    <dc:date>2018-12-20T15:04:55Z</dc:date>
    <item>
      <title>Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447707#M126876</link>
      <description>&lt;P&gt;I need to extract "hostname" from the path in data input on directory monitoring.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Path: /export/var/path/host1.log                    -&amp;gt;  Host: host1
Path: /export/var/path/host-02.ac.lp.our.domain.log -&amp;gt;  Host: host-02
Path /export/var/path/host3.ac.lp.our.domain.log   -&amp;gt;   Host:  host3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried 3 different regexes. They all work on regex101.com, but only extraction for host1.log works when I use regex as host_regex in inputs.conf.&lt;BR /&gt;
The other 2 "host" get set to "host-02.ac.lp.our.domain" and "host3.ac.lp.our.domain" after the data is ingested instead of being set to &lt;BR /&gt;
host-2 and host3.&lt;/P&gt;

&lt;P&gt;1) \/export\/var\/path\/(.*?[^.]+)&lt;BR /&gt;
&lt;A href="https://regex101.com/r/hu4Wax/1"&gt;https://regex101.com/r/hu4Wax/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///export/var/path/*.log]
disabled = false
host_regex =/export\/var/path/(.*?[^\.]+)
index = default
sourcetype = default
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk sets host to host1, host-02.ac.lp.our.domain and  host3.ac.lp.our.domain. Objective was host1,host-02,host3.&lt;/P&gt;

&lt;P&gt;2) ^\/\w+\/\w+\/\w+\/?([^.]+)&lt;BR /&gt;
&lt;A href="https://regex101.com/r/jTeVML/1"&gt;https://regex101.com/r/jTeVML/1&lt;/A&gt;&lt;BR /&gt;
Inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///export/var/path/*.log]
    disabled = false
    host_regex = ^\/\w+\/\w+\/\w+\/?([^\.]+)
    index = default
    sourcetype = default
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk sets host to host1  &amp;amp; host-02.ac.lp.our.domain &amp;amp; host3.ac.lp.our.domain&lt;/P&gt;

&lt;P&gt;3) \/export\/var\/path\/(.+?)..*log&lt;BR /&gt;
&lt;A href="https://regex101.com/r/yUJY9j/1/"&gt;https://regex101.com/r/yUJY9j/1/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [monitor:///export/var/path/*.log]
    disabled = false
    host_regex = \/export\/var\/path\/(.+?)\..*log
    index = default
    sourcetype = default
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk sets host to host1  &amp;amp; host-02.ac.lp.our.domain &amp;amp; host3.ac.lp.our.domain&lt;/P&gt;

&lt;P&gt;Will appreciate any advice!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 20:19:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447707#M126876</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-14T20:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447708#M126877</link>
      <description>&lt;P&gt;Try This&lt;/P&gt;

&lt;P&gt;| makeresults &lt;BR /&gt;
| eval Path="/export/var/path/host3.ac.lp.our.domain.log"&lt;BR /&gt;
| rex field=Path ".+\/(?[^.]+).*" &lt;BR /&gt;
| table Path host&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 20:44:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447708#M126877</guid>
      <dc:creator>saurabhkharkar</dc:creator>
      <dc:date>2018-12-14T20:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447709#M126878</link>
      <description>&lt;P&gt;Your #1 answer should be fine but use this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host_regex = ^(?:\/\w+){3}\/([^\.]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem that you are having is that you are not evaluating your changes correctly.   Are you restarting the splunk forwarder instance after you drop a change?  If so, then likely this is because you are not timestamping your events correctly so you are throwing events into the future and so when you think that you are evaluating the effect of your recent change, you are actually looking at events that were processed from a previous change but have just recently tricked from the future into the present.  Put in this change and evaluate your search with the &lt;CODE&gt;All time&lt;/CODE&gt; timepicker and with these arguments added to the base search, to make sure that you are really seeing events that were indexed recently.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... _index_earliest=-5m _index_latest=@m
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Dec 2018 21:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447709#M126878</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-12-14T21:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447710#M126879</link>
      <description>&lt;P&gt;@saurabhkharkar , I'm trying to extract host from log name into "host" field in data input monitoring via host_regex, not in search &lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 15:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447710#M126879</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-20T15:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447711#M126880</link>
      <description>&lt;P&gt;@woodcock, host_regex in data input works, but only for logs like host1.log. &lt;BR /&gt;
When I search for data host is set to "host1" after ingesting host1.log. &lt;BR /&gt;
But if a file name of a log has a domain name in it , like host-02.ac.lp.our.domain.log, &lt;BR /&gt;
then host is set to "host-02.ac.lp.our.domain" instead of "host-02". &lt;/P&gt;

&lt;P&gt;I don't think this issue is related to time stamping. &lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 15:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447711#M126880</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-20T15:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447712#M126881</link>
      <description>&lt;P&gt;Did you try the adjusted regex woodcock suggested? That &lt;CODE&gt;.*?&lt;/CODE&gt; part in your original regex is not needed and might cause some funky behavior (some regex libraries are more equal than others).&lt;/P&gt;

&lt;P&gt;Another option could be is that there is some hostname override happening. Is this syslog-like data, with the hostname also near the start of the log message? By using default sourcetype you may very well get some syslog-host extraction for free defined in system/default/props.conf, which bluntly overwrites whatever you do in inputs.conf.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 15:30:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447712#M126881</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-12-20T15:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447713#M126882</link>
      <description>&lt;P&gt;Do you really understand what I am saying?  The &lt;CODE&gt;RegEx&lt;/CODE&gt; is fine.  It must be that your evaluation for the efficacy of it is improper.  i stand by this statement.  Re-read what I said, and use the search parameters that I gave you.  The problem is NOT the &lt;CODE&gt;host_regex&lt;/CODE&gt; line.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 16:15:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447713#M126882</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-12-20T16:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447714#M126883</link>
      <description>&lt;P&gt;@woodcock, sorry for the delay. Hopefully, you will see my reply.&lt;BR /&gt;
I understood what you said, I don't have to re-read it. &lt;BR /&gt;
As I was testing it in our development env first, I made sure I wasn't looking on  previously ingested data.&lt;BR /&gt;
I've deleted index, created a new one , and used web gui -&amp;gt; Add Data -&amp;gt; Index Once -&amp;gt; Used current time as time stamp--&amp;gt; Used Regular Expression on path. &lt;BR /&gt;
Still host was extracted as expected only for "host.log" format , not for "host.ac.lp.doman.name.log" format. &lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 16:32:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447714#M126883</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-28T16:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447715#M126884</link>
      <description>&lt;P&gt;There is nothing more that I can do.  Something is not as it seems.  You should open a support case and report back what you eventually find.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 16:37:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447715#M126884</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-12-28T16:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447716#M126885</link>
      <description>&lt;P&gt;@FrankVl , hopefully you will see my comment. &lt;BR /&gt;
You were right in your suggestion!&lt;/P&gt;

&lt;P&gt;The sourcetype I was using ( I was selecting already existing sourcetype "syslog", was making some modifications to it and was saving under different name) -  had [syslog-host] in transforms.conf , that was overriding my host_regex in data input. &lt;/P&gt;

&lt;P&gt;Now I have  a challenge - how to extract host by using my host_regex without making any changes to sourcetype.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 18:42:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447716#M126885</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-28T18:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447717#M126886</link>
      <description>&lt;P&gt;@woodcock , &lt;BR /&gt;
The sourcetype I was using ( I was selecting already existing sourcetype "syslog", was making some modifications to it and was saving under different name) - had [syslog-host] in transforms.conf , that was overriding my host_regex in data input. &lt;/P&gt;

&lt;P&gt;Now I have a challenge - how to extract host by using my host_regex without making any changes to sourcetype ( for number of reasons)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 18:44:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447717#M126886</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-12-28T18:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447718#M126887</link>
      <description>&lt;P&gt;You only get 1 pass.through the parsing queue and if you are using the &lt;CODE&gt;syslog&lt;/CODE&gt; sourcetype (which I &lt;EM&gt;highly&lt;/EM&gt; discourage for exactly this reason) then that is the problem.  Copy the &lt;CODE&gt;syslog&lt;/CODE&gt; stuff that you need into your own sourcetype and work from there.   &lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 19:47:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447718#M126887</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-12-28T19:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447719#M126888</link>
      <description>&lt;P&gt;You can check if the regex works with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Path="/export/var/path/host-04.ac.lp.our.domain.log"
| rex field=Path ".+\/(?&amp;lt;host&amp;gt;\-?[^.]+).*" 
| table Path host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Just adjust the host in the "| eval Path=........" to check what is hitting with this regex.&lt;BR /&gt;
This is your working host_regex: (remove the naming of the capture group &lt;CODE&gt;"?&amp;lt;host&amp;gt;"&lt;/CODE&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host_regex = .+\/(\-?[^.]+).*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 11:48:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447719#M126888</guid>
      <dc:creator>micheldejong</dc:creator>
      <dc:date>2019-05-22T11:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why does regex to extract host from path work in regex101, while it's not working in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447720#M126889</link>
      <description>&lt;P&gt;The issue was never with the regex. His host field was being overwritten by a transforms from some of the config files in etc/system. See &lt;A href="https://answers.splunk.com/comments/710989/view.html"&gt;https://answers.splunk.com/comments/710989/view.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 13:41:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-regex-to-extract-host-from-path-work-in-regex101-while/m-p/447720#M126889</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-05-22T13:41:37Z</dc:date>
    </item>
  </channel>
</rss>

