<?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 create a field on the fly using CASE in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711911#M240260</link>
    <description>&lt;P&gt;Can you provide a sample?&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2025 13:01:39 GMT</pubDate>
    <dc:creator>NanSplk01</dc:creator>
    <dc:date>2025-02-18T13:01:39Z</dc:date>
    <item>
      <title>How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711401#M240155</link>
      <description>&lt;P&gt;I have the following values that will go in a field titled StatusMsg:&lt;/P&gt;&lt;P&gt;"Task threw an uncaught and unrecoverable exception"&lt;BR /&gt;"Ignoring await stop request for non-present connector"&lt;BR /&gt;"Graceful stop of task"&lt;BR /&gt;"Failed to start connector"&lt;BR /&gt;"Error while starting connector"&lt;BR /&gt;"Ignoring error closing connection"&lt;BR /&gt;"failed to publish monitoring message"&lt;BR /&gt;"Ignoring error closing connection"&lt;BR /&gt;"restart failed"|&lt;BR /&gt;"disconnected"&lt;BR /&gt;"Communications link failure during rollback"&lt;BR /&gt;"Exception occurred while closing reporter"&lt;BR /&gt;"Connection to node"&lt;BR /&gt;"Unexpected exception sending HTTP Request"&lt;BR /&gt;"Ignoring stop request for unowned task"&lt;BR /&gt;"failed on invocation of onPartitionsAssigned for partitions"&lt;BR /&gt;"Ignoring stop request for unowned connector"&lt;BR /&gt;"Ignoring await stop request for non-present connector"&lt;BR /&gt;"Connection refused"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not certain how to do this.&amp;nbsp; This is the base search:&amp;nbsp;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR=ERROR OR ERROR=WARN&lt;/P&gt;&lt;P&gt;I want to create the field on the fly and have it pick up the appropriate CASE value.&amp;nbsp; I would then put it in a table with host connName StatusMsg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assist would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 17:26:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711401#M240155</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-12T17:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711411#M240158</link>
      <description>&lt;P&gt;The command you're looking for is &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR=ERROR OR ERROR=WARN
| eval StatusMsg = case(&amp;lt;&amp;lt;some expression&amp;gt;&amp;gt;, "Task threw an uncaught and unrecoverable exception",
    &amp;lt;&amp;lt;some other expression&amp;gt;&amp;gt;, "Ignoring await stop request for non-present connector",
    ...,
    &amp;lt;&amp;lt;a different expression&amp;gt;&amp;gt;, "Connection refused",
    1==1, "Unknown")
