Dashboards & Visualizations

access custom Rest endpoint using javascript

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

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

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

Path Finder

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

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

Communicator

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

0 Karma

Path Finder

yes, restmap.conf:

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

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