Dashboards & Visualizations

access custom Rest endpoint using javascript

lweber
Path Finder

my restmap.conf looks like this:

[script:testrest]
match=/mytest
scripttype=python
handler=testhandler.MyHandler
output_modes=json
requireAuthentication=true

Accessing it with curl works like a charm.
But how can I fire a call to it from within a Splunk dashboard (using javascript)?

I tried something like:

var service = mvc.createService();
service.get("/mytest")

what obviously doesnt work...

Edit:
seems nobody can give me a hint, let me ask my question in a different way:
How can i tell Splunk to expose my REST endpoint under: http://127.0.0.1:8000/en-US/splunkd/__raw/mytest?

or more general:
How can i run (custom) server side code from within a dashboard using javascript?

Hope this helps to get into the right direction

0 Karma
1 Solution

lweber
Path Finder

ok. found the solution myself...

I had to add the following in my web.conf:

[expose:testrest]
pattern=mytest
methods=GET,POST,DELETE

now i can access it in js with:
service.get("/services/mytest")

View solution in original post

lweber
Path Finder

ok. found the solution myself...

I had to add the following in my web.conf:

[expose:testrest]
pattern=mytest
methods=GET,POST,DELETE

now i can access it in js with:
service.get("/services/mytest")

tmontney
Builder

The web.conf addition was exactly what I was missing. I originally copied it from another app (using it to learn how to build a custom rest handler). I would then test using port 8089 but couldn't get it to work from 443 (Splunk web). I kept thinking restmap.conf was the only file I had to update.

0 Karma

Dev999
Communicator

I made essentially the exactly same setup in a new app, but I got 404 error when calling service.post('services/myendpoint', ). I am using Splunk 7.2.0. Could you please take a look at my question:

https://answers.splunk.com/answers/699676/accessing-custom-endpoint-from-dashboard-javascrip.html

Thanks,
Tony

0 Karma

atari1050
Path Finder

Hi lweber-
I know this is VERY old, but could you point me to some python code or maybe some of your code that can show me more how you accessed the endpoint in the script? I am trying to create an app that will allow an admin to do REST calls within a dashboard that would normally take forever in GUI (and are not always convenient to do on the CLI - like mass job deletes, mass saved search updates, mass ID changes, etc).

Thanks!
Mike

0 Karma

i2sheri
Communicator

where did you link this end point to your python code ? in restmap.conf ?

0 Karma

lweber
Path Finder

yes, restmap.conf:

[script:testrest]
match=/mytest
scripttype=python
handler=myscript.MyClass
output_modes=json
requireAuthentication=true

i2sheri
Communicator

thanks, works with 6.3.
I can use this solution to get rid of frame work app, which does not work with requireClientCert=true and is deprecated now.

0 Karma
Get Updates on the Splunk Community!

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

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...