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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...