<?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 perform branching to different SPL commands based on the value of a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428928#M122686</link>
    <description>&lt;P&gt;Run line number 9 to 12 in separate search and check the result. What ever the result you get here the same you will get with append, as append is not any rocket science it just append multiple result set.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2019 07:07:11 GMT</pubDate>
    <dc:creator>VatsalJagani</dc:creator>
    <dc:date>2019-06-20T07:07:11Z</dc:date>
    <item>
      <title>How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428923#M122681</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
Novice, but getting better. I am searching the Internet, Splunk Docs, and Splunk Answers for an answer. Meanwhile, I figured to post my issue.&lt;/P&gt;

&lt;P&gt;After the general search commands (index, sourcetype, etc.) I want to perform branching to different SPL commands based on the value of a field.&lt;/P&gt;

&lt;P&gt;For example in pseudo code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if process=snmpd
(| rex message=(blah, blah, blah)
| stats count(process), blah, blah, blah)
if process=sudo
(| rex message=(blah, blah, blah)
| stats count(process), blah, blah, blah)
etc., etc.,.....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm figuring this will be a combination of &lt;STRONG&gt;where&lt;/STRONG&gt;, &lt;STRONG&gt;eval&lt;/STRONG&gt;, &lt;STRONG&gt;case&lt;/STRONG&gt;. However,I haven't figured out which one or combinations this would be.&lt;/P&gt;

&lt;P&gt;I will continue to research and test. And any guidance or direction is appreciated. &lt;/P&gt;

&lt;P&gt;Thanks in advance and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 13:15:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428923#M122681</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-06-19T13:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428924#M122682</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/116827"&gt;@genesiusj&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;It depends on your use case, let me give you one example in which I want to extract field id from field either message1, message2 or message3 based on value of event_id field.&lt;BR /&gt;
event_id=2, then I need to apply regex  &lt;CODE&gt;(?&amp;lt;id&amp;gt;\d+)&lt;/CODE&gt; on message2 field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval message=case(event_id==1,message1, event_id==2, message2, event_id==3, message3)
| rex field=message "(?&amp;lt;id&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But yeah this is not a programming script so we need to find some approach based on use-cases. If you can explain your use-case explicitly I can guide.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:58:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428924#M122682</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2020-09-30T00:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428925#M122683</link>
      <description>&lt;P&gt;@VatsalJagani &lt;BR /&gt;
The events are from &lt;EM&gt;rsyslog&lt;/EM&gt;. Based on the value of the field &lt;STRONG&gt;process&lt;/STRONG&gt; (&lt;STRONG&gt;snmpd&lt;/STRONG&gt;, &lt;STRONG&gt;sudo&lt;/STRONG&gt;, &lt;STRONG&gt;crond&lt;/STRONG&gt;, etc.) within the &lt;EM&gt;rsyslog&lt;/EM&gt; event, I want to create new fields using the &lt;STRONG&gt;rex&lt;/STRONG&gt; commands against &lt;EM&gt;_raw&lt;/EM&gt;. I am using &lt;EM&gt;_raw&lt;/EM&gt; because the information I am looking for is not in a predesignated field during ingest time.&lt;/P&gt;

&lt;P&gt;Here is the SPL I have thus far, which works. But I need to have each of the different values for &lt;STRONG&gt;process&lt;/STRONG&gt; run a different set of &lt;STRONG&gt;rex&lt;/STRONG&gt; &lt;STRONG&gt;rename&lt;/STRONG&gt; and &lt;STRONG&gt;stats&lt;/STRONG&gt; commands.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=linuxevents Connection
| rex field=_raw "]:\s+(?&amp;lt;SyslogMsg&amp;gt;.*$)"
| rex field=SyslogMsg "\[(?&amp;lt;SrcIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})"
| rex field=SyslogMsg "\[\S*\[(?&amp;lt;DstIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})"
| rename process as Process
| stats count by SrcIP, DstIP, Process
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is an event with the word "Connection" inside _raw.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Jun 19 10:24:58 apps21 snmpd[9900]: Connection from UDP: [10.111.77.106]:60418-&amp;gt;[10.222.143.6]:161&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Here is a sample from the Statistics tab after running the search.&lt;/P&gt;

&lt;P&gt;SrcIP                   DstIP             Process   count&lt;BR /&gt;
10.111.77.100   10.222.143.6      snmpd         512&lt;/P&gt;

&lt;P&gt;However, an event with &lt;STRONG&gt;sudo&lt;/STRONG&gt; as the process would generate a different SyslogMsg from the &lt;STRONG&gt;rex&lt;/STRONG&gt; command.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Jun 19 10:02:53 snk30 sudo: pam_unix(sudo:session): session opened for user root by onnyd(uid=0)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I have not written the &lt;STRONG&gt;rex&lt;/STRONG&gt; and other commands for this yet, but I want to &lt;STRONG&gt;rex&lt;/STRONG&gt; SyslogMsg for &lt;EM&gt;pam_unix&lt;/EM&gt; into a Command field; &lt;EM&gt;opened&lt;/EM&gt; into an Action field; &lt;EM&gt;onnyd&lt;/EM&gt; into a User field; etc.&lt;/P&gt;

&lt;P&gt;There are over 30 possible values for process. I don't want to create a separate search for each one.&lt;/P&gt;

&lt;P&gt;I hope this clarifies what I am attempting to do.&lt;/P&gt;

