<?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 Return values from map command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176590#M50730</link>
    <description>&lt;P&gt;So I have a function which takes a certain amount of time (timer_value) and I'm trying to create an alert that triggers when the time starts to increase. For this I'm calculating the slope using this macro (&lt;A href="http://wiki.splunk.com/Community:Plotting_a_linear_trendline"&gt;http://wiki.splunk.com/Community:Plotting_a_linear_trendline&lt;/A&gt;). I'm using the map command, because I want to calculate the slope for each host running this process. This works fine, and I get a chart (using the table command) that gives me the host, slope, and a boolean that tells me if this value is good or bad. &lt;BR /&gt;
However, since I want to create an alert for this, I need to pass the value out of the sub-search and map command and use it as a custom condition for the alert. I'm stuck on how to do this-I've tried return as well as table. I'm assuming this is a problem because the map command returns multiple instances of the variable named slope? &lt;BR /&gt;
For now I don't care which host triggered the alert, I just need it to trigger if any of the values of slope are over a certain value. I can pass out either the boolean or the slope value, it doesn't matter. &lt;/P&gt;

&lt;P&gt;This is my search: &lt;/P&gt;

&lt;P&gt;TIMER timer_function="'scene_ingest_ndvi'" | stats count by host | map [search host=$host$ | timechart span=20min avg(timer_value) as avgyvalue | where isnotnull (avgyvalue) | `lineartrend(_time,avgyvalue)` | stats first(slope) as slope | eval host=$host$ | eval err= if(slope&amp;gt;0.005 OR slope&amp;lt;-0.005,"Bad","Good") | table host err slope ] maxsearches=100&lt;/P&gt;

&lt;P&gt;If anyone has any ideas on how to do this, they would be more than welcome. I'm also open to doing it another way, if there's something easier than map that will achieve the desired result. &lt;/P&gt;

&lt;P&gt;Thanks in advance!! &lt;/P&gt;</description>
    <pubDate>Fri, 23 May 2014 00:37:50 GMT</pubDate>
    <dc:creator>silentttone</dc:creator>
    <dc:date>2014-05-23T00:37:50Z</dc:date>
    <item>
      <title>Return values from map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176590#M50730</link>
      <description>&lt;P&gt;So I have a function which takes a certain amount of time (timer_value) and I'm trying to create an alert that triggers when the time starts to increase. For this I'm calculating the slope using this macro (&lt;A href="http://wiki.splunk.com/Community:Plotting_a_linear_trendline"&gt;http://wiki.splunk.com/Community:Plotting_a_linear_trendline&lt;/A&gt;). I'm using the map command, because I want to calculate the slope for each host running this process. This works fine, and I get a chart (using the table command) that gives me the host, slope, and a boolean that tells me if this value is good or bad. &lt;BR /&gt;
However, since I want to create an alert for this, I need to pass the value out of the sub-search and map command and use it as a custom condition for the alert. I'm stuck on how to do this-I've tried return as well as table. I'm assuming this is a problem because the map command returns multiple instances of the variable named slope? &lt;BR /&gt;
For now I don't care which host triggered the alert, I just need it to trigger if any of the values of slope are over a certain value. I can pass out either the boolean or the slope value, it doesn't matter. &lt;/P&gt;

&lt;P&gt;This is my search: &lt;/P&gt;

&lt;P&gt;TIMER timer_function="'scene_ingest_ndvi'" | stats count by host | map [search host=$host$ | timechart span=20min avg(timer_value) as avgyvalue | where isnotnull (avgyvalue) | `lineartrend(_time,avgyvalue)` | stats first(slope) as slope | eval host=$host$ | eval err= if(slope&amp;gt;0.005 OR slope&amp;lt;-0.005,"Bad","Good") | table host err slope ] maxsearches=100&lt;/P&gt;

&lt;P&gt;If anyone has any ideas on how to do this, they would be more than welcome. I'm also open to doing it another way, if there's something easier than map that will achieve the desired result. &lt;/P&gt;

&lt;P&gt;Thanks in advance!! &lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2014 00:37:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176590#M50730</guid>
      <dc:creator>silentttone</dc:creator>
      <dc:date>2014-05-23T00:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Return values from map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176591#M50731</link>
      <description>&lt;P&gt;I have converted your search to this run-anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal bytes=* | stats count by sourcetype | map [search index=_internal sourcetype=$sourcetype$ | timechart span=20min avg(bytes) as avgyvalue | where isnotnull (avgyvalue) | `linearregression(_time,avgyvalue)` | stats first(slope) as slope | eval sourcetype="$sourcetype$" | eval err= if(slope&amp;gt;0.005 OR slope&amp;lt;-0.005,"Bad","Good") | table sourcetype err slope ] maxsearches=100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That gives me this table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   sourcetype         err   slope
1  splunk_web_access  Bad    -0.26764105
2  splunkd            Good             0
3  splunkd_access     Bad   -0.007066474
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note, I have added double quotes around the second $sourcetype$ because you're looking for the string rather than the field's value.&lt;/P&gt;

&lt;P&gt;To create an alert on this you could define a custom condition &lt;CODE&gt;where err=="Bad"&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2014 09:31:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176591#M50731</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-23T09:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Return values from map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176592#M50732</link>
      <description>&lt;P&gt;Huh. I tried where slope&amp;gt;0.005 yesterday (I think using a return) and the Alert menu wasn't able to access the value for slope. I don't know what was going on there. &lt;BR /&gt;
Anyway, where err=="Bad" works, thanks for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2014 18:41:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176592#M50732</guid>
      <dc:creator>silentttone</dc:creator>
      <dc:date>2014-05-23T18:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Return values from map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176593#M50733</link>
      <description>&lt;P&gt;The &lt;CODE&gt;return&lt;/CODE&gt; command turns the results into a string stored in the &lt;CODE&gt;search&lt;/CODE&gt; field for filtering based on subsearches: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.1/SearchReference/return"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.1/SearchReference/return&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;That's bound to break access to the &lt;CODE&gt;slope&lt;/CODE&gt; field.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2014 20:22:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176593#M50733</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-23T20:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Return values from map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176594#M50734</link>
      <description>&lt;P&gt;Okay, interesting. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2014 17:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-values-from-map-command/m-p/176594#M50734</guid>
      <dc:creator>silentttone</dc:creator>
      <dc:date>2014-05-27T17:04:55Z</dc:date>
    </item>
  </channel>
</rss>