| table host connName StatusMsg&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The trick is in selecting the appropriate status message.&amp;nbsp; You'll need to key off some field(s) in the results.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 18:53:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711411#M240158</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2025-02-12T18:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711503#M240183</link>
      <description>&lt;P&gt;StatusMsg is the field (on the fly field) that I want to be populated by the message so I'm not certain what you mean by&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;&amp;lt;some expression&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;So that was why I thought maybe this would be an if then type of query.&amp;nbsp; If StatusMsg="some value" then put that in the table along with the other data.&amp;nbsp; If not, then go to the next status message.&amp;nbsp; So I would want:&lt;/P&gt;&lt;P&gt;Action&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Host&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ConnName&lt;/P&gt;&lt;P&gt;"Task through an uncaught..."&amp;nbsp; &amp;nbsp; &amp;nbsp;lx.......&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CCNBU----&lt;/P&gt;&lt;P&gt;So should this be an if then search?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 16:39:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711503#M240183</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-13T16:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711505#M240185</link>
      <description>&lt;P&gt;The StatusMsg field is being created on the fly, but it has to come from *somewhere*.&amp;nbsp; The OP has a list of possible messages, but there is no indication of when each is used.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;lt;&amp;lt;some expression&amp;gt;&amp;gt;&lt;/FONT&gt; refers to a Boolean check that decides when to set StatusMsg to a specific string.&amp;nbsp; The expression probably will need to test the values of other fields (perhaps Host and/or ConnName).&amp;nbsp; You know your data better than I do so I can't be more detailed than that.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 16:59:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711505#M240185</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2025-02-13T16:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711520#M240189</link>
      <description>&lt;P&gt;So I have been trying to use if statements, but I don't seem to be getting the if statement correct:&lt;/P&gt;&lt;P&gt;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR=ERROR OR ERROR=WARN Action="restart failed" OR Action="disconnected" OR Action="Task threw an uncaught an unrecoverable exception"&lt;BR /&gt;| eval if(Action="restart failed", "restart failed", "OK", Action="disconnected","disconnected","OK", Action="Task threw an uncaught an unrecoverable exception", "ok")&lt;BR /&gt;| table Action host connName&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried several different formats for the if, but it keeps telling me the if statements are wrong.&amp;nbsp; What am I not seeing here?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 18:40:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711520#M240189</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-13T18:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711524#M240190</link>
      <description>&lt;P&gt;If this is your literal search, you're not assigning a field correctly with eval.&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;eval&lt;/EM&gt; command must have a destination field name. The&amp;nbsp;&lt;EM&gt;if&amp;nbsp;&lt;/EM&gt; and &lt;EM&gt;case&lt;/EM&gt; commands just return a value. You have to assign this value somewhere.&lt;/P&gt;&lt;P&gt;And you're using &lt;EM&gt;if&lt;/EM&gt; with&amp;nbsp;&lt;EM&gt;case&lt;/EM&gt; syntax.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 19:07:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711524#M240190</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-02-13T19:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711911#M240260</link>
      <description>&lt;P&gt;Can you provide a sample?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 13:01:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711911#M240260</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-18T13:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711922#M240262</link>
      <description>&lt;P&gt;The &lt;EM&gt;if&lt;/EM&gt; function works like a ternary ? : operator in C. So the proper syntax for setting a field conditionally is like this:&lt;/P&gt;&lt;PRE&gt;| eval field=if(something="something","value_when_true","value_when_false")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 15:52:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711922#M240262</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-02-18T15:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711943#M240265</link>
      <description>&lt;P&gt;I think I'm close, but the error_msg does not display:&lt;/P&gt;&lt;P&gt;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR=ERROR OR ERROR=WARN&lt;BR /&gt;| eval error_msg = case(match(_raw, "Disconnected"), "disconected", match(_raw, "restart failed"), "restart failed", match(_raw, "Failed to start connector"), "failed to start connector")&lt;BR /&gt;| dedup host&lt;BR /&gt;| table host connName error_msg&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 18:22:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711943#M240265</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-18T18:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711969#M240273</link>
      <description>&lt;P&gt;Get rid of that dedup host. &amp;nbsp;You will see some events with error_msg, some without. &amp;nbsp;I cannot decipher what that dedup is supposed to accomplish, or what real problem you are trying to solve. &amp;nbsp;So, I cannot suggest an alternative. &amp;nbsp;But if you have that dedup and if for each host the last event is NOT a failure or disconnect, you will get no error_msg. &amp;nbsp;Maybe you mean this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR=ERROR OR ERROR=WARN
| eval error_msg = case(match(_raw, "Disconnected"), "disconected", match(_raw, "restart failed"), "restart failed", match(_raw, "Failed to start connector"), "failed to start connector")
| search error_msg = *
| dedup host
| table host connName error_msg&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 05:30:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711969#M240273</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-02-19T05:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711992#M240276</link>
      <description>&lt;P&gt;Was able to get it working this way.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=kafka-np sourcetype="KCON" connName="CCNGBU_*" ERROR!=INFO _raw=*&lt;BR /&gt;| eval error_msg = case(match(_raw, "Disconnected"), "disconected",&lt;BR /&gt;match(_raw, "restart failed"), "restart failed",&lt;BR /&gt;match(_raw, "Failed to start connector"), "failed to start connector")&lt;BR /&gt;| search error_msg=*&lt;BR /&gt;| dedup connName&lt;BR /&gt;| table host connName error_msg ERROR&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 12:46:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/711992#M240276</guid>
      <dc:creator>NanSplk01</dc:creator>
      <dc:date>2025-02-19T12:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a field on the fly using CASE</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/712053#M240286</link>
      <description>&lt;P&gt;If your problem is resolved, then please click the "Accept as Solution" button to help future readers.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 05:52:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-field-on-the-fly-using-CASE/m-p/712053#M240286</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2025-02-20T05:52:37Z</dc:date>
    </item>
  </channel>
</rss>

