<?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 Combined queries, matching unique rex values and comparing in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503972#M140694</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I've got two queries I'm trying to combine to track authorizations that are completed, or expire after a period of seven days.&amp;nbsp; The first query gets all of the authorizations sent, filtered by a unique AccountNum.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 1:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=-8d@d latest=-7d@d sourcetype="PCF:log" cf_app_name=app1 "Sending authorization" 
| rex field=msg "BAN: (?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The second query returns all authorizations that have expired after a period of inactivity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 2:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=@d latest=now sourcetype="PCF:log" cf_app_name=app2 "authorizationExpired" 
| rex field=msg ",ban:(?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I've gotten to combining them how I need is:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 3:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=-8d@d latest=-7d@d sourcetype="PCF:log" cf_app_name=app1 "Sending authorization" 
| rex field=msg "BAN: (?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum 
| append 
[search earliest=@d latest=now sourcetype="PCF:log" cf_app_name=app2 "authorizationExpired" 
| rex field=msg ",ban:(?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum ] 
| fields msg | eval action=case(     match(msg,"Sending authorization+"), "Total Authorizations Sent",    match(msg,"authorizationExpired+"), "Authorizations Expired")  
| stats count(msg) by action&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there are two mistakes/gaps with this third query. The first problem is I need the second query to only return results where AccountNum in query 2 is matching an AccountNum in query 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, I'd like to have a pie chart of Authorizations Expired (query 2) vs Authorizations Complete (total - expired = complete) but I'm struggling with the syntax on how to achieve that.&amp;nbsp; This third query shows total + expired, where expired is actually a subset of total.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess a third thing would be I don't know that &lt;EM&gt;append&amp;nbsp;&lt;/EM&gt;is really what I need or if there's a better, more performant way to construct this query?&amp;nbsp; I'd love to learn any helpful tips or tricks!&lt;/P&gt;&lt;P&gt;Greatly appreciate any help&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jun 2020 17:35:53 GMT</pubDate>
    <dc:creator>mrhodes93</dc:creator>
    <dc:date>2020-06-11T17:35:53Z</dc:date>
    <item>
      <title>Combined queries, matching unique rex values and comparing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503972#M140694</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I've got two queries I'm trying to combine to track authorizations that are completed, or expire after a period of seven days.&amp;nbsp; The first query gets all of the authorizations sent, filtered by a unique AccountNum.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 1:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=-8d@d latest=-7d@d sourcetype="PCF:log" cf_app_name=app1 "Sending authorization" 
| rex field=msg "BAN: (?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The second query returns all authorizations that have expired after a period of inactivity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 2:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=@d latest=now sourcetype="PCF:log" cf_app_name=app2 "authorizationExpired" 
| rex field=msg ",ban:(?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I've gotten to combining them how I need is:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Query 3:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=-8d@d latest=-7d@d sourcetype="PCF:log" cf_app_name=app1 "Sending authorization" 
| rex field=msg "BAN: (?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum 
| append 
[search earliest=@d latest=now sourcetype="PCF:log" cf_app_name=app2 "authorizationExpired" 
| rex field=msg ",ban:(?&amp;lt;AccountNum&amp;gt;\w+)" | dedup AccountNum ] 
| fields msg | eval action=case(     match(msg,"Sending authorization+"), "Total Authorizations Sent",    match(msg,"authorizationExpired+"), "Authorizations Expired")  
| stats count(msg) by action&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there are two mistakes/gaps with this third query. The first problem is I need the second query to only return results where AccountNum in query 2 is matching an AccountNum in query 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, I'd like to have a pie chart of Authorizations Expired (query 2) vs Authorizations Complete (total - expired = complete) but I'm struggling with the syntax on how to achieve that.&amp;nbsp; This third query shows total + expired, where expired is actually a subset of total.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess a third thing would be I don't know that &lt;EM&gt;append&amp;nbsp;&lt;/EM&gt;is really what I need or if there's a better, more performant way to construct this query?&amp;nbsp; I'd love to learn any helpful tips or tricks!&lt;/P&gt;&lt;P&gt;Greatly appreciate any help&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503972#M140694</guid>
      <dc:creator>mrhodes93</dc:creator>
      <dc:date>2020-06-11T17:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combined queries, matching unique rex values and comparing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503975#M140696</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sourcetype="PCF:log" (earliest=-8d@d latest=-7d@d  cf_app_name=app1 "Sending authorization" ) OR (earliest=@d latest=now cf_app_name=app2 "authorizationExpired" )
| rex field=msg "BAN: (?&amp;lt;AccountNum&amp;gt;\w+)" 
| stats count dc(cf_app_name) as flag values(cf_app_name) as cf_app_name by AccountNum
| stats count as total count(eval(flag=2)) as expired
| eval complete = total - expired
| fields - complete&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In this case, cf_app_name can be used to determine expire or not.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:59:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503975#M140696</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-06-11T17:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combined queries, matching unique rex values and comparing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503989#M140703</link>
      <description>&lt;P&gt;I haven't yet tried the query but wondered if this will work as the regex for identifying the AccountNum varies slightly between the two queries?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rex field=msg "BAN: (?&amp;lt;BAN&amp;gt;\w+)"&amp;nbsp; &amp;nbsp;- space between colon and var value&lt;/P&gt;&lt;P&gt;rex field=msg ",ban:(?&amp;lt;BAN&amp;gt;\w+)" - prefixed comma, no space between colon and var value&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 19:40:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503989#M140703</guid>
      <dc:creator>mrhodes93</dc:creator>
      <dc:date>2020-06-11T19:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Combined queries, matching unique rex values and comparing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503998#M140707</link>
      <description>&lt;P&gt;You can merge the two regex strings together for this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rex field=msg "BAN: (?&amp;lt;BAN&amp;gt;\w+)"&amp;nbsp; &amp;nbsp;- space between colon and var value&lt;/P&gt;&lt;P&gt;rex field=msg ",ban:(?&amp;lt;BAN&amp;gt;\w+)" - prefixed comma, no space between colon and var value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can just become&lt;/P&gt;&lt;P&gt;rex field=msg "(BAN|,ban): ?(?&amp;lt;BAN&amp;gt;'w+)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first part is a grouped OR statement specifying that the string must be either BAN or ,ban. The second change is the ? after space. this indicates the space is optional. Please make sure, however, that this pattern does in fact work with your data and I would advise running a test set in something like regex101&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 20:47:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/503998#M140707</guid>
      <dc:creator>twesty</dc:creator>
      <dc:date>2020-06-11T20:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combined queries, matching unique rex values and comparing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/504027#M140715</link>
      <description>&lt;P&gt;Thank you both so much, both for the information and the explanations! Minor regex tinkering got this working as expected!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 22:54:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combined-queries-matching-unique-rex-values-and-comparing/m-p/504027#M140715</guid>
      <dc:creator>mrhodes93</dc:creator>
      <dc:date>2020-06-11T22:54:04Z</dc:date>
    </item>
  </channel>
</rss>

