All Apps and Add-ons

Sideview button action to refresh page

craigkleen
Communicator

There's probably a quick way to do this with a customBehavior, but all those warnings on the docs for customBehavior make me want to ask first before trying it. I've followed instructions from:

https://answers.splunk.com/answers/68392/trigger-shell-script-from-dashboard-button.html

and I've got a nifty dashboard that will call a python script to take some action, but when I click the button, there's no refresh of the page that would indicate to the user that an action was taken. I do have the button appending to an outputcsv which records the action and displays it at the bottom of the page in another table. The page will eventually refresh to show a new entry in a table, but I'd like the button to immediately refresh the page too. This way users of the page don't start clicking >1 time.

1 Solution

sideview
SplunkTrust
SplunkTrust

The answer I gave years ago seems pretty flawed now. Here is a much better example.

If you create a csv lookup called "acknowledged_sourcetypes_example", and give it two columns "sourcetype", and "acknowledged", then you can run the following example locally.

Since it's Sideview XML view, it has no source code to read. the downside of course is you get to read a bunch of XML and learn an extremely unusual set of UI development conventions.

-- In every row of the rendered table, it presents an "acknowledge" button, for sourcetypes that do not have "acknowledged=1" set in the given lookup.
-- When that button is clicked,
a) a search is run that adds the given "acknowledged" row to that lookup, meaning on subsequent runs of the same search and subsequent renders of this same table, the button will not be shown.
b) when the button is clicked, the button dissappears immediately.
c) when the search appending the acknowledged row to the lookup completes a few moments later, a simple dynamic message is written out where the button was, here just saying "success".

<view template="dashboard.html" >
  <label>Table-Embedding Example - embedding action buttons</label>
  <module name="AccountBar" layoutPanel="appHeader" />
  <module name="AppBar" layoutPanel="appHeader" />
  <module name="SideviewUtils" layoutPanel="appHeader" />

  <module name="Messaging" layoutPanel="messaging" />

  <module name="HTML" layoutPanel="viewHeader">
    <param name="html"><![CDATA[
    <h1>Page title goes here</h1>
    ]]></param>
  </module>

  <!-- best practice for all sideview xml views to have a URLLoader module -->
  <module name="URLLoader" layoutPanel="panel_row1_col1" autoRun="True">

    <!-- our main search gets two secret fields that will not be displayed in the table.-->
    <module name="Search" layoutPanel="panel_row1_col1">
      <param name="search"><![CDATA[
index=_internal source=*metrics.log group="per_sourcetype_thruput" 
| head 1000 
| stats sum(kb) as totalKB by series 
| rename series as sourcetype
| eval actions="PLACEHOLDER"
| streamstats count as rowNumber
| lookup acknowledged_sourcetypes_example sourcetype OUTPUT acknowledged
| fillnull acknowledged value="0"
      ]]></param>

      <module name="Pager">

        <module name="Table">
          <!-- they need to be in the data for our logic, but not displayed -->
          <param name="hiddenFields">rowNumber,acknowledged</param>

          <!-- this module config is embedded in each "actions" cell in our table -->
          <module name="Switcher" group="row.fields.actions">
            <!-- basically only show the Button for rows where the ack field is "0" -->
            <param name="selectedGroup">$row.fields.acknowledged$</param>

            <module name="Button" group="0">
              <param name="label">Acknowledge</param>
              <param name="allowAutoSubmit">False</param>
              <!-- We paint this CSS class on here so we can hide the button onclick later -->
              <param name="cssClass">customButton$row.fields.rowNumber$</param>

              <!-- This is the search that then adds the new acknowledgement to the lookup -->
              <module name="Search">
                <param name="search"><![CDATA[
| inputlookup acknowledged_sourcetypes_example 
| append [
  | makeresults 
  | eval sourcetype="$row.fields.sourcetype$" 
  | eval acknowledged="1"
] 
| stats max(acknowledged) as acknowledged by sourcetype
| outputlookup acknowledged_sourcetypes_example
| eval message="Success!"
                ]]></param>

                <!-- doesn't really have to be a dynamic message but it's easy enough and might be useful -->
                <module name="HTML">
                  <param name="html"><![CDATA[
                    $results[0].message$
                  ]]></param>
                </module>
                <!-- when the push hits this module it hides the current row's button -->
                <module name="ShowHide">
                  <param name="hide">.customButton$row.fields.rowNumber$</param>
                </module>
              </module>
            </module>
          </module>
          <!-- thus endeth the table-embedding. -->

        </module>
      </module>
    </module>
  </module>

</view>

View solution in original post

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...