<?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: Can I use ' if (match (X, &amp;quot;regex), Y, Z) ' in a colorPalette expression? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376059#M24621</link>
    <description>&lt;P&gt;I noticed your regex is invalid in your match.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.{0,}(\d{1}\s.{0,}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is an incomplete grouping by having an open "(" without a closing ")".&lt;/P&gt;</description>
    <pubDate>Wed, 09 May 2018 16:38:10 GMT</pubDate>
    <dc:creator>jconger</dc:creator>
    <dc:date>2018-05-09T16:38:10Z</dc:date>
    <item>
      <title>Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376056#M24618</link>
      <description>&lt;P&gt;I am trying to match a timestamp field depending on how many minutes ago (0-9, or 10+). I'm using a colorPalette of type="expression" to color a table column based on the age of the data. The field is concatenated from _time and a field that is evaluated from now()-_time. Here's an example of my field:&lt;/P&gt;

&lt;P&gt;05/07/18 - 12:44:32 (1 minutes ago) &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;format type="color" field="Updated"&amp;gt;
&amp;lt;colorPalette type="expression"&amp;gt;if (match (value, ".*\(\d\s.*"), "0x65A637", "0xD93F3C")&amp;lt;/colorPalette&amp;gt;
&amp;lt;/format&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;on my dashboard this returns 0x65A637 for (0-9 minutes ago), but also for (10+ minutes ago). &lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;The same statement, as an eval to add a table column, works fine, so I don't think the problem is with the regex match. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:22:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376056#M24618</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2020-09-29T19:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376057#M24619</link>
      <description>&lt;P&gt;Are you using the actual text "color1" and "color2"?  Those should be RGB hex values like #FF0000 (for red), or #00FF00 (for blue).&lt;/P&gt;

&lt;P&gt;I believe you need to specify the field in your &lt;CODE&gt;&amp;lt;format&amp;gt;&lt;/CODE&gt; tag too.  Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;format type="color" field="count"&amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 May 2018 22:35:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376057#M24619</guid>
      <dc:creator>jconger</dc:creator>
      <dc:date>2018-05-07T22:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376058#M24620</link>
      <description>&lt;P&gt;Thanks for the suggestion, I am specifying the actual hex values, and have the field name in my format tag&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 22:40:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376058#M24620</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2018-05-07T22:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376059#M24621</link>
      <description>&lt;P&gt;I noticed your regex is invalid in your match.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.{0,}(\d{1}\s.{0,}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is an incomplete grouping by having an open "(" without a closing ")".&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 16:38:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376059#M24621</guid>
      <dc:creator>jconger</dc:creator>
      <dc:date>2018-05-09T16:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376060#M24622</link>
      <description>&lt;P&gt;I escaped it in the original, the code sample tool is not behaving as I would like.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 16:50:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376060#M24622</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2018-05-09T16:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376061#M24623</link>
      <description>&lt;P&gt;I think that this is not possible, by the way - I tried a much simpler regex and it did not work. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (match (value, "Online"), "0x65A637", "0xD93F3C")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This has no effect on the column color although Online is the value. Simple if&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if ( value == "Online", "0x65A637", "0xD93F3C") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;works fine. &lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 16:55:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376061#M24623</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2018-05-09T16:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376062#M24624</link>
      <description>&lt;P&gt;@camillak, somehow complex regular expression for colorPalette i.e. &lt;CODE&gt;\d{1}&lt;/CODE&gt; does not seem to work. Can you please try the following instead?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;format type="color" field="Updated"&amp;gt;
      &amp;lt;colorPalette type="expression"&amp;gt;if(match(value,"^[0-9] Minutes Ago"),"#65A637","#D93F3C")&amp;lt;/colorPalette&amp;gt;
    &amp;lt;/format&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere dashboard based on Splunk's internal indexes.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4886i0E6726AA0493B78E/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Following is the dashboard Simple XML code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;Color based on Regular Expression Match&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| metadata type=sourcetypes index=_*
| table sourcetype totalCount lastTime
| fieldformat lastTime=strftime(lastTime,"%Y/%m/%d %H:%M:%S")
| eval Updated=round((now()-lastTime)/60,0)
| eval Updated=if(Updated&amp;lt;10,Updated." Minutes Ago","10+ Minutes Ago")&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;20&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;format type="color" field="Updated"&amp;gt;
          &amp;lt;colorPalette type="expression"&amp;gt;if(match(value,"^[0-9] Minutes Ago"),"#65A637","#D93F3C")&amp;lt;/colorPalette&amp;gt;
        &amp;lt;/format&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 18:14:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376062#M24624</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-09T18:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376063#M24625</link>
      <description>&lt;P&gt;I had actually just figured this out. The &lt;CODE&gt;\d&lt;/CODE&gt; and &lt;CODE&gt;\(&lt;/CODE&gt; were both not working. The example that you posted is almost exactly what I needed. Because the number of minutes is not the beginning of my field, I still had to account for the open parenthesis. This worked for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;colorPalette type="expression"&amp;gt;if (match (value, " .[0-9] minutes ago"), "0x65A637", "0xD93F3C")&amp;lt;/colorPalette&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 18:26:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376063#M24625</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2018-05-09T18:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use ' if (match (X, "regex), Y, Z) ' in a colorPalette expression?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376064#M24626</link>
      <description>&lt;P&gt;As pointed out by @jeffland seems like 8.x version supports case statement. Not sure which version onward this started working.&lt;/P&gt;

&lt;P&gt;Following answer used &lt;CODE&gt;case&lt;/CODE&gt; with &lt;CODE&gt;match&lt;/CODE&gt; for applying &lt;CODE&gt;colorPalette&lt;/CODE&gt; based on &lt;CODE&gt;expression&lt;/CODE&gt;:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/820403/how-to-change-font-color-based-on-a-condition-for.html"&gt;https://answers.splunk.com/answers/820403/how-to-change-font-color-based-on-a-condition-for.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2020 16:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-use-if-match-X-quot-regex-Y-Z-in-a-colorPalette-expression/m-p/376064#M24626</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-04-25T16:55:09Z</dc:date>
    </item>
  </channel>
</rss>

