Dashboards & Visualizations

How do you access the custom endpoint from dashboard javascript?

Dev999
Communicator

I have configured my REST API custom endpoint within a new app, and tested successfully through the service web's UI (:8089). But got 404 from javascript. Splunk version: 7.2.0, User account has admin role:

service.post('services/my_submit', data, function...
http://mysplunk:8000/en-US/splunkd/__raw/services/my_submit?output_mode=json 404 (Not Found)

Accessing from service port prints 'success' from the python script:

https://mysplunk:8089/services/my_submit

web.xml:

[expose:my_submit]
pattern=my_submit
methods=POST

restmap.conf:

[script:my_submit]
match=/my_submit
handler=my_submit.Submit

my_submit.py:

import splunk
class Submit(splunk.rest.BaseRestHandler):
    def handle_submit(self):
        try:
            self.response.setHeader('content-type', 'text/html')
            self.response.write('success')
        except:
            self.response.setHeader('content-type', 'text/html')
            self.response.write('<p>Uh oh! Something wrong!</p>')

    handle_GET = handle_submit    

Should I use 'services/my_submit' as the endpoint in the service call? What else could I miss? Your help is greatly appreciated.
Tony

0 Karma
1 Solution

Dev999
Communicator

After correcting GET/POST, I realized the problem was that the file name should be web.conf, not web.xml.

View solution in original post

Dev999
Communicator

After correcting GET/POST, I realized the problem was that the file name should be web.conf, not web.xml.

lweber
Path Finder

seems that you are mixing Get and Post.

try:

web.xml:
methods=POST,GET

my_submit.py:
handle_GET = handle_POST = handle_submit

and try both js methods:
service.post(...) and service.get(...)

0 Karma

Dev999
Communicator

Thanks lweber. I can see missing handle_POST in python would be a problem. If I replace handle_GET with handle_POST only, I got a specific python error (object has no attribute 'handle_GET' ) on port 8089 web. Now I have both as you suggested, and added to web.xml, but still gets 404 error regardless I do service.get or service.post. I can do curl with -XPOST to get the correct response from port 8089.

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