Skip to content

Instantly share code, notes, and snippets.

@marcusschiesser
Created December 21, 2021 11:11
Show Gist options
  • Save marcusschiesser/eaf173393932a15332e10058d264caae to your computer and use it in GitHub Desktop.
Save marcusschiesser/eaf173393932a15332e10058d264caae to your computer and use it in GitHub Desktop.
Using URL path parameters with Custom REST endpoints in Splunk
[script:url_path]
match = /api/v1/url_path
script = url_path_handler.py
scripttype = persist
handler = url_path_handler.UrlPathHandler
requireAuthentication = true
output_modes = json
passPayload = false
import json
from splunk.persistconn.application import PersistentServerConnectionApplication
class UrlPathHandler(PersistentServerConnectionApplication):
def __init__(self, command_line, command_arg):
PersistentServerConnectionApplication.__init__(self)
def handle(self, in_string):
request = json.loads(in_string)
return {'payload': {'url_parameter': request['path_info']},
'status': 200
}
[expose:url_path]
methods = GET
pattern = /api/v1/url_path/*
@marcusschiesser
Copy link
Author

After deploying this handler, you can pass parameters to the REST endpoint inside of the URL path, e.g. for passing 325039 use:
http://localhost:8000/en-US/splunkd/__raw/servicesNS/-/{appName}/api/v1/url_path/325039

Note: The *.conf files need to be in the default folder and the .py script in the bin folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment