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
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")
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")
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.
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
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
where did you link this end point to your python code ? in restmap.conf ?
yes, restmap.conf:
[script:testrest]
match=/mytest
scripttype=python
handler=myscript.MyClass
output_modes=json
requireAuthentication=true
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.