<?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: Lookups - dynamic values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252661#M176492</link>
    <description>&lt;P&gt;So the following should get you started.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count as host 
| eval host="jboss-vm-2f5r8.prod.d2-nonpfv-brown.cloud.pi.com" 
| rex field=host "(?&amp;lt;host_part1&amp;gt;[^\.]*)\.(?&amp;lt;host_part2&amp;gt;[^\.]*)\.(?&amp;lt;host_part3&amp;gt;[^\-]*).*" 
| eval sitename=case(host_part3=="d2","BOHO",host_part2=="d3","Cranebank") 
| eval environment=case(host_part2=="prod","Production",host_part2=="sys","System testing")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The trick is to break up the host string using rex into fields with the text to check, then use a case command to test the text and then set it  to the value you want. Depending on how consistent the naming convention for the host is the rex may need some tweaking.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Oct 2016 23:04:35 GMT</pubDate>
    <dc:creator>msivill_splunk</dc:creator>
    <dc:date>2016-10-12T23:04:35Z</dc:date>
    <item>
      <title>Lookups - dynamic values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252660#M176491</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;My lookup table has 3 columns, host, sitename and environment.&lt;/P&gt;

&lt;P&gt;Input to lookup is host name. &lt;BR /&gt;
If the host name contains "d2" sitename="BOHO", if hostname contains "d3" sitename="Cranebank".&lt;BR /&gt;
If the host name contains "prod" environment="Production", if hostname contains "sys" environment="System testing".&lt;/P&gt;

&lt;P&gt;For example,&lt;BR /&gt;
host =jboss-vm-2f5r8.prod.d2-nonpfv-brown.cloud.pi.com&lt;BR /&gt;
     sitename="BOHO" and environment="Production"&lt;/P&gt;

&lt;P&gt;jboss-vm-6j5v3.prod.d3-nonpfv-brown.cloud.pi.com&lt;BR /&gt;
     sitename="Cranebank" and environment="Production"&lt;/P&gt;

&lt;P&gt;jboss-vm-4l3s1.sys.d2-nonpfv-green.cloud.pi.com&lt;BR /&gt;
     sitename="BOHO" and environment="System Testing"&lt;/P&gt;

&lt;P&gt;jboss-vm-8w3b2.sys.d3-nonpfv-green.cloud.pi.com&lt;BR /&gt;
     sitename="Cranebank" and environment="System Testing"&lt;/P&gt;

&lt;P&gt;I do not want to hardcode sitename and environment in the lookup table. Instead I want the sitename and environment to be generated dynamically based on the host name.&lt;/P&gt;

&lt;P&gt;Is there any way of doing it using lookup?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 21:44:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252660#M176491</guid>
      <dc:creator>namritha</dc:creator>
      <dc:date>2016-10-12T21:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Lookups - dynamic values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252661#M176492</link>
      <description>&lt;P&gt;So the following should get you started.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count as host 
| eval host="jboss-vm-2f5r8.prod.d2-nonpfv-brown.cloud.pi.com" 
| rex field=host "(?&amp;lt;host_part1&amp;gt;[^\.]*)\.(?&amp;lt;host_part2&amp;gt;[^\.]*)\.(?&amp;lt;host_part3&amp;gt;[^\-]*).*" 
| eval sitename=case(host_part3=="d2","BOHO",host_part2=="d3","Cranebank") 
| eval environment=case(host_part2=="prod","Production",host_part2=="sys","System testing")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The trick is to break up the host string using rex into fields with the text to check, then use a case command to test the text and then set it  to the value you want. Depending on how consistent the naming convention for the host is the rex may need some tweaking.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 23:04:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252661#M176492</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2016-10-12T23:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Lookups - dynamic values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252662#M176493</link>
      <description>&lt;P&gt;I'm not sure exactly what you mean when saying you don't want to hardcode them in a lookup.  I think you have a couple different options.&lt;/P&gt;

&lt;P&gt;First, if those are literally the only two environements and sites, you could just create a couple &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/Knowledge/CreatecalculatedfieldswithSplunkWeb"&gt;calculated fields&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval env = case(match(host,"(?i)\.prod\."),"Production",match(host,"(?i)\.sys\."),"System Testing",1=1,"unknown")
eval site =  case(match(host,"(?i)\.d2"),"BOHO",match(host,"(?i)\.d3"),"Cranebank",1=1,"unknown")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or i you have a lot of them, you can use a couple &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/Knowledge/Addfieldmatchingrulestoyourlookupconfiguration"&gt;lookup tables&lt;/A&gt; - maybe one for site and one for environment.  Configure them to allow wildcard matching on host, and I think you should be fine.&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host,env
*.prod.*,Production
*.sys.*,System Testing
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Oct 2016 23:29:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252662#M176493</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-10-12T23:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Lookups - dynamic values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252663#M176494</link>
      <description>&lt;P&gt;I guess you cannot accomplish what I asked for using lookups alone. It also requires changes in transforms.conf and props.conf&lt;/P&gt;

&lt;P&gt;I have switched over to using calculated fields.&lt;/P&gt;

&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 17:28:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookups-dynamic-values/m-p/252663#M176494</guid>
      <dc:creator>namritha</dc:creator>
      <dc:date>2016-10-13T17:28:46Z</dc:date>
    </item>
  </channel>
</rss>

