Dashboards & Visualizations

How to create Javascript for a button on a splunk dashboard?

Roy_9
Motivator

Hello,

Can someone please kindly help me with the Javascript for the below criteria.

create a JavaScript that calls PagerDuty using a button, eventually passing parameters from the dashboard.


Thanks

Tags (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Roy_9 

Let's follow the best practice for calling third-party API from Splunk Dashboard. 

 

Please check below pictorial view for Flow understanding.

Screenshot 2023-01-21 at 1.37.54 PM.png

I hope this will help you.

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Roy_9 

Let's follow the best practice for calling third-party API from Splunk Dashboard. 

 

Please check below pictorial view for Flow understanding.

Screenshot 2023-01-21 at 1.37.54 PM.png

I hope this will help you.

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

Roy_9
Motivator

Thanks @kamlesh_vaghela , will try to implement the suggested approach.

0 Karma

Roy_9
Motivator

Did anyone has developed a java script for this similar kind of situation? any leads would be highly appreciated

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Roy_9 

May be it's late but answering.

function callCustomAPI() {
        var service = mvc.createService({ owner: "nobody" });
        //send data to server
        console.log(selected_values_array.join());
        var params = selected_values_array.join();
        service.request("/services/my-api-path","POST", {}, {}, JSON.stringify(params), {'Content-Type': 'application/json'}, function(err, resp) {
            // Handle response    
            if(resp != null){
              if(resp.status == 200){  
                //do something
              } else {
                //do something with status !=200
              }
            }
            // Handle error
            if(err != null){
              //handle error
            }
          });
     }

 

You can call callCustomAPI from the button click event or any other javascript event.

 

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...