&lt;P&gt;I went to this site, &lt;A href="https://splunkonbigdata.com"&gt;https://splunkonbigdata.com&lt;/A&gt;, but so far I have not been able to find an answer.&lt;/P&gt;

&lt;P&gt;Thanks for your help and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:46:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428925#M122683</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-06-19T14:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428926#M122684</link>
      <description>&lt;P&gt;Hi @genesiusj,&lt;/P&gt;

&lt;P&gt;If you just want to extract different field based on some value then please use regex with that text specified like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "snmpd\[\d+\]\:\s+.*\[(?&amp;lt;SrcIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\]:\d+-&amp;gt;\[(?&amp;lt;DstIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\]:\d+"
| rex field=_raw "sudo:\s+(?&amp;lt;Command&amp;gt;[^(]+)\(sudo:session\):\s+session\s+(?&amp;lt;Action&amp;gt;[^\s]+)\sfor user root by (?&amp;lt;user&amp;gt;[^\(]+)\(uid=0\)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But apart from field extraction you want so many more operations also you can use  &lt;CODE&gt;append&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=linuxevents Connection sudo
 | rex field=_raw "]:\s+(?&amp;lt;SyslogMsg&amp;gt;.*$)"
 | rex field=SyslogMsg "\[(?&amp;lt;SrcIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})"
......
| append [
search index=linuxevents Connection sudo
 | rex field=_raw "sudo:\s+(?&amp;lt;Command&amp;gt;[^(]+)\(sudo:session\):\s+session\s+(?&amp;lt;Action&amp;gt;[^\s]+)\sfor user root by (?&amp;lt;user&amp;gt;[^\(]+)\(uid=0\)"
......
]
...... &amp;lt;some other common operations&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Before using  &lt;CODE&gt;append [ ]&lt;/CODE&gt; command, just take care of sub-search command limitation. By default sub-search returns only first 10k results, you can change this limit from limits.conf file.&lt;/P&gt;

&lt;P&gt;Hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 16:20:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428926#M122684</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-19T16:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428927#M122685</link>
      <description>&lt;P&gt;@VatsalJagani &lt;BR /&gt;
Thanks.&lt;BR /&gt;
I know I am &lt;STRONG&gt;misunderstanding&lt;/STRONG&gt; something here.&lt;/P&gt;

&lt;P&gt;The below  SPL returns 14,356 events, and the same number of rows in the Statistics tab. The rows in the Statistics tab contain &lt;STRONG&gt;SrcIP&lt;/STRONG&gt; and &lt;STRONG&gt;DstIP&lt;/STRONG&gt;, as well as the SyslogMsg from the &lt;STRONG&gt;rex&lt;/STRONG&gt; commands in the first &lt;STRONG&gt;append&lt;/STRONG&gt; (lines 4-6). However, the rows from the &lt;STRONG&gt;rex&lt;/STRONG&gt; commands in the second &lt;STRONG&gt;append&lt;/STRONG&gt; (lines 10-12) are completely blank.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  1.  index=prod_linuxevents process="sudo" OR process="snmpd"
  2.  | append [ 
  3.   search index=prod_linuxevents process="snmpd"
  4.  | rex field=_raw "]:\s+(?&amp;lt;SyslogMsg&amp;gt;.*$)"
  5.  | rex field=SyslogMsg "\[(?&amp;lt;SrcIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})"
  6.  | rex field=SyslogMsg "\[\S*\[(?&amp;lt;DstIP&amp;gt;\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})"
  7.  ]
  8.  | append [
  9.  search index=prod_linuxevents process="sudo"
10.  | rex field=_raw "]:\s+(?&amp;lt;SyslogMsg&amp;gt;.*$)"
11.  | rex field=SyslogMsg "\.*root by (?&amp;lt;SudoID&amp;gt;\w{1,10})"
12.  | rex field=SyslogMsg "\.*COMMAND=(?&amp;lt;SudoCommand&amp;gt;.*$)"
13.  ]
14.  | table SyslogMsg, SrcIP, DstIP, SudoID, SudoCommand
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 20:14:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428927#M122685</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-06-19T20:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428928#M122686</link>
      <description>&lt;P&gt;Run line number 9 to 12 in separate search and check the result. What ever the result you get here the same you will get with append, as append is not any rocket science it just append multiple result set.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 07:07:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428928#M122686</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-20T07:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428929#M122687</link>
      <description>&lt;P&gt;@Vatsal&lt;BR /&gt;
Again, thank you so much for your help.&lt;BR /&gt;
I had a typo during my cut and paste.&lt;BR /&gt;
The first rex command creating SyslogMsg in each append were identical. This didn't work because _raw  is different for each process value.&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 15:49:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428929#M122687</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-06-21T15:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform branching to different SPL commands based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428930#M122688</link>
      <description>&lt;P&gt;@VatsalJagani &lt;BR /&gt;
As this is a new Splunk implementation, before I get a chance to complete one thing, another is tossed our way.&lt;BR /&gt;
I am getting back to old forum posts to Accept answers from those who have directed me down the correct path.&lt;BR /&gt;
Apologies for the delay.&lt;BR /&gt;
Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 13:26:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-branching-to-different-SPL-commands-based-on-the/m-p/428930#M122688</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-09-26T13:26:20Z</dc:date>
    </item>
  </channel>
</rss>

