<?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 How to create a new key-value pair name and value based on text within a log? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134007#M27540</link>
    <description>&lt;P&gt;I would like to create a whole new KV Pair, and based on the text from within a log, give it a specific value.&lt;/P&gt;

&lt;P&gt;Example log 1:&lt;BR /&gt;
user logged on&lt;/P&gt;

&lt;P&gt;Example log 2:&lt;BR /&gt;
user failed logon&lt;/P&gt;

&lt;P&gt;Desired KV Pair:&lt;BR /&gt;
Logon = yes&lt;BR /&gt;
Logon = no&lt;/P&gt;

&lt;P&gt;Is this possible? I suspect this would be done in props.conf, but not sure how to get started.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Feb 2015 20:38:49 GMT</pubDate>
    <dc:creator>jizzmaster</dc:creator>
    <dc:date>2015-02-09T20:38:49Z</dc:date>
    <item>
      <title>How to create a new key-value pair name and value based on text within a log?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134007#M27540</link>
      <description>&lt;P&gt;I would like to create a whole new KV Pair, and based on the text from within a log, give it a specific value.&lt;/P&gt;

&lt;P&gt;Example log 1:&lt;BR /&gt;
user logged on&lt;/P&gt;

&lt;P&gt;Example log 2:&lt;BR /&gt;
user failed logon&lt;/P&gt;

&lt;P&gt;Desired KV Pair:&lt;BR /&gt;
Logon = yes&lt;BR /&gt;
Logon = no&lt;/P&gt;

&lt;P&gt;Is this possible? I suspect this would be done in props.conf, but not sure how to get started.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Feb 2015 20:38:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134007#M27540</guid>
      <dc:creator>jizzmaster</dc:creator>
      <dc:date>2015-02-09T20:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new key-value pair name and value based on text within a log?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134008#M27541</link>
      <description>&lt;P&gt;You could construct such a field as part of a search string, or if you wanted it to always be available you could use a calculated field (EVAL-whatever).  It's possible you could even express this as a "field extraction" where the value string is hardcoded.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2015 14:27:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134008#M27541</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2015-02-10T14:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new key-value pair name and value based on text within a log?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134009#M27542</link>
      <description>&lt;P&gt;The following eval clause might do the trick though it will result in field Logon being present with a blank value if neither phrase is found:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval Logon=case(match(_raw,"user logged on"), "yes", match(_raw,"user failed logon"),"no",1==1,"")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As jrodman wrote this could be used as part of the search and should also work for creating a calculated field.&lt;/P&gt;

&lt;P&gt;Another approach would be using rex mode=sed to change the text:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=_raw "s/user logged on/Logon=yes/" | rex mode=sed field=_raw "s/user failed logon/Logon=no/" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You might need a kv or &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "Logon=(?&amp;lt;Logon&amp;gt;yes|no)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to pick up the name value pair.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2015 15:36:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134009#M27542</guid>
      <dc:creator>tpflicke</dc:creator>
      <dc:date>2015-02-10T15:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new key-value pair name and value based on text within a log?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134010#M27543</link>
      <description>&lt;P&gt;That "eval" statement is pretty much exactly what I needed. Along with jrodman's answer, I was able to get this turned into an automatic field extraction by adding it in the props.conf. Thank you both.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2015 19:31:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-new-key-value-pair-name-and-value-based-on-text/m-p/134010#M27543</guid>
      <dc:creator>jizzmaster</dc:creator>
      <dc:date>2015-02-10T19:31:01Z</dc:date>
    </item>
  </channel>
</rss>

