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!

.conf24 | Registration Open!

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

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...