Splunk Dev

Can I get the current app from Python?

timpgray
Path Finder

I notice there is a method to get the current apps dir from python. There is also a getCurrentApp() available in javascript, but I need the current app from Python.

Does anyone have any suggestions?

Tags (2)
1 Solution

araitz
Splunk Employee
Splunk Employee

Which type of python file? We tend to use python's __file__ attribute. I assume that you have imported os and cherrypy at least.

For example, in the file $SPLUNK_HOME/etc/apps/TA-opseclea/appserver/controllers/:

 app_name = __file__.split('.')[-2]

If I was implementing a controller method where a request was routed to me:

@route('/:app/:action=edit/:name')
@expose_page(must_login=True, methods=['GET']) 
def edit(self, app, action, name, **kwargs):
    host_app = cherrypy.request.path_info.split('/')[3]

For a scripted input in an app's .\bin directory:

app_name = __file__.split(os.sep)[-3]

View solution in original post

0 Karma

araitz
Splunk Employee
Splunk Employee

Which type of python file? We tend to use python's __file__ attribute. I assume that you have imported os and cherrypy at least.

For example, in the file $SPLUNK_HOME/etc/apps/TA-opseclea/appserver/controllers/:

 app_name = __file__.split('.')[-2]

If I was implementing a controller method where a request was routed to me:

@route('/:app/:action=edit/:name')
@expose_page(must_login=True, methods=['GET']) 
def edit(self, app, action, name, **kwargs):
    host_app = cherrypy.request.path_info.split('/')[3]

For a scripted input in an app's .\bin directory:

app_name = __file__.split(os.sep)[-3]
0 Karma

timpgray
Path Finder

I am writing a custom search command. Looks like the last option you presented may be the one. I will give it a shot. Thanks

0 Karma
Get Updates on the Splunk Community!

Accelerate Service Onboarding, Decomposition, Troubleshooting - and more with ITSI’s ...

Accelerate Service Onboarding, Decomposition, Troubleshooting - and more! Faster Time to ValueManaging and ...

New Release | Splunk Enterprise 9.3

Admins and Analyst can benefit from:  Seamlessly route data to your local file system to save on storage ...

2024 Splunk Career Impact Survey | Earn a $20 gift card for participating!

Hear ye, hear ye! The time has come again for Splunk's annual Career Impact Survey!  We need your help by ...