<?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 Conditional If statement in search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-If-statement-in-search/m-p/60128#M14791</link>
    <description>&lt;P&gt;All,&lt;/P&gt;

&lt;P&gt;I have a search that is looking for two specific events.  One is for new 2008 OS's and up, the other is 2003 OS's and below. &lt;/P&gt;

&lt;P&gt;The problem that I am seeing is that the difference between the two log formats is the mufti-valued Account_Name in the 2008 Os's on up (event id 4624).  I can solve the problem by looking for the second value of Account_Name, but when I do that, the results for event id 528 fail to pass the eval test and never show in the results.  &lt;/P&gt;

&lt;P&gt;It seems that I need a conditional if statement to only eval the Account_Name value if the event id is 4624 present first. I also been toying with the idea of having a count of repeated Account_Name and User_Name values per host (so if user X logs in multiple times, then I would only see one entry per host for that user with a total amount of connections), but not sure where in the search statement that "count" would need to occur.&lt;/P&gt;

&lt;P&gt;Below is my current search string.  Any help would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;source="wineventlog:security" (EventCode="4624" OR EventCode="528") (Logon_Type="2" OR Logon_Type="10") | eval Account_Name=mvindex(Account_Name, -1) | search Account_Name!=scom* AND Account_Name!=esx* | table host, EventCode, User_Name, Account_Name, Source_Network_Address, _time, Logon_Type | sort by host&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 09:48:27 GMT</pubDate>
    <dc:creator>jcrensh</dc:creator>
    <dc:date>2020-09-28T09:48:27Z</dc:date>
    <item>
      <title>Conditional If statement in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-If-statement-in-search/m-p/60128#M14791</link>
      <description>&lt;P&gt;All,&lt;/P&gt;

&lt;P&gt;I have a search that is looking for two specific events.  One is for new 2008 OS's and up, the other is 2003 OS's and below. &lt;/P&gt;

&lt;P&gt;The problem that I am seeing is that the difference between the two log formats is the mufti-valued Account_Name in the 2008 Os's on up (event id 4624).  I can solve the problem by looking for the second value of Account_Name, but when I do that, the results for event id 528 fail to pass the eval test and never show in the results.  &lt;/P&gt;

&lt;P&gt;It seems that I need a conditional if statement to only eval the Account_Name value if the event id is 4624 present first. I also been toying with the idea of having a count of repeated Account_Name and User_Name values per host (so if user X logs in multiple times, then I would only see one entry per host for that user with a total amount of connections), but not sure where in the search statement that "count" would need to occur.&lt;/P&gt;

&lt;P&gt;Below is my current search string.  Any help would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;source="wineventlog:security" (EventCode="4624" OR EventCode="528") (Logon_Type="2" OR Logon_Type="10") | eval Account_Name=mvindex(Account_Name, -1) | search Account_Name!=scom* AND Account_Name!=esx* | table host, EventCode, User_Name, Account_Name, Source_Network_Address, _time, Logon_Type | sort by host&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-If-statement-in-search/m-p/60128#M14791</guid>
      <dc:creator>jcrensh</dc:creator>
      <dc:date>2020-09-28T09:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional If statement in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-If-statement-in-search/m-p/60129#M14792</link>
      <description>&lt;P&gt;I think I understand what you are trying to do, just to rephrase, IF event_id=4624, you want account_name to be set to the 2nd value in the multi value field account_name, otherwise you want it to remain the value it's already set to?&lt;/P&gt;

&lt;P&gt;something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Account_Name=if(EventCode="4624",mvindex(Account_Name, -1),Account_Name)|
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2011 17:04:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-If-statement-in-search/m-p/60129#M14792</guid>
      <dc:creator>bbingham</dc:creator>
      <dc:date>2011-08-18T17:04:37Z</dc:date>
    </item>
  </channel>
</rss>

