<?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 search logs for values on multiple lines? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403137#M116648</link>
    <description>&lt;P&gt;Can you share a sanitized version of the logs for the connection with ID 952?&lt;/P&gt;</description>
    <pubDate>Thu, 17 May 2018 19:45:55 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2018-05-17T19:45:55Z</dc:date>
    <item>
      <title>How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403129#M116640</link>
      <description>&lt;P&gt;I have a log (IPs and user name altered):&lt;BR /&gt;
Time - ID - Command - Argument&lt;BR /&gt;
2018-05-16T18:06:23.680096Z   225 Connect   Access denied for user 'admin'@'214.76.36.55' (using password: YES)&lt;BR /&gt;
2018-05-16T18:06:25.389937Z   226 Connect   &lt;A href="mailto:admin@214.76.36.55"&gt;admin@214.76.36.55&lt;/A&gt; on  using TCP/IP&lt;BR /&gt;
2018-05-16T18:06:25.390134Z   226 Connect   Access denied for user 'admin'@'218.76.36.55' (using password: YES) &lt;BR /&gt;
2018-05-16T18:15:49.136165Z   227 Connect   &lt;A href="mailto:ruff@205.181.75.173"&gt;ruff@205.181.75.173&lt;/A&gt; on  using TCP/IP&lt;BR /&gt;
2018-05-16T18:15:49.213672Z   227 Query select @@version_comment limit 1&lt;BR /&gt;
2018-05-16T18:15:52.691468Z   227 Quit  &lt;/P&gt;

&lt;P&gt;I'd like to build a query that will show me any two lines that &lt;BR /&gt;
Line 1 has a "Connect" and the NEXT line has a "Query"&lt;/P&gt;

&lt;P&gt;2018-05-16T18:06:25.390134Z   226 Connect   Access denied for user 'admin'@'218.76.36.55' (using password: YES) &lt;BR /&gt;
2018-05-16T18:15:49.136165Z   227 Connect   &lt;A href="mailto:ruff@205.181.75.173"&gt;ruff@205.181.75.173&lt;/A&gt; on  using TCP/IP&lt;/P&gt;

&lt;P&gt;Note, the 226 and 227 (ID) appear to be unique for each attempt, i.e. both 226's are related to the same connection, the 227, Connect, query and quit are all part of the same connection.  Also, some of the lines are not formatted so nicely.&lt;/P&gt;

&lt;P&gt;I'm stumped!!  Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 15:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403129#M116640</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T15:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403130#M116641</link>
      <description>&lt;P&gt;Question - Do you really need to detect the pattern "Line containing 'Connect' followed immediately by line containing 'Query'"? What's the root purpose? Are you trying to find the username of the user running a query? If so, that's a little different (and actually easier).&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 17:43:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403130#M116641</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-17T17:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403131#M116642</link>
      <description>&lt;P&gt;I guess you can do something like this to combine each connection attempt (ID) like this (assuming fields are not extracted, if they are exclude rex command)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rex "^\S+\s+(?&amp;lt;ID&amp;gt;\S+)\s+(?&amp;lt;Action&amp;gt;\S+)"
