Dashboards & Visualizations

Why am I getting an error "Error in 'eval' command" for lines assigning a token to a variable in a dashboard?

wrangler2x
Motivator

I've got a real simple dashboard that has two inputs (a start time and an end time). Where I'm trying to assign the value entered from the input token to a variable using eval, it generates this error when the thing runs:

Error in 'eval' command: The expression is malformed.

It looks like it should be straightforward to me, but it does not work. I've used this technique in a search and that works with no problem. Is there something I have to do differently when using eval? Here is the dashboard

<form>
  <label>Elapsed Time Calculator</label>
  <description>Enter time in %H:%M format as 24 hour time</description>
 <searchTemplate>
| makeresults
| eval starttime = $STARTT$
| eval endtime = $ENDT$
| eval sepoch = strptime(starttime, "%H:%M")
| eval eepoch = strptime(endtime, "%H:%M")
| eval elapsedMin = round((eepoch - sepoch) / 60, 0)
| eval elapsedHour = round(elapsedMin / 60, 3)
| table starttime endtime elapsedMin elapsedHour
</searchTemplate>
  <fieldset>
    <input type="text" token="STARTT" searchWhenChanged="true"></input>
    <input type="text" token="ENDT" searchWhenChanged="true"></input>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Search result</title>
      </table>
    </panel>
  </row>
</form>
0 Karma
1 Solution

MuS
Legend

Hi wrangler2x,

your token is a string, but your code tells eval to use a field. Change it have the tokens in quotes and it will work 😉

<form>
   <label>Elapsed Time Calculator</label>
   <description>Enter time in %H:%M format as 24 hour time</description>
   <fieldset>
     <input type="text" token="STARTT" searchWhenChanged="true"></input>
     <input type="text" token="ENDT" searchWhenChanged="true"></input>
   </fieldset>
   <row>
     <panel>
       <table>
         <search>
           <query>
             | makeresults
             | eval starttime = "$STARTT$"
             | eval endtime = "$ENDT$"
             | eval sepoch = strptime(starttime, "%H:%M")
             | eval eepoch = strptime(endtime, "%H:%M")
             | eval elapsedMin = round((eepoch - sepoch) / 60, 0)
             | eval elapsedHour = round(elapsedMin / 60, 3)
             | table starttime endtime elapsedMin elapsedHour
            </query>
          </search>
         <title>Search result</title>
       </table>
     </panel>
   </row>
 </form>

Update: I also updated the XML code.

Hope this helps ...

cheers, MuS

View solution in original post

MuS
Legend

Hi wrangler2x,

your token is a string, but your code tells eval to use a field. Change it have the tokens in quotes and it will work 😉

<form>
   <label>Elapsed Time Calculator</label>
   <description>Enter time in %H:%M format as 24 hour time</description>
   <fieldset>
     <input type="text" token="STARTT" searchWhenChanged="true"></input>
     <input type="text" token="ENDT" searchWhenChanged="true"></input>
   </fieldset>
   <row>
     <panel>
       <table>
         <search>
           <query>
             | makeresults
             | eval starttime = "$STARTT$"
             | eval endtime = "$ENDT$"
             | eval sepoch = strptime(starttime, "%H:%M")
             | eval eepoch = strptime(endtime, "%H:%M")
             | eval elapsedMin = round((eepoch - sepoch) / 60, 0)
             | eval elapsedHour = round(elapsedMin / 60, 3)
             | table starttime endtime elapsedMin elapsedHour
            </query>
          </search>
         <title>Search result</title>
       </table>
     </panel>
   </row>
 </form>

Update: I also updated the XML code.

Hope this helps ...

cheers, MuS

wrangler2x
Motivator

Aha! @MuS -- genius!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Perhaps you could put fieldset before searchTemplate?

---
If this reply helps you, Karma would be appreciated.
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 ...