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
SplunkTrust
SplunkTrust

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
SplunkTrust
SplunkTrust

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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...