<?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 Field extraction using regex -- Do I need to use an if or eval for this? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338252#M100335</link>
    <description>&lt;P&gt;I'm a newbie/rusty w/ regex and I'm sure I'm over thinking this.  I have lines from a firewall log and I would like to extract a field called protocol.  I want the "TCP" and "ICMP" from the following two lines where the second line has a second word so its a little more complex.  Do I use an if() or an eval to do this or is it simpler than that?  &lt;/P&gt;

&lt;P&gt;Teardown TCP connection 3119818 for outside:209.98.44.193/49936 to inside:192.168.1.8/1547 duration 0:05:01 bytes 931 TCP Reset-I&lt;/P&gt;

&lt;P&gt;Built outbound ICMP connection for faddr 192.168.151.96/512 gaddr 192.168.1.1/0 laddr 192.168.1.1/0&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2017 21:10:47 GMT</pubDate>
    <dc:creator>dipasqum</dc:creator>
    <dc:date>2017-12-12T21:10:47Z</dc:date>
    <item>
      <title>Field extraction using regex -- Do I need to use an if or eval for this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338252#M100335</link>
      <description>&lt;P&gt;I'm a newbie/rusty w/ regex and I'm sure I'm over thinking this.  I have lines from a firewall log and I would like to extract a field called protocol.  I want the "TCP" and "ICMP" from the following two lines where the second line has a second word so its a little more complex.  Do I use an if() or an eval to do this or is it simpler than that?  &lt;/P&gt;

&lt;P&gt;Teardown TCP connection 3119818 for outside:209.98.44.193/49936 to inside:192.168.1.8/1547 duration 0:05:01 bytes 931 TCP Reset-I&lt;/P&gt;

&lt;P&gt;Built outbound ICMP connection for faddr 192.168.151.96/512 gaddr 192.168.1.1/0 laddr 192.168.1.1/0&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 21:10:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338252#M100335</guid>
      <dc:creator>dipasqum</dc:creator>
      <dc:date>2017-12-12T21:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction using regex -- Do I need to use an if or eval for this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338253#M100336</link>
      <description>&lt;P&gt;&lt;CODE&gt;rex&lt;/CODE&gt; is a command so no need for &lt;CODE&gt;if&lt;/CODE&gt; or &lt;CODE&gt;eval&lt;/CODE&gt;. Try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "\s(?P&amp;lt;protocol&amp;gt;(TCP|ICMP))\s"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 02:27:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338253#M100336</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-12-13T02:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction using regex -- Do I need to use an if or eval for this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338254#M100337</link>
      <description>&lt;P&gt;thanks cpetterborg but I don't want this hardcoded because then it would miss protocols that could be there but aren't in my sample.&lt;/P&gt;

&lt;P&gt;^(?:[^:\n]*:){6}\s+\w+\w+\s+[a-z]+\s(?P\w+) is something I tried.  What is in bold is the content thats needed to extract into the field.&lt;/P&gt;

&lt;P&gt;Sep 7 15:47:28 10.1.1.99 Sep 07 2016 15:47:27 10.1.1.99 : %ASA-6-302014: Teardown &lt;STRONG&gt;TCP&lt;/STRONG&gt; connection 3119818 for outside:209.98.44.193/49936 to inside:192.168.1.8/1547 duration 0:05:01 bytes 931 TCP Reset-I&lt;BR /&gt;
Sep 7 15:47:28 10.1.1.99 Sep 07 2016 15:47:28 10.1.1.99 : %ASA-6-302020: Built outbound &lt;STRONG&gt;ICMP&lt;/STRONG&gt; connection for faddr 192.168.151.96/512 gaddr 192.168.1.1/0 laddr 192.168.1.1/0&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 17:48:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338254#M100337</guid>
      <dc:creator>dipasqum</dc:creator>
      <dc:date>2017-12-13T17:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction using regex -- Do I need to use an if or eval for this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338255#M100338</link>
      <description>&lt;P&gt;Since you are talking Cisco ASA events, this seems to work quite well on the events that we collect:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?P&amp;lt;protocol&amp;gt;\w+)\s+connection"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In our data only 60 events out of 36,000,000 didn't match a protocol. The protocol wasn't always  something caught correctly, however. Here is the breakdown of the value of protocol of the 36M events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TCP - 69%
no - 11%
ICMP - 10%
UDP - 10%
matching - .05%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Everything else made up less than 200 events of the 36M. So if you eliminate &lt;CODE&gt;no&lt;/CODE&gt; and &lt;CODE&gt;matching&lt;/CODE&gt; from your results, you should get a pretty good result set:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?P&amp;lt;protocol&amp;gt;\w+)\s+connection" | search protocol=*
regex protocol!="(no|matching|closing|Dropped|deleting|allocate)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There's plenty of opportunity to make changes to this, but it is at least a start.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 19:54:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-using-regex-Do-I-need-to-use-an-if-or-eval-for/m-p/338255#M100338</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-12-13T19:54:08Z</dc:date>
    </item>
  </channel>
</rss>

