Dashboards & Visualizations

pass quotes inside of tokens for dashboard

johnmvang
Path Finder

Hello,

I'm looking to pass a token in a dashboard where the value may have quotes, since the token is going into an eval, anyone know how to get that to work? Right now i'm running into eval malformed errors. with quadruple quotes or more depending on how many quotes the user inputs.

Thanks.

0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@johnmvang
You can escape quote by replacing " to \" on change of input. Just try to insert "ABC" in below provided sample dashboard XML.

<form>
  <label>Quotes</label>
  <fieldset submitButton="false">
    <input type="text" token="field1">
      <label>field1</label>
      <change>
        <eval token="txtValue">replace('value',"\"","\\\"")</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>
        $txtValue$
      </title>
      <table>
        <search>
          <query>| stats count | eval A="$txtValue$"</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@johnmvang
You can escape quote by replacing " to \" on change of input. Just try to insert "ABC" in below provided sample dashboard XML.

<form>
  <label>Quotes</label>
  <fieldset submitButton="false">
    <input type="text" token="field1">
      <label>field1</label>
      <change>
        <eval token="txtValue">replace('value',"\"","\\\"")</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>
        $txtValue$
      </title>
      <table>
        <search>
          <query>| stats count | eval A="$txtValue$"</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

vasanthi77
Explorer

Hi Kamlesh ,
I had the same problem, was trying the solution provided by you here.
I could see only first occurence is getting replaced.
Can Please you help me here

0 Karma

johnmvang
Path Finder

Hi Kamlesh, that did it for me. Thanks works great.

kamlesh_vaghela
SplunkTrust
SplunkTrust

Glad to help you @johnmvang
Can you please accept the answer to help the community?

0 Karma

Vijeta
Influencer

Can you post some example values for tokens and the code which is giving error

0 Karma

johnmvang
Path Finder

sure,

i've got a dashboard, where users can fill out 3 forms:

they can input:

'My Title' for input1 - which is a title input.
index="my_index" sourcetype="my_sourcetype" my_search - for the search
then choose a dropdown.

 <panel depends="$show_row2_tok$,$show_r2panel2_tok$">
      <title>Row 2 - Panel 2</title>
      <input type="text" token="r2p2_title">
        <label>Panel Title</label>
        <default></default>
      </input>
      <input type="text" token="r2p2_search">
        <label>Search String</label>
        <default></default>
      </input>
      <input type="dropdown" token="r2p2_viz">
        <label>Visualization Type</label>
        <choice value="column">Column Chart</choice>
        <choice value="line">Line Graph</choice>
        <choice value="stats">Stats Table</choice>
        <default></default>
      </input>
      <html>

    </html>
    </panel>

These will then populate values in a KVstore where i need to write them with an eval:

| makeresults
| eval custom_r2p2_title = "$write_r2p2_title$"
| eval custom_r2p2_search = "$write_r2p2_search$"
| eval custom_r2p2_vi = "$write_r2p2_viz$"
| outputlookup my_kvstore append=true

since i'm enabling users to add a search string into the second input, sometimes they will have quotes inside of their values which will break the search with this error:

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

0 Karma

johnmvang
Path Finder

this all works as long as there are no quotes. just fyi.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...