<?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 Can you help me compare two searches and then print the difference? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420915#M167159</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am using two searches for seeking two windows events 4732 and 4733. I want to print into a new table events which registered only one of two events. For example, usually when local admin add in any groups at servers windows, a security event with number 4732 is created. And after deleting this user, Windows creates the new event 4733. &lt;/P&gt;

&lt;P&gt;I want to try find in events 4732 or 4733, which ones registered only in one of events 4732 or 4733.&lt;/P&gt;

&lt;P&gt;I used search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 ) OR (source="WinEventLog:Sec*" index="wineventlog" EventCode=4733) | rex field=_raw "Message=(?\S+.*)" | eval Description=Descript | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?\S+)" | eval CDSID=UserName | rex field=_raw "Member:\s+Security ID:\s+(?\S+)" | eval MCDSID=MemberName | rex field=_raw "Group:\s+.*\s+Group Name:\s+(?\S+.*)" | eval LocalGroup=GName | rename host as Host EventCode as "Event Code" MCDSID as "Member Name" LocalGroup as "Local Group" _time as Date | stats Count by Host, "Event Code", Description, CDSID, "Member Name", "Local Group", Date | fieldformat Date =strftime(Date,"%x %X") | table Host, "Event Code", Description, CDSID, "Member Name", "Local Group", Date, Count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I compare and print only unique event which not the same account name in both events 4732 and 4733 at the same time? &lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 07:20:53 GMT</pubDate>
    <dc:creator>atyshke1</dc:creator>
    <dc:date>2018-10-09T07:20:53Z</dc:date>
    <item>
      <title>Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420915#M167159</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am using two searches for seeking two windows events 4732 and 4733. I want to print into a new table events which registered only one of two events. For example, usually when local admin add in any groups at servers windows, a security event with number 4732 is created. And after deleting this user, Windows creates the new event 4733. &lt;/P&gt;

&lt;P&gt;I want to try find in events 4732 or 4733, which ones registered only in one of events 4732 or 4733.&lt;/P&gt;

&lt;P&gt;I used search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 ) OR (source="WinEventLog:Sec*" index="wineventlog" EventCode=4733) | rex field=_raw "Message=(?\S+.*)" | eval Description=Descript | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?\S+)" | eval CDSID=UserName | rex field=_raw "Member:\s+Security ID:\s+(?\S+)" | eval MCDSID=MemberName | rex field=_raw "Group:\s+.*\s+Group Name:\s+(?\S+.*)" | eval LocalGroup=GName | rename host as Host EventCode as "Event Code" MCDSID as "Member Name" LocalGroup as "Local Group" _time as Date | stats Count by Host, "Event Code", Description, CDSID, "Member Name", "Local Group", Date | fieldformat Date =strftime(Date,"%x %X") | table Host, "Event Code", Description, CDSID, "Member Name", "Local Group", Date, Count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I compare and print only unique event which not the same account name in both events 4732 and 4733 at the same time? &lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 07:20:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420915#M167159</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-09T07:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420916#M167160</link>
      <description>&lt;P&gt;If i understood correctly you need to find the "orphaned" accounts that do not have BOTH events 4732 and 4733.&lt;BR /&gt;
In this case i can suggest simply to group by account &lt;CODE&gt;| stats list(EventCode) by "Account Name" | where mvcount(EventCode)&amp;lt;2&lt;/CODE&gt;&lt;BR /&gt;
Obviously this will work only if the accounts and Event Codes are uniques (no single account can have more than 1 event 4732 and 1 4733 event)&lt;/P&gt;

&lt;P&gt;If this is not the case then you need first to group the events in different transactions, then apply the evaluation: something like &lt;CODE&gt;| transaction Host "Account Name" startswith=4732 endswith=4733 | where mvcount(EventCode)&amp;lt;2 | table _time "Account Name" EventCode&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 10:33:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420916#M167160</guid>
      <dc:creator>jlelli</dc:creator>
      <dc:date>2018-10-09T10:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420917#M167161</link>
      <description>&lt;P&gt;Yes, you are right, I need to find the "orphaned" accounts. I tried both codes and didn't work &lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 11:55:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420917#M167161</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-09T11:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420918#M167162</link>
      <description>&lt;P&gt;The first code is work. But the second not.&lt;BR /&gt;
I use next search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 ) OR (source="WinEventLog:Sec*" index="wineventlog" EventCode=4733) | rex field=_raw "Message=(?&amp;lt;Descript&amp;gt;\S+.*)" | eval Description=Descript | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?&amp;lt;UserName&amp;gt;\S+)" | eval CDSID=UserName | rex field=_raw "Member:\s+Security ID:\s+(?&amp;lt;MemberName&amp;gt;\S+)" | eval MCDSID=MemberName | rex field=_raw "Group:\s+.*\s+Group Name:\s+(?&amp;lt;GName&amp;gt;\S+.*)" | eval LocalGroup=GName | rename host as Host EventCode as "Event Code" MCDSID as "Member Name" LocalGroup as "Local Group" _time as Date | fieldformat Date =strftime(Date,"%x %X") | transaction Host "Member Name" startswith="4732" endswith="4733" | where mvcount("Event Code")&amp;lt;2 | table Date, "Member Name", "Event Code"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 12:56:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420918#M167162</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-09T12:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420919#M167163</link>
      <description>&lt;P&gt;I'm not familiar with Windows Security Logs and your query uses a logic that i don't fully understand; if you need a test string i need a sample of the event.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 12:59:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420919#M167163</guid>
      <dc:creator>jlelli</dc:creator>
      <dc:date>2018-10-09T12:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420920#M167164</link>
      <description>&lt;P&gt;This is example of event code 4732:&lt;/P&gt;

