<?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: splunk query to use regex on the basis of if statement. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646698#M223840</link>
    <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;For all &lt;STRONG&gt;"action"&lt;/STRONG&gt; we have separate &lt;STRONG&gt;regex,&lt;/STRONG&gt; we want to use &lt;STRONG&gt;regex&lt;/STRONG&gt; inside &lt;STRONG&gt;if&lt;/STRONG&gt; condition on the basis of &lt;STRONG&gt;"action"&lt;/STRONG&gt; matched.&lt;/P&gt;&lt;P&gt;so that it extract information from event that belongs to particular &lt;STRONG&gt;"action"&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;if (action = "A&lt;SPAN&gt;CCEPTED UPDATE", &amp;lt;apply regex3 to events matches with action)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if condition satisfied&amp;nbsp; for event apply &lt;STRONG&gt;regex&lt;/STRONG&gt; on that event, if not satisfied for event nothing to do.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Abhineet&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jun 2023 16:38:01 GMT</pubDate>
    <dc:creator>Abhineet</dc:creator>
    <dc:date>2023-06-12T16:38:01Z</dc:date>
    <item>
      <title>How to write a query to use regex on the basis of if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646693#M223838</link>
      <description>&lt;P&gt;HI,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for splunk query to use regex on the basis of if statement.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Query:&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;index=jfrog_index "org.artifactory.security.AccessLogger" NOT "127.0.0.1"&lt;BR /&gt;| rex field=_raw ".*AccessLogger \[(?&amp;lt;action&amp;gt;[\w\s]+)\].*"|dedup action|search action = "ACCEPTED*" | table action&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;OUTPUT:&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;action&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED DOWNLOAD&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED LOGIN&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED DELETE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED DEPLOY&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED UPDATE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED PROPERTY_UPDATED&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED CONFIGURATION_CHANGE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ACCEPTED BUILD_CREATE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want to use separate regex on the basis of action value with if condition so event matches with action mentioned above apply particular regex and filter out the information.&lt;/P&gt;
&lt;P&gt;As on the basis of action event format is different.&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;if (action = "ACCEPTED DOWNLOAD",&amp;lt;regex1&amp;gt;)&lt;/P&gt;
&lt;P&gt;if(action = "ACCEPTED LOGIN", &amp;lt;regex2&amp;gt;)&lt;/P&gt;
&lt;P&gt;regex1 =&amp;nbsp;.*[\s]+\d+ (?&amp;lt;time&amp;gt;[\d:]+) (?&amp;lt;HOST&amp;gt;[\w\d]+) \[(?&amp;lt;date&amp;gt;[\d-]+)T.*\].*AccessLogger \[.*\] (?&amp;lt;repo&amp;gt;[\w-]+):(?&amp;lt;package&amp;gt;.*) for client : (?&amp;lt;user&amp;gt;[\_\w\-\d]+) \/ (?&amp;lt;userIp&amp;gt;.*)\.&lt;/P&gt;
&lt;P&gt;Provide me Splunk query for above example to extract information for different format event for different action type.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Abhineet Kumar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 13:49:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646693#M223838</guid>
      <dc:creator>Abhineet</dc:creator>
      <dc:date>2023-06-13T13:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query to use regex on the basis of if statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646696#M223839</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236195"&gt;@Abhineet&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;make the two regex extractions and then the if condition, something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex ".*[\s]+\d+ (?&amp;lt;time1&amp;gt;[\d:]+) (?&amp;lt;HOST1&amp;gt;[\w\d]+) \[(?&amp;lt;date1&amp;gt;[\d-]+)T.*\].*AccessLogger \[.*\] (?&amp;lt;repo1&amp;gt;[\w-]+):(?&amp;lt;package1&amp;gt;.*) for client : (?&amp;lt;user1&amp;gt;[\_\w\-\d]+) \/ (?&amp;lt;userIp1&amp;gt;.*)\."
