All Apps and Add-ons

Unable to run query containing gentimes from dashboard

msashish
Explorer

Hi,

I am using below to generate a date information which I shall later use:

| makeresults
| eval startDate=strftime(relative_time(_time,"-4y@y"),"%m/%d/%Y")
| eval endDate=strftime(relative_time(_time,"+2w@w"),"%m/%d/%Y")
| fields startDate, endDate
| map search="| gentimes start=\"$startDate$\" end=\"$endDate$\" increment=0d
| eval AsOfDate=strftime(starttime,\"%Y-%m-%d\")
| sort AsOfDate
| fields AsOfDate"
| eval Weekday=strftime(strptime(AsOfDate, "%Y-%m-%d"), "%A")
| eval flag=case(strptime(AsOfDate,"%Y-%m-%d")>now(),"future",1==1,"past")
| fields AsOfDate, Weekday , flag

This works fine on search but does not work from within dashboard query (Within dashboard query I replaced > & < with corresponding html tags).

When run from dashboard query I keep getting "Could not create search" (appears it has not been able to resolve startDate and endDate)

Is there any way I can save above & refer in dashboard (for joining to other queries) ?

0 Karma

to4kawa
Ultra Champion
<dashboard>
  <label>AsOfDate</label>
  <row>
    <panel>
      <table>
        <search>
          <query>| makeresults count=2
| streamstats count
| eval _time=if(count=1,relative_time(_time,"-4y@y"),relative_time(_time,"+2w@w"))
| makecontinuous span=1d _time
| eval AsOfDate=strftime(_time,"%Y-%m-%d")
| sort AsOfDate
| eval Weekday=strftime(_time, "%A")
| eval flag=case(_time > now(),"future",1==1,"past")
| table AsOfDate, Weekday , flag</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</dashboard>
0 Karma

msashish
Explorer

Looks like map command does not work with single $. I tried $$ for my variables and it worked. Testing further.

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...