Splunk Search

How to call Splunk custom endpoint using jquery ?

ecoquelin
Explorer

Dear all,

I wish I could make a call such as $.ajax(...) to my custom endpoint.

But which Splunk method should I use to automatically build the URI ? If I provide "/services/mycustomendpoint", it won't work as it depends on the app URI for example. But I wish I could avoid adding manually the app URI and other prefixes.

Which Splunk library should I use to get that URI from the context?

Thank you,

Tags (1)
0 Karma

arkadyz1
Builder

The REST endpoints under "/services" are not app-specific even though you put them you $SPLUNK_HOME/etc/apps/yourapp/bin, and they go via Splunk management port (8089 by default). This is somewhat of a problem - while your browser normally connects to http://yoursplunkhost:8000/en-US/app/yourapp, REST API calls go to https://yoursplunkhost:8089/services/yourcustomendpoint. This creates CORS problems unless you properly set HTTP headers in your custom endpoint. And it normally needs authentication, unless you set requireAuthentication = false in the endpoint's stanza in restmap.conf.

There is another way of creating custom endpoints - putting the scripts not in $SPLUNK_HOME/etc/apps/yourapp/bin, but in $SPLUNK_HOME/etc/apps/yourapp/appserver/controllers and defining it in $SPLUNK_HOME/etc/apps/yourapp/default/web.conf. This one goes through http://yoursplunkhost:8080/en-US/custom/yourapp/yourcustomendpoint and picks up the authentication of your browser page IIRC, but you'd better check the exact ways in the documentation.

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 ...