&lt;P&gt;09/28/2018 02:42:44 PM&lt;BR /&gt;
LogName=Security&lt;BR /&gt;
SourceName=Microsoft Windows security auditing.&lt;BR /&gt;
EventCode=4732&lt;BR /&gt;
EventType=0&lt;BR /&gt;
Type=Information&lt;BR /&gt;
ComputerName=ser02056.servers.fo.com&lt;BR /&gt;
TaskCategory=Security Group Management&lt;BR /&gt;
OpCode=Info&lt;BR /&gt;
RecordNumber=17799424&lt;BR /&gt;
Keywords=Audit Success&lt;BR /&gt;
Message=A member was added to a security-enabled local group.&lt;/P&gt;

&lt;P&gt;Subject:&lt;BR /&gt;
    Security ID:        FOEU1\$LKRUD&lt;BR /&gt;
    Account Name:       $LKRUD&lt;BR /&gt;
    Account Domain:     FOEU1&lt;BR /&gt;
    Logon ID:       0x72857CA&lt;/P&gt;

&lt;P&gt;Member:&lt;BR /&gt;
    Security ID:        FOEU1\AAGURI&lt;BR /&gt;
    Account Name:       -&lt;/P&gt;

&lt;P&gt;Group:&lt;BR /&gt;
    Security ID:        BUILTIN\Administrators&lt;BR /&gt;
    Group Name:     Administrators&lt;BR /&gt;
    Group Domain:       Builtin&lt;/P&gt;

&lt;P&gt;Additional Information:&lt;BR /&gt;
    Privileges:     -&lt;/P&gt;

&lt;P&gt;The log for 4733 is the same. Different only with description "Message=A member was added to a security-enabled local group."&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 13:07:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420920#M167164</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-09T13:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420921#M167165</link>
      <description>&lt;P&gt;I don't understand the reason for all the field extraction, eval and renaming; so i took some liberties in the query. Try instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 OR EventCode=4733 
| rex "Security ID:\s+(?&amp;lt;MemberName&amp;gt;.*)" 
| rex "Account Name:\s+(?&amp;lt;UserName&amp;gt;.*)"  
| rex "Group Name:\s+(?&amp;lt;GName&amp;gt;.*)"  
| transaction host MemberName startswith="4732" endswith="4733"
| where mvcount(EventCode)&amp;lt;2 
| eval Date=strftime(_time, "%d/%y") 
| table Date MemberName EventCode 
| rename MemberName as "Member Name" EventCode as "EventCode"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the Windows Security ID has matches this should work, otherwise you can try to match the Account Name replacing the transaction and table lines with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction host UserName startswith="4732" endswith="4733" 

| table Date, UserName, EventCode 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:23:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420921#M167165</guid>
      <dc:creator>jlelli</dc:creator>
      <dc:date>2018-10-09T14:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420922#M167166</link>
      <description>&lt;P&gt;The first code is working. But the is second not.&lt;BR /&gt;
I use next search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 ) OR (source="WinEventLog:Sec*" index="wineventlog" EventCode=4733) | rex field=_raw "Message=(?&amp;lt;Descript&amp;gt;\S+.*)" | eval Description=Descript | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?&amp;lt;UserName&amp;gt;\S+)" | eval CDSID=UserName | rex field=_raw "Member:\s+Security ID:\s+(?&amp;lt;MemberName&amp;gt;\S+)" | eval MCDSID=MemberName | rex field=_raw "Group:\s+.*\s+Group Name:\s+(?&amp;lt;GName&amp;gt;\S+.*)" | eval LocalGroup=GName | rename host as Host EventCode as "Event Code" MCDSID as "Member Name" LocalGroup as "Local Group" _time as Date | fieldformat Date =strftime(Date,"%x %X") | transaction Host "Member Name" startswith="4732" endswith="4733" | where mvcount("Event Code")&amp;lt;2 | table Date, "Member Name", "Event Code"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:23:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420922#M167166</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-09T14:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420923#M167167</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I don't understand the reason for all the field extraction, eval and renaming&lt;BR /&gt;
I need extract the fields which has contains in only one of two events 4732 or 4733 for accounts&lt;BR /&gt;
I want report if account in 4732 or 4733 that allow me understand that account was added or deleted. If event for account registered in 4732 and 4733 that told is ok. Account was added and deleted. But if account only in one of 4732 or 4733 that is tell us we need to check why the account registered in only one event 4732 or 4733 &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I tried the search code:&lt;BR /&gt;
&lt;CODE&gt;source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 OR EventCode=4733 &lt;BR /&gt;
 | rex "Security ID:\s+(?.*)" &lt;BR /&gt;
 | rex "Account Name:\s+(?.*)"  &lt;BR /&gt;
 | rex "Group Name:\s+(?.*)"  &lt;BR /&gt;
 | transaction host MemberName startswith="4732" endswith="4733"&lt;BR /&gt;
 | where mvcount(EventCode)&amp;lt;2 &lt;BR /&gt;
 | eval Date=strftime(_time, "%d/%y") &lt;BR /&gt;
 | table Date MemberName EventCode &lt;BR /&gt;
 | rename MemberName as "Member Name" EventCode as "EventCode"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but it doesn't show me anything&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 05:13:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420923#M167167</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-10T05:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420924#M167168</link>
      <description>&lt;P&gt;Now I use this code:&lt;BR /&gt;
