<?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: Search time parsing using regex with lookahead in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574311#M101532</link>
    <description>&lt;P&gt;Try a regex that doesn't use lookahead.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;REGEX = \bcs1Label=(.*?)((\s\w+=)|$).*cs1=(.*?)((\s\w+=)|$)
FORMAT = $1::$4&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 10 Nov 2021 01:07:47 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2021-11-10T01:07:47Z</dc:date>
    <item>
      <title>Search time parsing using regex with lookahead</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574233#M101524</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to ask about problem with parsing log using regex with lookahead.&lt;/P&gt;&lt;P&gt;I have this log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Oct 10 04:18:31 ATLAS Threat Categories|Blocked Host|7|rt=1633832250000 src=122.226.102.59 cs3Label=Match Type dpt=23 cn2=13 proto=TCP dst=193.85.146.63 cn1=21129644 spt=39528 cs2Label=Protection Group Name cs1Label=IOC Pattern cn1Label=Element Id cn2Label=Protection Group ID cs7Label=Threat Category cs7=Malware cs6=Telnet Bruteforce cs1=122.226.102.59 cs6Label=Threat Name cs3=ip cs2=Default Protection Group&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, there are a number of parameters for which two fields are always used, eg "cs1Label" (parameter name) and "cs1" (parameter value). My goal is to create a new field in search time parsing phase, which will be the value of the field "cs1Label" and the value will be the value of the field "cs1". For example:&lt;/P&gt;&lt;P&gt;IOC Pattern = 122.226.102.59&lt;/P&gt;&lt;P&gt;The problem is that the log does not have a fixed structure, the order of the individual fields changes.&lt;BR /&gt;Therefore, "normal" regex cannot be used. So I created the following regex using a lookahead that parses the appropriate values ​​(I tested it in a regex101.com tester and it works):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;^(?=.*\bcs1Label=\b((.*?)((\s\w+\=)|($))))(?=.*\bcs1=\b((.*?)((\s\w+\=)|($))))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, when I use it in Splunk, in transforms.conf, it doesn't work. My transforms.conf looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[combined_field_cs1]
SOURCE_KEY = _raw
REGEX = ^(?=.\bcs1Label=\b((.?)((\s\w+=)|($))))(?=.\bcs1=\b((.?)((\s\w+=)|($))))
FORMAT = $2::$7&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;props.conf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;REPORT-combined_field_cs1 = combined_field_cs1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Strictly speaking, when I simply want to look at the messages in a given index, the search freezes, it does not display any messages and I have to close it manually.&lt;BR /&gt;I made some testing and it obvious that REGEX is the problem. It is not clear to me why the regex in Splunk does not work. Or did I choose the completely wrong path and need to use a completely different way to achieve my goal? Could yomeone more experinced help? Any help will be highly appreciated.&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Lukas Mecir&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 16:15:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574233#M101524</guid>
      <dc:creator>lukasmecir</dc:creator>
      <dc:date>2021-11-09T16:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Search time parsing using regex with lookahead</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574311#M101532</link>
      <description>&lt;P&gt;Try a regex that doesn't use lookahead.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;REGEX = \bcs1Label=(.*?)((\s\w+=)|$).*cs1=(.*?)((\s\w+=)|$)
FORMAT = $1::$4&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 Nov 2021 01:07:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574311#M101532</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-11-10T01:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Search time parsing using regex with lookahead</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574352#M101539</link>
      <description>&lt;P&gt;Hi, thanks for the suggestion, but I have already tried such a regex and unfortunately it is not a solution. As I wrote, the order of the parts of the report may vary. So your regex would work if the "cs1Label" field was in the message before the "cs1" field, but if the order was reversed (which can happen), then it wouldn't work. That's why I used lookahead, it works with it in any order of fields, but unfortunately only in regex101.com, not in Splunk ...&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 09:01:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574352#M101539</guid>
      <dc:creator>lukasmecir</dc:creator>
      <dc:date>2021-11-10T09:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Search time parsing using regex with lookahead</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574554#M101564</link>
      <description>&lt;P&gt;I thought again about what you wrote, and I think I finally - inspired by you - found a solution.&lt;BR /&gt;Parameters cn1 - cn7 and cs1 - cs7 can appear in each log message, where each parameter is expressed by two fields, eg field cs1Label bears the name of the parameter and its corresponding field cs1 bears the value of this parameter (and similarly for parameters cs2 - cs7 and cn1 - cn7).&lt;BR /&gt;So the message can contain the following fields:&lt;BR /&gt;cs1, cs2, cs3, cs4, cs5, cs6, cs7&lt;BR /&gt;cs1Label, cs2Label, cs3Label, cs4Label, cs5Label, cs6Label, cs7Label&lt;BR /&gt;cn1, cn2, cn3, cn4, cn5, cn6, cn7&lt;BR /&gt;cn1Label, cn2Label, cn3Label, cn4Label, cn5Label, cn6Label, cn7Label&lt;BR /&gt;These fields can be in a different order in each message.&lt;BR /&gt;So in the end I created two REGEXs for each pair of corresponding parameters - eg cs1 and cs1Label:&lt;/P&gt;&lt;P&gt;in case the first field in the message is cs1 and cs1Label after it&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cs1=([^=]+)\s.*cs1Label=([^=]+)(\s|$)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for the opposite case, when the first field is cs1Label and cs1 only after it&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cs1Label=([^=]+)\s.*cs1=([^=]+)(\s|$)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;And the same for every other pair.&lt;BR /&gt;This ensures that the data is parsed in any field order.&lt;BR /&gt;Therefore, the transforms.conf file looks like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[cs1_named_v1]
SOURCE_KEY = _raw
REGEX = cs1=([^=]+)\s.*cs1Label=([^=]+)(\s|$)
FORMAT = $2::$1

[cs1_named_v2]
SOURCE_KEY = _raw
REGEX = cs1Label=([^=]+)\s.*cs1=([^=]+)(\s|$)
FORMAT = $1::$2

[cn1_named_v1]
SOURCE_KEY = _raw
REGEX = cn1=([^=]+)\s.*cn1Label=([^=]+)(\s|$)
FORMAT = $2::$1

[cn1_named_v2]
SOURCE_KEY = _raw
REGEX = cn1Label=([^=]+)\s.*cn1=([^=]+)(\s|$)
FORMAT = $1::$2
etc.&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;And of course I added the appropriate REPORT commands to props.conf.&lt;BR /&gt;Thanks again for the inspiration and the effort to help.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 12:18:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Search-time-parsing-using-regex-with-lookahead/m-p/574554#M101564</guid>
      <dc:creator>lukasmecir</dc:creator>
      <dc:date>2021-11-11T12:18:23Z</dc:date>
    </item>
  </channel>
</rss>

