<?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 How to merge a search result with multiple fields and a dbquery with multiple columns matching on one (or more) fields or columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216308#M63424</link>
    <description>&lt;P&gt;I have a table in Oracle that monitors user logins to web apps. When a user accesses the webpage, I see the following in my access log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;192.168.100.12 - user1 [28/Sep/2016:13:11:17 -0700] [ecid: 005FP^^R3NfBh4HLyu_AiWi0x7FV002xSS] "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0" "GET /my_app HTTP/1.1" 302 263 17480 nifit.llnl.gov
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the following in session table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user1 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I have a field extraction setup for access common that returns ip address (ip_addr), user (username), request context (application)&lt;/P&gt;

&lt;P&gt;To see the database session information in Splunk, I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbquery USER_SESS "select userid, 
                     to_char(login_time,'YYYY-MM-DD HH24:MI:SS') AS created, 
                     to_char(last_accessed,'YYYY-MM-DD HH24:MI:SS') AS last_accessed, 
                     to_char(expiration,'YYYY-MM-DD HH24:MI:SS') AS expiry
                from USER_SESSION
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above query returns:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; USERID CREATED LAST_ACCESSED EXPIRY
&amp;gt; user1 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To view the access_common fields, I can use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sds_prod sourcetype=access_common | table ip_addr, username, application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That returns:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; IP_ADDR USERNAME APPLICATION
&amp;gt; 192.168.100.12 user1 /my_app
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to merge the two results so I can see a report with IP_ADDR, USERNAME, APPLICATION, LOGIN_TIME, LAST_ACCESSED,  EXPIRATION:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; IP_ADDR USERNAME APPLICATION CREATED LAST_ACCESSED EXPIRY
&amp;gt; 192.168.100.12 user1 /my_app 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The results from the access common log is matched to the database table on the Username/USERID field/column. For now I am not worried about matching the timestamps (i.e., the timestamps in the access common log is within the created/expiry time in database) as I am only looking at the last 24 hours.&lt;/P&gt;

&lt;P&gt;I was looking into subsearch but I am not clear how that works with a search + dbquery combination!&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 11:11:16 GMT</pubDate>
    <dc:creator>rrax619</dc:creator>
    <dc:date>2020-09-29T11:11:16Z</dc:date>
    <item>
      <title>How to merge a search result with multiple fields and a dbquery with multiple columns matching on one (or more) fields or columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216308#M63424</link>
      <description>&lt;P&gt;I have a table in Oracle that monitors user logins to web apps. When a user accesses the webpage, I see the following in my access log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;192.168.100.12 - user1 [28/Sep/2016:13:11:17 -0700] [ecid: 005FP^^R3NfBh4HLyu_AiWi0x7FV002xSS] "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0" "GET /my_app HTTP/1.1" 302 263 17480 nifit.llnl.gov
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the following in session table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user1 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I have a field extraction setup for access common that returns ip address (ip_addr), user (username), request context (application)&lt;/P&gt;

&lt;P&gt;To see the database session information in Splunk, I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbquery USER_SESS "select userid, 
                     to_char(login_time,'YYYY-MM-DD HH24:MI:SS') AS created, 
                     to_char(last_accessed,'YYYY-MM-DD HH24:MI:SS') AS last_accessed, 
                     to_char(expiration,'YYYY-MM-DD HH24:MI:SS') AS expiry
                from USER_SESSION
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above query returns:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; USERID CREATED LAST_ACCESSED EXPIRY
&amp;gt; user1 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To view the access_common fields, I can use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sds_prod sourcetype=access_common | table ip_addr, username, application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That returns:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; IP_ADDR USERNAME APPLICATION
&amp;gt; 192.168.100.12 user1 /my_app
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to merge the two results so I can see a report with IP_ADDR, USERNAME, APPLICATION, LOGIN_TIME, LAST_ACCESSED,  EXPIRATION:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; IP_ADDR USERNAME APPLICATION CREATED LAST_ACCESSED EXPIRY
&amp;gt; 192.168.100.12 user1 /my_app 2016-09-28 11:41:27 2016-09-28 13:11:17 2016-09-28 15:41:27
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The results from the access common log is matched to the database table on the Username/USERID field/column. For now I am not worried about matching the timestamps (i.e., the timestamps in the access common log is within the created/expiry time in database) as I am only looking at the last 24 hours.&lt;/P&gt;

&lt;P&gt;I was looking into subsearch but I am not clear how that works with a search + dbquery combination!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216308#M63424</guid>
      <dc:creator>rrax619</dc:creator>
      <dc:date>2020-09-29T11:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a search result with multiple fields and a dbquery with multiple columns matching on one (or more) fields or columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216309#M63425</link>
      <description>&lt;P&gt;Probably not the most efficient option but if your data volumes are not huge you should be able to achieve what you want with this;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |dbquery USER_SESS "select userid, 
                      to_char(login_time,'YYYY-MM-DD HH24:MI:SS') AS created, 
                      to_char(last_accessed,'YYYY-MM-DD HH24:MI:SS') AS last_accessed, 
                      to_char(expiration,'YYYY-MM-DD HH24:MI:SS') AS expiry
                 from USER_SESSION
| join userid [
    | search index=sds_prod sourcetype=access_common earliest=-1d
    | stats count by ip_addr, username, application
    | fields - count
    | rename username as userid
]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Simply change the type of your join to left if you want to include everything from the dbquery output even if it doesn't find a match.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 09:51:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216309#M63425</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-09-29T09:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a search result with multiple fields and a dbquery with multiple columns matching on one (or more) fields or columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216310#M63426</link>
      <description>&lt;P&gt;Thanks! That allowed me to create a single report that displays the apps the user is accessing and information on their session! We only have a few hundred users and low 100k page views to handle and it works fast. &lt;/P&gt;

&lt;P&gt;The left join was definitely what I was looking for. I added &lt;CODE&gt;| join type=left USERID&lt;/CODE&gt; to the query and uppercased &lt;CODE&gt;USERID&lt;/CODE&gt; for the query to work. I believe Oracle DB connector returns column headers in caps and it doesn't match otherwise.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 13:33:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-merge-a-search-result-with-multiple-fields-and-a-dbquery/m-p/216310#M63426</guid>
      <dc:creator>rrax619</dc:creator>
      <dc:date>2016-09-29T13:33:11Z</dc:date>
    </item>
  </channel>
</rss>

