<?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: New field with conditional value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/544768#M154268</link>
    <description>&lt;P&gt;Hi&amp;nbsp; -&amp;nbsp; I have an interestnig follow up..&lt;/P&gt;&lt;P&gt;The query section of code in my dashboard panel looks like this at the moment...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;query&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;index=myindex sourcetype=bla:linux:syslog host="server.bla.COM" ABCEVENT &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1124"))) as "Started"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND SUCCESS"))) as "Successful"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND FAILURE"))) as "Failed"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval Running=if(Started-(Successful+Failed) &amp;amp;gt;= 0, Started-(Successful+Failed), 0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| table Started, Running, Successful, Failed&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;lt;/query&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The field Running is a calculated field which works, but not well as it relies on data that may notbe unreliable.&lt;/P&gt;&lt;P&gt;I want to replace the value that is displayed for field Running with something like the following (based on new data I send to splunk). Idea is to fetch only the last occurence of this event from the past 5 minutes. The event returned will essentially include a count value that I want to extra and use in my panel as a statistic.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=myindex sourcetype=bla:linux:syslog host="server.bla.COM" ABCEVENT *NONSBS earliest=-5m | eventstats max(_time) as maxtime | where _time=maxtime&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When I do above as a regular Splunk search, I get a single event returned which is perfect.&lt;/P&gt;&lt;P&gt;I already created a field extraction which always shows up as an available field in my search results. It's called Jobs_Running.&lt;/P&gt;&lt;P&gt;What I would like to do is to replace this ...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| eval Running=if(Started-(Successful+Failed) &amp;amp;gt;= 0, Started-(Successful+Failed), 0)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;With something similar to the above search string, adapted to work within the existing panel, so that I can display the new value for "Running" along side the existing fields "Started", "Successful" and "Failed".&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;One thing I'm not sure about is whether I can pull in the already extracted field (Jobs_Running) that ia visible when I do a regular search or do I need to perform a field extraction on the fly?&lt;/P&gt;&lt;P&gt;The expression is:&amp;nbsp;&lt;SPAN&gt;^(?:[^ \n]* ){9}(?P&amp;lt;Jobs_Running&amp;gt;\d+)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Mar 2021 13:11:11 GMT</pubDate>
    <dc:creator>owulz</dc:creator>
    <dc:date>2021-03-22T13:11:11Z</dc:date>
    <item>
      <title>New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539629#M152616</link>
      <description>&lt;P&gt;I have a dashboard panel with a table that show 3 fields, each of which contain numeric values.&lt;/P&gt;&lt;P&gt;A) "Backups started (count)"&lt;/P&gt;&lt;P&gt;B) "Backups completed successfully (count)"&lt;/P&gt;&lt;P&gt;C) "Backups failed (count)"&lt;/P&gt;&lt;P&gt;I want to create a 4th field (D) "Backups in-progress" that simply calculates B-A.&lt;/P&gt;&lt;P&gt;I already have the logic to change the color of (D) if it's less than (A).&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 06:48:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539629#M152616</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-12T06:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539636#M152618</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231476"&gt;@owulz&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Are these fields in table columns or rows? Solution would be different. If you can share your current SPL of that creates that table, we can provide solution easier.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 07:38:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539636#M152618</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-02-12T07:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539638#M152620</link>
      <description>&lt;P&gt;Hi scelikok, thanks for answering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are fields created as part of a query search within a table, so each field is a column with a single status result each, so I get 3 columns.&lt;/P&gt;&lt;P&gt;Started, Successful, Failed.&lt;/P&gt;&lt;P&gt;I'm trying to dynamically calculate a 4th field that I'll insert between Started and Successful, to say InProgress.&lt;/P&gt;&lt;P&gt;For those three fields, taking the example of the first, after the index... sourcetype... host.... I have | stats count(eval(searchmatch("search string"))) as "Started". There are three of these. I assumed I'd be able to append something like&amp;nbsp;| eval diff(Successful-Started) as "InProgress"&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 07:50:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539638#M152620</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-12T07:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539643#M152623</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231476"&gt;@owulz&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It is clear now. You can use the eval command to calculate a new field (You are very close)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval InProgress = Successful-Started&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 Feb 2021 08:05:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539643#M152623</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-02-12T08:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539648#M152627</link>
      <description>&lt;P&gt;That worked a treat @&lt;SPAN&gt;scelikok&amp;nbsp;&lt;/SPAN&gt;- thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 08:42:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539648#M152627</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-12T08:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539669#M152635</link>
      <description>&lt;P&gt;Can I just ask a follow up?&lt;/P&gt;&lt;P&gt;My new field now works well. There are occasions where the value is &amp;lt;0. In such cases I want it to show 0. Any value 0 or above stays as is. I tried the following which is to create another field that checks the original newly created field and if &amp;lt;0, use 0 else use original value.&lt;/P&gt;&lt;P&gt;I get an error but not sure why. I had used a researched article.&lt;/P&gt;&lt;P&gt;index=a0_designeng_generic_app_audit_prd sourcetype=cba:designeng:as400:syslog host="MIDINT01.CBA.COM.AU"&lt;BR /&gt;| stats&lt;BR /&gt;count(eval(searchmatch("BACKUP AND CPF1124"))) as "Started"&lt;BR /&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND SUCCESS"))) as "Successful"&lt;BR /&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND FAILURE"))) as "Failed"&lt;BR /&gt;| eval running1 = Started-(Successful+Failed) | rename running as "Running1"&lt;BR /&gt;| eval running2 = case(Running1&amp;lt;0, 0, Running1&amp;gt;= 0, Running1) | rename running as "Running"&lt;/P&gt;&lt;P&gt;The last statement above is the one that the editor says has an error.&lt;/P&gt;&lt;P&gt;The original article link: &lt;A href="https://docs.splunk.com/Documentation/SCS/current/SearchReference/ConditionalFunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/SCS/current/SearchReference/ConditionalFunctions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Section Extended example.&lt;/P&gt;&lt;P&gt;Appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 11:27:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539669#M152635</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-12T11:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539671#M152636</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231476"&gt;@owulz&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I couldn't guess the error but below should work;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=a0_designeng_generic_app_audit_prd sourcetype=cba:designeng:as400:syslog host="MIDINT01.CBA.COM.AU"