| stats list(_time) as _raw list(Action) as Action by ID
| where isnotnull(mvfind(Action,"Connect")) AND isnotnull(mvfind(Action,"Query"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There can be a better/different solution possible based on your final requirement (what your final output should look like).&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:04:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403131#M116642</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-17T18:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403132#M116643</link>
      <description>&lt;P&gt;I must have pasted wrong, I"m looking for this combo:&lt;/P&gt;

&lt;P&gt;2018-05-16T18:15:49.136165Z 227 Connect &lt;A href="mailto:ruff@205.181.75.173"&gt;ruff@205.181.75.173&lt;/A&gt; on using TCP/IP&lt;BR /&gt;
2018-05-16T18:15:49.213672Z 227 Query select version_comment limit 1&lt;/P&gt;

&lt;P&gt;After reviewing all the logs manually, this combo is the only indication of a successful connection and authentication.  There are multitudes of "connects" and "query"s, but this exact combo, having the same ID number for both Connect and Query, is what I'm looking for.   Extracting the resulting IP and date/time should be easy after finding both lines.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403132#M116643</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T18:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403133#M116644</link>
      <description>&lt;P&gt;Did you get a chance to test this?&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:15:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403133#M116644</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-17T19:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403134#M116645</link>
      <description>&lt;P&gt;Building on the suggestion above by @somesoni2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rex "^\S+\s+(?&amp;lt;ID&amp;gt;\S+)\s+(?&amp;lt;Action&amp;gt;\S+)\s+((?&amp;lt;User&amp;gt;\w+)@(?&amp;lt;IP&amp;gt;\d+\.\d+\.\d+\.\d+))?"
| stats list(User) AS User list(IP) AS IP list(Action) AS Action BY ID
| where isnotnull(mvfind(Action,"Connect")) AND isnotnull(mvfind(Action,"Query"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give you the User, IP, and Action for each ID - based on the format of those two events here in your comment.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:22:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403134#M116645</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-17T19:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403135#M116646</link>
      <description>&lt;P&gt;Some,&lt;BR /&gt;
Very close, it adds a raw field which I can deal with because I do get the information I need, here's the output:&lt;/P&gt;

&lt;P&gt;ID  _raw            Action&lt;BR /&gt;
952 1526559902.256133   Quit&lt;BR /&gt;
        1526559902.241782   Query&lt;BR /&gt;
        1526559902.241542   Connect&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:40:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403135#M116646</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T19:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403136#M116647</link>
      <description>&lt;P&gt;Pretty close as well, Output:&lt;/P&gt;

&lt;P&gt;ID  User    IP  Action&lt;BR /&gt;
952             Quit&lt;BR /&gt;
                Query&lt;BR /&gt;
                Connect&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403136#M116647</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T19:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403137#M116648</link>
      <description>&lt;P&gt;Can you share a sanitized version of the logs for the connection with ID 952?&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:45:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403137#M116648</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-17T19:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403138#M116649</link>
      <description>&lt;P&gt;There actually a typo in my query, list(_time) should actually be list(_raw) in line 3. This way you retain the raw log data and can extract any field you want for later.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:34:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403138#M116649</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-29T19:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403139#M116650</link>
      <description>&lt;P&gt;Because I only had the last 24 hours selected, I didn't realize the output was actually wrong:&lt;/P&gt;

&lt;P&gt;Search Result:&lt;/P&gt;

&lt;P&gt;227 ruff 205.181.75.173  Quit&lt;BR /&gt;
        root 62.164.252.90 Query&lt;BR /&gt;
&amp;lt;---space                       -&amp;gt; Connect&lt;BR /&gt;
&amp;lt;---space                       -&amp;gt;Connect&lt;BR /&gt;
&amp;lt;---space                       -&amp;gt;Connect&lt;/P&gt;

&lt;P&gt;RAW Data:&lt;BR /&gt;
2018-05-16T18:15:52.691468Z 227 Quit&lt;BR /&gt;
2018-05-16T18:15:49.213672Z 227 Query   select @@version_comment limit 1&lt;BR /&gt;
2018-05-16T18:15:49.136165Z 227 Connect &lt;A href="mailto:ruff@205.181.75.173"&gt;ruff@205.181.75.173&lt;/A&gt; on using TCP/IP&lt;BR /&gt;
2018-05-11T18:19:41.688250Z 227 Connect Access denied for user 'root'@'62.164.252.90' (using password: YES)&lt;BR /&gt;
2018-05-11T18:19:41.688086Z 227 Connect &lt;A href="mailto:root@62.164.252.90"&gt;root@62.164.252.90&lt;/A&gt; on mysql using TCP/IP&lt;/P&gt;

&lt;P&gt;It looks like the ID is recycled as ID 227 has multiple dates.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 20:30:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403139#M116650</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T20:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403140#M116651</link>
      <description>&lt;P&gt;After correctly expanding the time field (I only had 24 hours selected)and changing the _time to _raw, here's the output:&lt;/P&gt;

&lt;P&gt;227 &lt;BR /&gt;
2018-05-16T18:15:52.691468Z 227 Quit                                            Quit&lt;BR /&gt;
2018-05-16T18:15:49.213672Z 227 Query   select @@version_comment limit 1                        Query&lt;BR /&gt;
2018-05-16T18:15:49.136165Z 227 Connect &lt;A href="mailto:SCADA@205.181.75.173"&gt;SCADA@205.181.75.173&lt;/A&gt; on using TCP/IP                        Connect&lt;BR /&gt;
2018-05-11T18:19:41.688250Z 227 Connect Access denied for user 'root'@'62.164.252.90' (using password: YES)     Connect&lt;BR /&gt;
2018-05-11T18:19:41.688086Z 227 Connect &lt;A href="mailto:root@62.164.252.90"&gt;root@62.164.252.90&lt;/A&gt; on mysql using TCP/IP                    Conn&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 20:33:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403140#M116651</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-17T20:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403141#M116652</link>
      <description>&lt;P&gt;If your ID is getting recycled, you'd have to make some assumption about the max time when ID will be recycled. Lets assuming an ID remains unique for a session at least for a day (it's not getting recycled same day), they try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
 | rex "^\S+\s+(?&amp;lt;ID&amp;gt;\S+)\s+(?&amp;lt;Action&amp;gt;\S+)" | eval date=strftime(_time,"%F")
 | stats list(_time) as _raw list(Action) as Action by ID date
 | where isnotnull(mvfind(Action,"Connect")) AND isnotnull(mvfind(Action,"Query"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 May 2018 21:47:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403141#M116652</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-17T21:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403142#M116653</link>
      <description>&lt;P&gt;That seemed to work, spot on.  Since you didn't answer this in the normal answer block, I can't upvote or select this as good.  If you put it in the answer block, I can give you credit.&lt;/P&gt;

&lt;P&gt;Again, thanks!!!&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 14:03:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403142#M116653</guid>
      <dc:creator>richnsanders_70</dc:creator>
      <dc:date>2018-05-18T14:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403143#M116654</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;I think you can use transaction command with maxspan and get the results,&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 14:29:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403143#M116654</guid>
      <dc:creator>kvswathi</dc:creator>
      <dc:date>2018-05-18T14:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to search logs for values on multiple lines?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403144#M116655</link>
      <description>&lt;P&gt;Here you go.&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 15:51:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-logs-for-values-on-multiple-lines/m-p/403144#M116655</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-18T15:51:09Z</dc:date>
    </item>
  </channel>
</rss>

