<?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: Can I use Eval to correlate two serial logs that have specific fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297064#M89604</link>
    <description>&lt;P&gt;Okay, SPL is not a programming language in that precise way.  You can accomplish what you are talking about with the &lt;CODE&gt;streamstats&lt;/CODE&gt; command.  It is MUCH cleaner, however, when there is some field in common.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your search that gets all the relevant events
 | sort 0 _time
 | eval mysource = if(category="a",source_ip,null())
 | streamstats current=f prior(mysource) as lastsource window=1
 | where category="B" AND isnotnull(lastsource)
 | table username lastsource
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Aug 2017 22:05:50 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-08-22T22:05:50Z</dc:date>
    <item>
      <title>Can I use Eval to correlate two serial logs that have specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297062#M89602</link>
      <description>&lt;P&gt;Not sure if that titled made sense but hopefully I can explain it better here:&lt;/P&gt;

&lt;P&gt;I am receiving sFTP logs from a host and I was able to manually extract new fields successfully and create several different reports, i.e. user login, failed logins, files downloaded etc., etc. ... Now I am attempting to correlate the external/source IP with the username that is associated with the external/source IP. The issue is that the external/source IP and the associating username are being indexed into separate lines. When someone is logging into the sFTP server the external/source IP is logged and the very next log that gets indexed is the username that just authenticated. &lt;BR /&gt;
So I was thinking if I could create a search that uses the if-this-then-that logic. For example, if Splunk sees a log with category=a and the very next log shows category=b then table the external/source ip (from category=a) and username (from category=b). I manually extracted the field titled 'category'. &lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:31:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297062#M89602</guid>
      <dc:creator>Jamaal</dc:creator>
      <dc:date>2017-08-22T15:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Eval to correlate two serial logs that have specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297063#M89603</link>
      <description>&lt;P&gt;TLDR;&lt;BR /&gt;
How to pull results only if one matching interesting field data is followed by a different matching interesting field. &lt;/P&gt;

&lt;P&gt;index=x sourcetype=x | if category=a is followed by category=b, table source_ip(from catgeory=a) username(from category=b)&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:35:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297063#M89603</guid>
      <dc:creator>Jamaal</dc:creator>
      <dc:date>2017-08-22T15:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Eval to correlate two serial logs that have specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297064#M89604</link>
      <description>&lt;P&gt;Okay, SPL is not a programming language in that precise way.  You can accomplish what you are talking about with the &lt;CODE&gt;streamstats&lt;/CODE&gt; command.  It is MUCH cleaner, however, when there is some field in common.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your search that gets all the relevant events
 | sort 0 _time
 | eval mysource = if(category="a",source_ip,null())
 | streamstats current=f prior(mysource) as lastsource window=1
 | where category="B" AND isnotnull(lastsource)
 | table username lastsource
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Aug 2017 22:05:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297064#M89604</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-22T22:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Eval to correlate two serial logs that have specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297065#M89605</link>
      <description>&lt;P&gt;Hi DalJeanis,&lt;/P&gt;

&lt;P&gt;Thank you for assisting me with this issue. I tried running the search string you provided but I get the following error message: "Error in 'streamstats' command: The argument 'prior(mysource)' is invalid.&lt;/P&gt;

&lt;P&gt;Here is what I copied and pasted into splunk:&lt;/P&gt;

&lt;P&gt;index=name sourcetype=name_sftp earliest=-1d@d latest=@d| sort 0 _time&lt;BR /&gt;
  | eval mysource = if(category="000",source_ip,null())&lt;BR /&gt;
  | streamstats current=f prior(mysource) as lastsource window=1&lt;BR /&gt;
  | where category="125" AND isnotnull(lastsource)&lt;BR /&gt;
  | table username lastsource&lt;/P&gt;

&lt;P&gt;Should I be swapping out "mysource" for maybe the name of the 'interesting field'?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297065#M89605</guid>
      <dc:creator>Jamaal</dc:creator>
      <dc:date>2020-09-29T15:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Eval to correlate two serial logs that have specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297066#M89606</link>
      <description>&lt;P&gt;DalJeanis,&lt;/P&gt;

&lt;P&gt;So re-reading your response, sounds like the logs would need to have a common field of some sort. Here is the raw log:&lt;/P&gt;

&lt;P&gt;2017-08-22 00:01:03.624; [00000C3C] {125} username has successfully authenticated via Password&lt;BR /&gt;
2017-08-22 00:01:03.610; [00000C3C] {121} username tries Password authentication&lt;BR /&gt;
2017-08-22 00:01:03.376; [00000C3C] {110} enforcing anti-hammering delay [0.20 secs]&lt;BR /&gt;
2017-08-22 00:01:03.288; [00000C3C] {120} username requests Password authentication&lt;BR /&gt;
2017-08-22 00:01:02.207; [000009A8] {000}         * x.x.x.x -&amp;gt; 1 active connections&lt;BR /&gt;
2017-08-22 00:01:02.207; [000009A8] {109} List of currently connected IP and count of per-IP connections:&lt;BR /&gt;
2017-08-22 00:01:02.113; [000009A8] {112} Optimizing socket configuration for better performance&lt;BR /&gt;
2017-08-22 00:01:02.113; [000009A8] {111} Incoming connection request from [x.x.x.x]&lt;/P&gt;

&lt;P&gt;so using the above logs, I was trying to see if I could possible correlate category={000} with category={125} maybe by time. So if the search see's category={000} and within say 5secs later if category={125} is listed, table source_ip(from category={000}) username(from category={125}).&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 20:53:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-use-Eval-to-correlate-two-serial-logs-that-have-specific/m-p/297066#M89606</guid>
      <dc:creator>Jamaal</dc:creator>
      <dc:date>2017-08-23T20:53:07Z</dc:date>
    </item>
  </channel>
</rss>

