<?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: Comparing regex and print result if a specific condition is met in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Comparing-regex-and-print-result-if-a-specific-condition-is-met/m-p/98451#M25338</link>
    <description>&lt;P&gt;Looks like you want to use the regex command.&lt;/P&gt;

&lt;P&gt;"Removes or keeps results that match the specified regular expression."&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Regex"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Regex&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Oct 2013 00:21:50 GMT</pubDate>
    <dc:creator>Lucas_K</dc:creator>
    <dc:date>2013-10-15T00:21:50Z</dc:date>
    <item>
      <title>Comparing regex and print result if a specific condition is met</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-regex-and-print-result-if-a-specific-condition-is-met/m-p/98450#M25337</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I've searched through the Answers section, with not much help.  What I'd like to do is to parse a log entry, to collect specific fields, and to compare those fields against a known value.  If and only if the field(s) do not match a known value, print the result so I can create an alert for it.&lt;/P&gt;

&lt;P&gt;Sample log file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Oct  9 23:28:05 10.100.200.10 Juniper: 2013-10-10 00:28:05 - vpnhostXXX - [1.2.3.4] test_user(FOO-NC)[BarNC] - Network Connect: Session started for user with IP 10.10.10.10, hostname test_user_hostname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using the log sample above, I'd like to check that a particular user, "test_user" connects to the VPN using ONLY a known host, in this case, "test_user_hostname".  If "test_user" connects with a different host OR "test_user_hostname" connects with a different "test_user" ID, then I'd like to alert on it. &lt;/P&gt;

&lt;P&gt;This is the query I've constructed, thus far (using Regex generated from 'Extract Field'):&lt;/P&gt;

&lt;P&gt;... | rex "(?i) hostname (?P&lt;HOSTNAME&gt;.+)" | rex "(?i)^[^\[]*\[\d+\.\d+\.\d+\.\d+\]\s+(?P&lt;VPNUSERID&gt;[^\(]+)" &lt;/VPNUSERID&gt;&lt;/HOSTNAME&gt;&lt;/P&gt;

&lt;P&gt;Pseudocode:&lt;BR /&gt;
print search result IF test_user != test_user_hostname&lt;/P&gt;

&lt;P&gt;Test:&lt;BR /&gt;
If test_user connects with a host other than test_user_hostname, Splunk should return that result with the name of that host in the search result(s).&lt;/P&gt;

&lt;P&gt;I'm struggling with coming up with the appropriate conditional statement(s).  &lt;/P&gt;

&lt;P&gt;Any help is much appreciated.&lt;/P&gt;

&lt;P&gt;thanks,&lt;BR /&gt;
-mike&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:58:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-regex-and-print-result-if-a-specific-condition-is-met/m-p/98450#M25337</guid>
      <dc:creator>mtanadsk</dc:creator>
      <dc:date>2020-09-28T14:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing regex and print result if a specific condition is met</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-regex-and-print-result-if-a-specific-condition-is-met/m-p/98451#M25338</link>
      <description>&lt;P&gt;Looks like you want to use the regex command.&lt;/P&gt;

&lt;P&gt;"Removes or keeps results that match the specified regular expression."&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Regex"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Regex&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2013 00:21:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-regex-and-print-result-if-a-specific-condition-is-met/m-p/98451#M25338</guid>
      <dc:creator>Lucas_K</dc:creator>
      <dc:date>2013-10-15T00:21:50Z</dc:date>
    </item>
  </channel>
</rss>