| rex ".*[\s]+\d+ (?&amp;lt;time2&amp;gt;[\d:]+) (?&amp;lt;HOST2&amp;gt;[\w\d]+) \[(?&amp;lt;date2&amp;gt;[\d-]+)T.*\].*AccessLogger \[.*\] (?&amp;lt;repo2&amp;gt;[\w-]+):(?&amp;lt;package2&amp;gt;.*) for client : (?&amp;lt;user2&amp;gt;[\_\w\-\d]+) \/ (?&amp;lt;userIp2&amp;gt;.*)\."
| eval 
   time=if(action="ACCEPTED DOWNLOAD",time1,time2),
   HOST=if(action="ACCEPTED DOWNLOAD",HOST1,HOST2),
   ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;you didn't shared regex 2, so I used the same regex to display the approach.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 16:29:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646696#M223839</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-06-12T16:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query to use regex on the basis of if statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646698#M223840</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;For all &lt;STRONG&gt;"action"&lt;/STRONG&gt; we have separate &lt;STRONG&gt;regex,&lt;/STRONG&gt; we want to use &lt;STRONG&gt;regex&lt;/STRONG&gt; inside &lt;STRONG&gt;if&lt;/STRONG&gt; condition on the basis of &lt;STRONG&gt;"action"&lt;/STRONG&gt; matched.&lt;/P&gt;&lt;P&gt;so that it extract information from event that belongs to particular &lt;STRONG&gt;"action"&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;if (action = "A&lt;SPAN&gt;CCEPTED UPDATE", &amp;lt;apply regex3 to events matches with action)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if condition satisfied&amp;nbsp; for event apply &lt;STRONG&gt;regex&lt;/STRONG&gt; on that event, if not satisfied for event nothing to do.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Abhineet&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 16:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646698#M223840</guid>
      <dc:creator>Abhineet</dc:creator>
      <dc:date>2023-06-12T16:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query to use regex on the basis of if statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646744#M223856</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236195"&gt;@Abhineet&lt;/a&gt;&amp;nbsp;.. running rex inside if condition looks like not possible.. but you can do like.. run two rex and then use the if condition to select your fields. (I just copy paste gcusello's SPL, adding ur base query)&lt;/P&gt;&lt;P&gt;pls update your rex2 and then whats your if condition requirement, then we can edit this SPL to match your requirement.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=jfrog_index "org.artifactory.security.AccessLogger" NOT "127.0.0.1"
| rex field=_raw ".*AccessLogger \[(?&amp;lt;action&amp;gt;[\w\s]+)\].*"|dedup action|search action = "ACCEPTED*" 
| rex ".*[\s]+\d+ (?&amp;lt;time1&amp;gt;[\d:]+) (?&amp;lt;HOST1&amp;gt;[\w\d]+) \[(?&amp;lt;date1&amp;gt;[\d-]+)T.*\].*AccessLogger \[.*\] (?&amp;lt;repo1&amp;gt;[\w-]+):(?&amp;lt;package1&amp;gt;.*) for client : (?&amp;lt;user1&amp;gt;[\_\w\-\d]+) \/ (?&amp;lt;userIp1&amp;gt;.*)\."
| rex ".*[\s]+\d+ (?&amp;lt;time2&amp;gt;[\d:]+) (?&amp;lt;HOST2&amp;gt;[\w\d]+) \[(?&amp;lt;date2&amp;gt;[\d-]+)T.*\].*AccessLogger \[.*\] (?&amp;lt;repo2&amp;gt;[\w-]+):(?&amp;lt;package2&amp;gt;.*) for client : (?&amp;lt;user2&amp;gt;[\_\w\-\d]+) \/ (?&amp;lt;userIp2&amp;gt;.*)\."
| eval 
   time=if(action="ACCEPTED DOWNLOAD",time1,time2),
   HOST=if(action="ACCEPTED DOWNLOAD",HOST1,HOST2),&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 04:43:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646744#M223856</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2023-06-13T04:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query to use regex on the basis of if statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646760#M223860</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236195"&gt;@Abhineet&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80737"&gt;@inventsekar&lt;/a&gt;&amp;nbsp;said, it isn't possible to insert a regex in an if statement, the only approach is the one I described, or the solution from &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80737"&gt;@inventsekar&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 06:32:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-query-to-use-regex-on-the-basis-of-if-statement/m-p/646760#M223860</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-06-13T06:32:25Z</dc:date>
    </item>
  </channel>
</rss>

