Dashboards & Visualizations

How do I do addition in a Splunk HTML form?

nick405060
Motivator

How do I evaluate $a$ + $b$? Or even just evaluate 1+2?

<form>
    <panel>
        <html>
            <ul>
                <li>
                    <p>Ram Per Server: $a$ + $b$</p>
                </li>
            </ul>
        </html>
    </panel>
  </row>

</form>
Tags (2)
0 Karma
1 Solution

Vijeta
Influencer

I don't think you can directly do calculation in HTML, for your requirement can't you do calculation in splunk query and use the result token in html?

View solution in original post

back2root
Path Finder

You can do that in SimpleXML using . Where to place the depends on where your tokens come from. In case they come from an input:

<form>
  <label>Dashboard</label>
  <fieldset submitButton="false">
    <input type="text" token="tok_mem">
      <label>Memory</label>
      <change>
        <eval token="tok_sum">$tok_mem$ + $tok_swap$</eval>
      </change>
    </input>
    <input type="text" token="tok_swap">
      <label>Swap</label>
      <change>
        <eval token="tok_sum">$tok_mem$ + $tok_swap$</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
         <html>
             <ul>
                 <li>
                     <p>Ram Per Server: $tok_sum$</p>
                 </li>
             </ul>
         </html>
    </panel>
  </row>
</form>

You could do that on Search as well, ... see Splunk>docs on token usage

0 Karma

Vijeta
Influencer

I don't think you can directly do calculation in HTML, for your requirement can't you do calculation in splunk query and use the result token in html?

nick405060
Motivator

Yes! Thanks. I'm not sure if it's the best way or not, and am definitely open to hearing other answers/modifications. This is what I did:

    <panel>
        <search>
            <query>
| makeresults | eval baz=$a$+$b$| table baz
            </query>
            <preview>
                <set token="baz">$result.baz$</set>
            </preview>
        </search>
        <html>
            <p><b>section title</b></p>
            <ul>     
                <li>
                    <p>field: <a>$baz$</a></p>
                </li>
            </ul>
        </html>
     </panel>
0 Karma

Vijeta
Influencer

You can always hide any panel or table by using depends="$hidden$", for eg:-

<table depends="$hidden$">

will hide the table from displaying.

nick405060
Motivator

Thanks once more. For anyone else looking for the answer on this page, @vijeta's comment above references my code before I edited it, where previously I had the query run in a table and was looking for a way to hide it.

Thus, there are two ways of accomplishing the answer to this question: run the query in a table and hide it, or just put your query in the same panel as the html form like I did in my edited comment.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Federated Search for Snowflake Is Now Generally Available on Splunk Cloud Platform

Splunk is excited to announce the General Availability (GA) of Federated Search for ...

Help Us Build Better Splunk Regex Puzzles (And Win Prizes!)

If you’ve spent any time in the Splunk Community Slack, you’ve likely seen our resident Splunk Trust ...

Fuel Your Journey: What’s Waiting for You at the .conf26 Acceleration Station

Navigating the show floor at .conf26 isn't just about keynotes and technical breakout sessions; it's also ...