All Apps and Add-ons

Sideview Utils (free internal use license): How to create a script in a dashboard that will post JSON data and interact with external REST API upon button click?

alpna84
Explorer

I have created dashboard with a button using Sideview Utils. I want to call script or backend program on button click to post JSON data and interact with external REST API and want to display response back on dashboard.
I get data to be posted on button click using custom behavior.

I looked in to few questions related to it but still not clear the approach to be used for my requirement.
Can i achieve it using Sideview Utils?

1 Solution

sideview
SplunkTrust
SplunkTrust

I can tell you more about the general area, and I'll try to update this answer again later based on our comments.

First, if you ultimately want to interact with an external REST API, meaning it's not a Splunk API, you'll have to first create a custom endpoint that is in the Splunk world and in the implementation thereof, proxy from that to your external API on the other host. Basically security settings in modern browsers prevent them from talking to any host beyond the one that served the HTML page.

However, I would start with the "Table" module documentation. Because this sort of question has historically been asked most as "How can I put buttons into my table rows and make happen when users click one of the buttons", the example that is most fleshed out is under the Table docs.

Specifically - "Module Documentation > The Table Module > Table - Embedding examples" . However I advise reading through the 4 preceding pages of Table examples at least a bit as the examples tend to build on eachother.

What you'll find, is a Table that has lots of green buttons "embedded" in it, and where clicking that button submits a request to a custom REST endpoint implemented in python, (whose config is within sideview_utils/default/web.conf and whose python code can be found at sideview_utils/appserver/controllers/example_controller.py)

However.. where it falls short of what you're asking
-- Obviously it's not hitting any external API - you'd have to implement that in your own controller and basically proxy out to wherever.
-- the example doesn't have anything that can interact with the response. In fact it just has a Redirector module send an Iframe to the given URL. If you need to interact with the JSON results, you would want to write a CustomBehavior instead and POST to the endpoint manually in there, etc.

You might consider writing a custom search command instead. You can marshal the return values from your API as key value pairs in Splunk search result set. this is a more common way of doing this believe it or not. You would push all this API complexity into the behavior of that search command, and then "consume the results" of the call by having the results come out as result rows with different key value pair "fields", that you can then interact with with more standard Sideview ui modules.

View solution in original post

0 Karma

sideview
SplunkTrust
SplunkTrust

I can tell you more about the general area, and I'll try to update this answer again later based on our comments.

First, if you ultimately want to interact with an external REST API, meaning it's not a Splunk API, you'll have to first create a custom endpoint that is in the Splunk world and in the implementation thereof, proxy from that to your external API on the other host. Basically security settings in modern browsers prevent them from talking to any host beyond the one that served the HTML page.

However, I would start with the "Table" module documentation. Because this sort of question has historically been asked most as "How can I put buttons into my table rows and make happen when users click one of the buttons", the example that is most fleshed out is under the Table docs.

Specifically - "Module Documentation > The Table Module > Table - Embedding examples" . However I advise reading through the 4 preceding pages of Table examples at least a bit as the examples tend to build on eachother.

What you'll find, is a Table that has lots of green buttons "embedded" in it, and where clicking that button submits a request to a custom REST endpoint implemented in python, (whose config is within sideview_utils/default/web.conf and whose python code can be found at sideview_utils/appserver/controllers/example_controller.py)

However.. where it falls short of what you're asking
-- Obviously it's not hitting any external API - you'd have to implement that in your own controller and basically proxy out to wherever.
-- the example doesn't have anything that can interact with the response. In fact it just has a Redirector module send an Iframe to the given URL. If you need to interact with the JSON results, you would want to write a CustomBehavior instead and POST to the endpoint manually in there, etc.

You might consider writing a custom search command instead. You can marshal the return values from your API as key value pairs in Splunk search result set. this is a more common way of doing this believe it or not. You would push all this API complexity into the behavior of that search command, and then "consume the results" of the call by having the results come out as result rows with different key value pair "fields", that you can then interact with with more standard Sideview ui modules.

0 Karma

alpna84
Explorer

Thanks for your response . I will look in to table embedding examples . Yes , it's not splunk API. I have further question , Can jquery library be used to interact with Rest api in custom behaviour , Does SideView util support that?

0 Karma

sideview
SplunkTrust
SplunkTrust

Certainly, yes. jquery is already there as a dependency of both Splunk's and Sideview's UI code, and you can make $.post and $.ajax calls as you would elsewhere. (Note that this won't help you get around the need to basically proxy from a splunk endpoint to your external api. )

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...