<?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: dynamic field value extraction in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171202#M10523</link>
    <description>&lt;P&gt;also, I want to avoid rex if possible since the field DataType, MaxPower, etc. are already automatically extracted by the search-engine; I just need to find a way to reference those values for comparison based on the name of the field dynamically&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2013 05:10:02 GMT</pubDate>
    <dc:creator>klee310</dc:creator>
    <dc:date>2013-12-09T05:10:02Z</dc:date>
    <item>
      <title>dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171201#M10522</link>
      <description>&lt;P&gt;I'm trying to extract a field-value for comparison - in a dynamic fashion. First let me illustrate the problem with some sample data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  DataType=2, MaxPower=10, MinPower=3, IdlePower=5
  DataType=3, Open=10, Close=23, HappyHour=15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a lookup table with something similar to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  DataType,FieldName,ValueMax,ValueMin
  2,MaxPower,100,10
  2,MinPower,10,1
  2,IdlePower,50,1
  3,Open,10,5
  ... etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now my search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=xxx | lookup LOOKUPFILEX DataType | mvexpand FieldName | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to map the results into a macro which will perform the actual evaluation, this part is ok. Now I'm trying to write this macro and i'm sort of hitting a wall. For example, the macro might be invoked like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  `checkRange("$FieldName$",$ValueMax$,$ValueMin$)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So from within the macro, given the field name "MaxPower", how do I extract the value (10 in this case) so I can perform comparison with its associated max/min range?&lt;/P&gt;

&lt;P&gt;I am currently on the path associated with another question "&lt;A href="http://answers.splunk.com/answers/83145/how-can-i-use-the-value-of-a-field-as-an-immediate-search-expression-dynamic-search-string-formatting"&gt;dynamic field substition&lt;/A&gt;"&lt;/P&gt;

&lt;P&gt;By the way, the reason I don't want to hard-coding the evaluation (MaxPower, MinPower, IdlePower, Open, etc.) is because - what you see here is just a sample; the actual use-case I am confronted with contains upwards of 100 fields that are subject to change. Therefore modifications must be easily implemented (like via a lookup table)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 05:05:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171201#M10522</guid>
      <dc:creator>klee310</dc:creator>
      <dc:date>2013-12-09T05:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171202#M10523</link>
      <description>&lt;P&gt;also, I want to avoid rex if possible since the field DataType, MaxPower, etc. are already automatically extracted by the search-engine; I just need to find a way to reference those values for comparison based on the name of the field dynamically&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 05:10:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171202#M10523</guid>
      <dc:creator>klee310</dc:creator>
      <dc:date>2013-12-09T05:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171203#M10524</link>
      <description>&lt;P&gt;Why can't you just use &lt;CODE&gt;ValueMin&lt;/CODE&gt; and &lt;CODE&gt;ValueMax&lt;/CODE&gt;? Isn't the point of the lookup that the max and min are going to be stored in those variables, so you can just them?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 05:47:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171203#M10524</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-12-09T05:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171204#M10525</link>
      <description>&lt;P&gt;In other words, why can't you just use &lt;CODE&gt;if(MaxPower&amp;lt;=ValueMax AND MaxPower &amp;gt;= ValueMin,1,null())&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 05:48:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171204#M10525</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-12-09T05:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171205#M10526</link>
      <description>&lt;P&gt;thanks gkanapathy for the quick response; if I have something like | eval foo=if(MaxPower&amp;lt;=ValueMax AND MaxPower&amp;gt;=ValueMin,1,null())... then MaxPower and MinPower will have to be hard-coded into my macro. Which is not want I want to do. On the other hand, if you are question why I don't use ... eval foo=if($arg1$ &amp;lt;= ValueMax...) well $arg1$ is a string, in this example, it is the string "MaxPower" - so that doesn't work either&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 06:12:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171205#M10526</guid>
      <dc:creator>klee310</dc:creator>
      <dc:date>2013-12-09T06:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171206#M10527</link>
      <description>&lt;P&gt;Your search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xxx | lookup LOOKUPFILEX DataType | mvexpand FieldName 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will give all fields present in index=xxx (already extracted by splunk) and fields ValueMin and ValueMax.&lt;/P&gt;

&lt;P&gt;Create a macro which will take 4 arguments.&lt;/P&gt;

&lt;P&gt;Macro Name: &lt;STRONG&gt;checkRange(4)&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Definition:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval validationResult=if($FieldValue$&amp;gt;=$ValueMin$ AND $FieldValue$&amp;lt;=$ValueMax$,$FieldName$." within range",$FieldName$." out of range")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Arguments : &lt;STRONG&gt;FieldValue,FieldName,ValueMin,ValueMax&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Modified search (say validate MinPower field value):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xxx | lookup LOOKUPFILEX DataType | mvexpand FieldName |`checkRange(MinPower,"MinPower", ValueMin, ValueMax)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should return the field validationResult created in Macro. Obviously, you have to customize this per your requirement, but this should give you fair idea.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 07:01:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171206#M10527</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2013-12-09T07:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171207#M10528</link>
      <description>&lt;P&gt;thanks somesoni for the reply, but I'm afraid this solution doesn't solve the problem I am having. If I had 100+ FieldName(s), how would I go about invoking this "Macro"? Wouldn't I need 100+ savedsearches, each unique to a FieldName?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 07:23:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171207#M10528</guid>
      <dc:creator>klee310</dc:creator>
      <dc:date>2013-12-09T07:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171208#M10529</link>
      <description>&lt;P&gt;Nope I don't. Actually I think you can't do this with macros (which is fundamentally one of the differences you get between macros and true functions). I guess my suggestion might be to use a scripted lookup or a custom search command. If you use a scripted lookup, you could combine it with the LOOKUPFILEX lookup. Or you could keep it separate.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2013 08:43:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171208#M10529</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-12-09T08:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic field value extraction</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171209#M10530</link>
      <description>&lt;P&gt;actually as it turns out, i did write all 100+ macros - but each is just a simple wrapper which calls a main-macro with the appropriate arguments&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2014 03:39:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/dynamic-field-value-extraction/m-p/171209#M10530</guid>
      <dc:creator>klee310</dc:creator>
      <dc:date>2014-01-03T03:39:51Z</dc:date>
    </item>
  </channel>
</rss>

