Archive

Determine the current app

kkalmbach
Path Finder

Is there any way (in a view or otherwise) to determine the current application that you are in?

We are going to have basically the same app deployed several times (using links), each app will have a different name and we would like to change the index that we are searching on based upon the app name.

If we could get the current url, we could also parse that.

I can't really use the default index function because we are searching multiple indexes (a real time index and a summary index) within the same app, but each index will always have the form of "XXX_" and "XXX_summary_".

Thanks

-Kevin

Tags (2)
0 Karma
1 Solution

sideview
SplunkTrust
SplunkTrust

Well, from Javascript you can do Splunk.util.getCurrentApp() and Splunk.util.getCurrentView()

However you probably want to use these as $appName$ variables in your searches, within your views.

You could write your own custom UI module but this is pretty involved and probably not what you want to do. Instead if you download the Sideview Utils app and follow its instructions for how to use its custom modules from inside your app's views, you can provide the current app name to your modules fairly easily using a CustomBehavior module:

1) You'd have a CustomBehavior module in the view that wrapped the modules you want to be able to use $appName$,

<module name="CustomBehavior">
  <param name="customBehavior">provideAppName</param>
  ... (everything goes here)
</module>

2) and then in application.js, you'd put this:

if (typeof(Sideview)!="undefined")  {
    $(document).bind("allModulesInHierarchy", function() {        
        Sideview.utils.forEachModuleWithCustomBehavior("provideAppName", function(i,module) {
            module.getModifiedContext = function() {
                var context = this.getContext();
                context.set("appName", Splunk.util.getCurrentApp());
                return context;
            }
        });
    }
}

and now you'll be able to use $appName$ in any Search modules or any HTML modules that are nested inside that CustomBehavior.

View solution in original post

0 Karma

niketnilay
Legend

In Case you are not running on Splunk 6.5 yet, for the older versions check out Define custom tokens example in Splunk 6.x Dashboard Examples App which gets environment tokens like App name and User Name though Javascript.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

sloshburch
Ultra Champion

I just discovered that, starting with 6.5.0, there's some sweet new global tokens!

One of which is $env:app$

http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Use_global_tokens_to_access_environmen...

sideview
SplunkTrust
SplunkTrust

Well, from Javascript you can do Splunk.util.getCurrentApp() and Splunk.util.getCurrentView()

However you probably want to use these as $appName$ variables in your searches, within your views.

You could write your own custom UI module but this is pretty involved and probably not what you want to do. Instead if you download the Sideview Utils app and follow its instructions for how to use its custom modules from inside your app's views, you can provide the current app name to your modules fairly easily using a CustomBehavior module:

1) You'd have a CustomBehavior module in the view that wrapped the modules you want to be able to use $appName$,

<module name="CustomBehavior">
  <param name="customBehavior">provideAppName</param>
  ... (everything goes here)
</module>

2) and then in application.js, you'd put this:

if (typeof(Sideview)!="undefined")  {
    $(document).bind("allModulesInHierarchy", function() {        
        Sideview.utils.forEachModuleWithCustomBehavior("provideAppName", function(i,module) {
            module.getModifiedContext = function() {
                var context = this.getContext();
                context.set("appName", Splunk.util.getCurrentApp());
                return context;
            }
        });
    }
}

and now you'll be able to use $appName$ in any Search modules or any HTML modules that are nested inside that CustomBehavior.

View solution in original post

0 Karma

kkalmbach
Path Finder

Nick,
Thanks, we are already using sideview, so this will work out great for us.
Thanks,
-Kevin

0 Karma