<?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 chart a list of key/value pair fields only if a condition matches? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434430#M123983</link>
    <description>&lt;P&gt;@ jbethmont,&lt;/P&gt;

&lt;P&gt;If you have only one value for each field, you could use &lt;CODE&gt;transpose&lt;/CODE&gt; and do the operation&lt;BR /&gt;
for e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    "your search to get all fields and values"| transpose |rename "row 1" as value|stats count(eval(if(value&amp;gt;100,1,null()))) as count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"your search"| transpose |rename "row 1" as value|where value&amp;gt;100|"chart functions"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Aug 2018 15:44:13 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-08-29T15:44:13Z</dc:date>
    <item>
      <title>How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434429#M123982</link>
      <description>&lt;P&gt;Hi Splunk'az,&lt;/P&gt;

&lt;P&gt;I have events composed of  64 key/value pairs that are being extracted into fields at indexing time:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;"d" : {&lt;BR /&gt;
       "field01" : [ 0 ],&lt;BR /&gt;
       "field02" : [ 5 ],&lt;BR /&gt;
       "field03" : [ 2 ],&lt;BR /&gt;
       "field04" : [ 3 ],&lt;BR /&gt;
        [...]&lt;BR /&gt;
       "field64" : [ 38]&lt;BR /&gt;
        }&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I would like to chart the "value" of the field "only if" it is above a certain threshold.&lt;/P&gt;

&lt;P&gt;I was initially thinking using 'where':&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;| stats count last(field*) | where field* &amp;gt; 100&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;But the above doesn't work as 'where' can't contain a wildcard...&lt;BR /&gt;
Then I was looking at the 'foreach' function. And trying something like:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;| foreach c5x*   [eval new_&amp;lt;&amp;gt;=if(&amp;lt;&amp;gt; &amp;gt; 0, &amp;lt;&amp;gt;, null)] &lt;BR /&gt;
| table new_*&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;But the above doesn't work either, and still, I would have to get rid of the 'null' values from fields using a wildcard again. So the problem would remain the same.&lt;/P&gt;

&lt;P&gt;So, how can I chart a set of fields values only if the value is above a certain threshold? And without having to hardcode to complete list of fields obviously &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:05:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434429#M123982</guid>
      <dc:creator>jbethmont</dc:creator>
      <dc:date>2020-09-29T21:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434430#M123983</link>
      <description>&lt;P&gt;@ jbethmont,&lt;/P&gt;

&lt;P&gt;If you have only one value for each field, you could use &lt;CODE&gt;transpose&lt;/CODE&gt; and do the operation&lt;BR /&gt;
for e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    "your search to get all fields and values"| transpose |rename "row 1" as value|stats count(eval(if(value&amp;gt;100,1,null()))) as count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"your search"| transpose |rename "row 1" as value|where value&amp;gt;100|"chart functions"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 15:44:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434430#M123983</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-29T15:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434431#M123984</link>
      <description>&lt;P&gt;Thanks a lot!!! This is much more simpler using transpose! &lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 23:58:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434431#M123984</guid>
      <dc:creator>jbethmont</dc:creator>
      <dc:date>2018-08-29T23:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434432#M123985</link>
      <description>&lt;P&gt;Based on @renjith.nair 's comment the solution was to use the &lt;CODE&gt;transpose&lt;/CODE&gt; function.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
| stats last(field*) as field*
| transpose
| rename "column" as key "row 1" as value
| where value &amp;gt; 20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works fine for a snapshot of the values at a given time (last events basically). &lt;BR /&gt;
However, If I'd like to graph them over time, the issue remain the same as the table will be composed of multiple columns per time bucket. And I will need again to deal with a &lt;CODE&gt;*&lt;/CODE&gt; in my &lt;CODE&gt;where&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;alarm     value1    value2  value3  value4  value5
Time      10:33:23 AM   10:36:23 AM 10:36:28 AM 10:37:23 AM 10:37:28 AM
field01 43  46  47  47  48
field02 5    5    5  5   5
field03 2    2    2  2
[...]
field64     ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Maybe a combination of &lt;CODE&gt;transpose&lt;/CODE&gt; and &lt;CODE&gt;foreach&lt;/CODE&gt; command ?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 00:20:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434432#M123985</guid>
      <dc:creator>jbethmont</dc:creator>
      <dc:date>2018-08-30T00:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434433#M123986</link>
      <description>&lt;P&gt;@jbethmont,&lt;BR /&gt;
In this case, how do you want to filter? For e.g. lets take field02 - you want to chart only if all the values of field02 is above threshold or at least one value ?&lt;BR /&gt;
Forgot to mention that in transpose you could mention &lt;CODE&gt;header_field="column_name"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 15:42:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434433#M123986</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-31T15:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434434#M123987</link>
      <description>&lt;P&gt;Thanks for your help @renjith.nair &lt;BR /&gt;
So if I go back to my initial question, I would like to chart the average value of a field02 only if this average is above a threshold.&lt;/P&gt;

&lt;P&gt;So this works fine for 1 field (threshold is 70):&lt;BR /&gt;
    | stats avg(field02) as avg_c5x02 | where avg_c5x02 &amp;gt; 70&lt;/P&gt;

&lt;P&gt;But this doesn't work if my field contains a wildcard:&lt;BR /&gt;
    | stats avg(field*) as avg_c5x* | where avg_c5x* &amp;gt; 70&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:06:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434434#M123987</guid>
      <dc:creator>jbethmont</dc:creator>
      <dc:date>2020-09-29T21:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to chart a list of key/value pair fields only if a condition matches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434435#M123988</link>
      <description>&lt;P&gt;@jbethmont , &lt;/P&gt;

&lt;P&gt;Try this approach by assuming your data is in the below format where the numbers are "values"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; alarm     time1 time2 time3 
 field01    43    46    47 
 field02    5     5      5 
 field03    2     2      2 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried to simulate this by creating a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_*|timechart span=1m count by sourcetype|untable _time,sourcetype,count|sort sourcetype|streamstats dc(sourcetype) as num global=t|eval Field="Field".num
|xyseries _time,Field,count|transpose header_field=_time|rename column as alert
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this matches our requirement, then we can go to the next step by adding&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;|untable alert,_time,count|eventstats avg(count) as avg by alert|where avg&amp;gt;70&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So the final search would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_*|timechart span=1m count by sourcetype|untable _time,sourcetype,count
|sort sourcetype|streamstats dc(sourcetype) as num global=t|eval Field="Field".num
|xyseries _time,Field,count|transpose header_field=_time|rename column as alert
|untable alert,_time,count|eventstats avg(count) as avg by alert|where avg&amp;gt;70
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So to adapt your field names it would be&lt;/P&gt;

&lt;P&gt;" your existing search to get the tabular format as mentioned above"|untable alert,Time,value|eventstats avg(value) as avg by alert|where avg&amp;gt;70&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 09:08:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-chart-a-list-of-key-value-pair-fields-only-if-a-condition/m-p/434435#M123988</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-09-04T09:08:29Z</dc:date>
    </item>
  </channel>
</rss>