&lt;CODE&gt;source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 OR EventCode=4733 &lt;BR /&gt;
 | rex field=_raw "Message=(?\S+.*)"&lt;BR /&gt;
 | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?\S+.*)" &lt;BR /&gt;
 | rex field=_raw "Member:\s+Security ID:\s+(?\S+.*)" &lt;BR /&gt;
 | rex field=_raw "Group:\s+.*\s+Group Name:\s+(?\S+.*)" &lt;BR /&gt;
 | transaction host MemberName startswith=4732 endswith=4733&lt;BR /&gt;
 | where mvcount(MemberName)&amp;lt;2&lt;BR /&gt;
 | fieldformat Date=strftime(Date,"%x %X") &lt;BR /&gt;
 | table host, EventCode, Descript, UserName, MemberName, GName, _time&lt;BR /&gt;
 | rename host as Host EventCode as "Event Code" MemberName as "Member Name" GName as "Local Group" _time as Date Descript as Description UserName as CDSID&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;And it seems that it's work but it's work incorrect. For example, I know that first event in a pictures has in 4732 and 4733 events, but why search it show me??&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5905i78F28FF2CCFA9871/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 11:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420924#M167168</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-10T11:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420925#M167169</link>
      <description>&lt;P&gt;Please note that in the code i provided the verification of the single event is made by:&lt;BR /&gt;
&lt;CODE&gt;| transaction host MemberName startswith="4732" endswith="4733"&lt;/CODE&gt; (this creates a single event from the coupling of member-add / member-remove)&lt;BR /&gt;
&lt;CODE&gt;| where mvcount(EventCode)&amp;lt;2&lt;/CODE&gt;  (this excludes all the paired events, showing only the orphaned ones)&lt;/P&gt;

&lt;P&gt;In your search your have replaced the where  command with &lt;CODE&gt;| where mvcount(MemberName)&amp;lt;2&lt;/CODE&gt; and since the MemberName field is unique the filter does not work. Replace this with the original &lt;CODE&gt;| where mvcount(EventCode)&amp;lt;2&lt;/CODE&gt; and it should work fine.&lt;/P&gt;

&lt;P&gt;If no records are shown is because there are no Orphaned events, so try to change the time slice of the search or to increase the search range.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 13:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420925#M167169</guid>
      <dc:creator>jlelli</dc:creator>
      <dc:date>2018-10-10T13:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two searches and then print the difference?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420926#M167170</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;In your search your have replaced the where command with | where mvcount(MemberName)&amp;lt;2 and since the MemberName field is unique the filter does not work. Replace this with the original | where mvcount(EventCode)&amp;lt;2 and it should work fine.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Yeah, yeah you are right&lt;BR /&gt;
Thank you very much for excellent help!&lt;/P&gt;

&lt;P&gt;I use the next code and it seems works fine:&lt;BR /&gt;
&lt;CODE&gt;source="WinEventLog:Sec*" index="wineventlog" EventCode=4732 OR EventCode=4733 &lt;BR /&gt;
| rex field=_raw "Message=(?\S+.*)" | rex field=_raw "Subject:\s+.*\s+Account Name:\s+(?\S+.*)" &lt;BR /&gt;
| rex field=_raw "Member:\s+Security ID:\s+(?\S+.*)" &lt;BR /&gt;
| rex field=_raw "Group:\s+.*\s+Group Name:\s+(?\S+.*)" &lt;BR /&gt;
| transaction host MemberName | where mvcount(EventCode)&amp;lt;2 &lt;BR /&gt;
| fieldformat Date=strftime(Date,"%x %X") &lt;BR /&gt;
| table host, EventCode, Descript, UserName, MemberName, GName, _time &lt;BR /&gt;
| rename host as Host EventCode as "Event Code" MemberName as "Member Name" GName as "Local Group" _time as Date Descript as Description UserName as CDSID&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 13:15:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-searches-and-then-print-the/m-p/420926#M167170</guid>
      <dc:creator>atyshke1</dc:creator>
      <dc:date>2018-10-10T13:15:12Z</dc:date>
    </item>
  </channel>
</rss>

