<?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: How to know which value from lookup table matched the log in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547118#M155111</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233271"&gt;@hFHUT2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Couple of suggestions:&lt;/P&gt;&lt;P&gt;1. You can always use rex to extract the fields from your data, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your search&amp;gt;
| rex field=_raw ".*(?&amp;lt;event_has_this&amp;gt;this).*"
| rex field=_raw ".*(?&amp;lt;event_has_that&amp;gt;that).*"
| rex field=_raw ".*(?&amp;lt;event_has_other&amp;gt;other).*"
| foreach event_* [ eval matches_found=mvappend(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, matches_found) ]&lt;/LI-CODE&gt;&lt;P&gt;this will create a new field event_has_X for each match found and then the last foreach line will collect all the matches found.&amp;nbsp; (This assumes it's possible to have more than one match in the data)&lt;/P&gt;&lt;P&gt;If you just want a single (first) match, you could use&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval match=coalesce(event_has_this, event_has_that, event_has_other)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. An alternative is to use a lookup definition with wildcard, so configure the lookup definition with&amp;nbsp;&lt;/P&gt;&lt;P&gt;WILDCARD(value)&lt;/P&gt;&lt;P&gt;and then surround your lookup values with *, i.e. *test_value1*&lt;/P&gt;&lt;P&gt;then do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| lookup definition_name value as _raw OUTPUT id value as found_value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Apr 2021 21:59:05 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2021-04-07T21:59:05Z</dc:date>
    <item>
      <title>How to know which value from lookup table matched the log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547104#M155103</link>
      <description>&lt;P&gt;I have a lookup table that has a list of values in it similar to:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;test_value1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;test_value2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can search for all logs that have any of these values in them by doing:&lt;/P&gt;&lt;PRE&gt;index=blah sourcetype=blah [|inputlookup test_values | rename value AS search | fields search | format]&lt;/PRE&gt;&lt;P&gt;This creates a search such as:&lt;/P&gt;&lt;PRE&gt;index=blah sourcetype=blah ( ( "test_value1" ) OR ( "test_value2" ) )&lt;/PRE&gt;&lt;P&gt;What I'm trying to figure out is how to know which value from the lookup table was responsible for matching each log.&lt;/P&gt;&lt;P&gt;However, because I'm not searching for the values in any particular field in the logs, and the fact that the lookup table values might be substrings of a larger value in the logs, I don't think I can use "| lookup" in order to match back to the lookup table.&lt;/P&gt;&lt;P&gt;Put another way that doesn't even necessarily need to involve a lookup table, if you had this search:&lt;/P&gt;&lt;PRE&gt;index=blah sourcetype=blah *this* OR *that*&lt;/PRE&gt;&lt;P&gt;Is there any way to create a new field within the matching logs that would contain either the string "this" or "that" depending on which one was the cause of the match?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 21:06:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547104#M155103</guid>
      <dc:creator>hFHUT2</dc:creator>
      <dc:date>2021-04-07T21:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to know which value from lookup table matched the log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547118#M155111</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233271"&gt;@hFHUT2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Couple of suggestions:&lt;/P&gt;&lt;P&gt;1. You can always use rex to extract the fields from your data, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your search&amp;gt;
| rex field=_raw ".*(?&amp;lt;event_has_this&amp;gt;this).*"
| rex field=_raw ".*(?&amp;lt;event_has_that&amp;gt;that).*"
| rex field=_raw ".*(?&amp;lt;event_has_other&amp;gt;other).*"
| foreach event_* [ eval matches_found=mvappend(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, matches_found) ]&lt;/LI-CODE&gt;&lt;P&gt;this will create a new field event_has_X for each match found and then the last foreach line will collect all the matches found.&amp;nbsp; (This assumes it's possible to have more than one match in the data)&lt;/P&gt;&lt;P&gt;If you just want a single (first) match, you could use&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval match=coalesce(event_has_this, event_has_that, event_has_other)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. An alternative is to use a lookup definition with wildcard, so configure the lookup definition with&amp;nbsp;&lt;/P&gt;&lt;P&gt;WILDCARD(value)&lt;/P&gt;&lt;P&gt;and then surround your lookup values with *, i.e. *test_value1*&lt;/P&gt;&lt;P&gt;then do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| lookup definition_name value as _raw OUTPUT id value as found_value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 21:59:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547118#M155111</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-04-07T21:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to know which value from lookup table matched the log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547177#M155130</link>
      <description>&lt;P&gt;I really like your wildcard lookup table suggestion. It seems like the cleanest fit for what I'm trying to do. I need to have someone enable that wildcard option on the KV Store I'm using so that I can give it a shot.&lt;/P&gt;&lt;P&gt;However, for your first suggestion, I'm unclear as to how I would actually make that work. In your example, you have three separate "rex" commands, but I'm not sure how to make that work with the lookup table... I would need to somehow automatically add those into the search for every value in the lookup table, which is a lot of them.&lt;/P&gt;&lt;P&gt;I'll report back when I have that set up so that I can potentially mark your answer as accepted. Thanks!&lt;/P&gt;&lt;P&gt;Edit: I got the WILDCARD setting enabled, and it works beautifully! Thank you so much! I didn't realize that was an option.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 12:49:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547177#M155130</guid>
      <dc:creator>hFHUT2</dc:creator>
      <dc:date>2021-04-08T12:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to know which value from lookup table matched the log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547532#M155265</link>
      <description>&lt;P&gt;On the rex part of my suggestion, as you suggested, it's not a practical solution for many matches. Glad the lookup worked though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 10:41:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-know-which-value-from-lookup-table-matched-the-log/m-p/547532#M155265</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-04-11T10:41:06Z</dc:date>
    </item>
  </channel>
</rss>

