Created
December 21, 2021 11:11
-
-
Save marcusschiesser/eaf173393932a15332e10058d264caae to your computer and use it in GitHub Desktop.
Using URL path parameters with Custom REST endpoints in Splunk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[expose:url_path] | |
methods = GET | |
pattern = /api/v1/url_path/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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