<?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 Regex the second occurrence of Account Name in AD logs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456175#M128975</link>
    <description>&lt;P&gt;If using rex (there are other KV extraction options using transforms) then you can pass it its &lt;STRONG&gt;max_match&lt;/STRONG&gt; option and, if "Account Name" is found twice, then the &lt;STRONG&gt;disabled&lt;/STRONG&gt; field will be multi-valued, which can then be tested for both fields with the 2nd field being set, as below&lt;BR /&gt;
...&lt;BR /&gt;
| rex field=Message max_match=2 "Account Name: (?.+)"&lt;BR /&gt;
| eval disabled=if(mvcount(disabled)=2, mvindex(disabled, 1), disabled)&lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 22:17:05 GMT</pubDate>
    <dc:creator>yeahnah</dc:creator>
    <dc:date>2019-05-15T22:17:05Z</dc:date>
    <item>
      <title>How to Regex the second occurrence of Account Name in AD logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456173#M128973</link>
      <description>&lt;P&gt;I need to filter AD logs with Event Code 4725 "A user account was disabled".&lt;BR /&gt;
I need to regex and filter the second occurrence of "Account Name:" so that I can further filter by account names.&lt;BR /&gt;
The specific issue is that in each event Message there is a "Service Account Name" associated with the "Target Account:  Account Name:"   And I only want the Account Name under the Target Account.&lt;/P&gt;

&lt;P&gt;Although the formatting is not indented correctly, this is a typical 4725 event.&lt;/P&gt;

&lt;P&gt;05/02/2019 10:32:13 AM&lt;BR /&gt;
LogName=Security&lt;BR /&gt;
SourceName=Microsoft Windows security auditing.&lt;BR /&gt;
EventCode=4725&lt;BR /&gt;
EventType=0&lt;BR /&gt;
... 1 line omitted ...&lt;BR /&gt;
ComputerName=123.ds.abc.com&lt;BR /&gt;
TaskCategory=User Account Management&lt;BR /&gt;
OpCode=Info&lt;BR /&gt;
RecordNumber=63515116&lt;BR /&gt;
Keywords=Audit Success&lt;BR /&gt;
Message=A user account was disabled.&lt;BR /&gt;
Subject:&lt;BR /&gt;
    Security ID:        S-132121123131213&lt;BR /&gt;
    Account Name:       Blah-service&lt;BR /&gt;
    Account Domain:     DS&lt;BR /&gt;
    Logon ID:       0x2ea0e04f8&lt;BR /&gt;
Target Account:&lt;BR /&gt;
    Security ID:        S-456454313131321&lt;BR /&gt;
    Account Name:       BlahBlah&lt;BR /&gt;
    Account Domain:     DS&lt;/P&gt;

&lt;P&gt;In Regex 101 I can capture the value I need but in splunk I cannot get the rex to work.&lt;/P&gt;

&lt;P&gt;Currently I have &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main  sourcetype=AD_logs EventCode="4725" | rex field = Message "Account Name\:\s+(?&amp;lt;disabled&amp;gt;.+)" | table disabled
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but this only gives me the first Account Name: Blah-service when I need the second Account Name: BlahBlah&lt;/P&gt;

&lt;P&gt;I cannot find a good example of how to match on the second occurrence of 'Account Name'.&lt;/P&gt;

&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 21:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456173#M128973</guid>
      <dc:creator>Log_wrangler</dc:creator>
      <dc:date>2019-05-15T21:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Regex the second occurrence of Account Name in AD logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456174#M128974</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Give a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query......| rex field=message max_match=0 "Account Name\:\s+(?P&amp;lt;disabled&amp;gt;.+)" 
| eval disabled= mvindex(disabled,1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 22:08:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456174#M128974</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-05-15T22:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Regex the second occurrence of Account Name in AD logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456175#M128975</link>
      <description>&lt;P&gt;If using rex (there are other KV extraction options using transforms) then you can pass it its &lt;STRONG&gt;max_match&lt;/STRONG&gt; option and, if "Account Name" is found twice, then the &lt;STRONG&gt;disabled&lt;/STRONG&gt; field will be multi-valued, which can then be tested for both fields with the 2nd field being set, as below&lt;BR /&gt;
...&lt;BR /&gt;
| rex field=Message max_match=2 "Account Name: (?.+)"&lt;BR /&gt;
| eval disabled=if(mvcount(disabled)=2, mvindex(disabled, 1), disabled)&lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 22:17:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456175#M128975</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2019-05-15T22:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to Regex the second occurrence of Account Name in AD logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456176#M128976</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 14:21:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Regex-the-second-occurrence-of-Account-Name-in-AD-logs/m-p/456176#M128976</guid>
      <dc:creator>Log_wrangler</dc:creator>
      <dc:date>2019-05-16T14:21:30Z</dc:date>
    </item>
  </channel>
</rss>