| stats
count(eval(searchmatch("BACKUP AND CPF1124"))) as "Started"
count(eval(searchmatch("BACKUP AND CPF1164 AND SUCCESS"))) as "Successful"
count(eval(searchmatch("BACKUP AND CPF1164 AND FAILURE"))) as "Failed"
| eval Running = Started-(Successful+Failed)
| eval Running = case(Running&amp;lt;0, 0,1=1,Running)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 Feb 2021 11:39:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539671#M152636</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-02-12T11:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539774#M152674</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;I think there may have been an error in this:&lt;/P&gt;&lt;PRE&gt;| eval Running = case(Running&amp;lt;0, 0,1=1,Running)&lt;/PRE&gt;&lt;P&gt;I didn't understand the part ...&amp;nbsp; ,1=1,&lt;/P&gt;&lt;P&gt;I am using below, but getting the error on the second statement: Error on line 434: Unencoded &amp;lt;&lt;/P&gt;&lt;P&gt;| eval Running = Started-(Successful+Failed)&lt;BR /&gt;| eval Running = case(Running&amp;lt;0, 0, Running &amp;gt;=0, Running)&lt;/P&gt;&lt;P&gt;Strange as the syntax appears to me to be the same as in the earlierexample (via link I posted).&lt;/P&gt;&lt;P&gt;Not sure why it doesn't like with the syntax I used.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 02:06:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539774#M152674</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-13T02:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539777#M152675</link>
      <description>&lt;P&gt;I should have mentioned that first I used the last statement exactly as you suggested, but that too returned the same error "Unencoded &amp;lt;"&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 02:26:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/539777#M152675</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-02-13T02:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: New field with conditional value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/544768#M154268</link>
      <description>&lt;P&gt;Hi&amp;nbsp; -&amp;nbsp; I have an interestnig follow up..&lt;/P&gt;&lt;P&gt;The query section of code in my dashboard panel looks like this at the moment...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;query&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;index=myindex sourcetype=bla:linux:syslog host="server.bla.COM" ABCEVENT &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1124"))) as "Started"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND SUCCESS"))) as "Successful"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;count(eval(searchmatch("BACKUP AND CPF1164 AND FAILURE"))) as "Failed"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval Running=if(Started-(Successful+Failed) &amp;amp;gt;= 0, Started-(Successful+Failed), 0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| table Started, Running, Successful, Failed&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;lt;/query&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The field Running is a calculated field which works, but not well as it relies on data that may notbe unreliable.&lt;/P&gt;&lt;P&gt;I want to replace the value that is displayed for field Running with something like the following (based on new data I send to splunk). Idea is to fetch only the last occurence of this event from the past 5 minutes. The event returned will essentially include a count value that I want to extra and use in my panel as a statistic.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=myindex sourcetype=bla:linux:syslog host="server.bla.COM" ABCEVENT *NONSBS earliest=-5m | eventstats max(_time) as maxtime | where _time=maxtime&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When I do above as a regular Splunk search, I get a single event returned which is perfect.&lt;/P&gt;&lt;P&gt;I already created a field extraction which always shows up as an available field in my search results. It's called Jobs_Running.&lt;/P&gt;&lt;P&gt;What I would like to do is to replace this ...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| eval Running=if(Started-(Successful+Failed) &amp;amp;gt;= 0, Started-(Successful+Failed), 0)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;With something similar to the above search string, adapted to work within the existing panel, so that I can display the new value for "Running" along side the existing fields "Started", "Successful" and "Failed".&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;One thing I'm not sure about is whether I can pull in the already extracted field (Jobs_Running) that ia visible when I do a regular search or do I need to perform a field extraction on the fly?&lt;/P&gt;&lt;P&gt;The expression is:&amp;nbsp;&lt;SPAN&gt;^(?:[^ \n]* ){9}(?P&amp;lt;Jobs_Running&amp;gt;\d+)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 13:11:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/New-field-with-conditional-value/m-p/544768#M154268</guid>
      <dc:creator>owulz</dc:creator>
      <dc:date>2021-03-22T13:11:11Z</dc:date>
    </item>
  </channel>
</rss>

