Getting Started with the App Framework

Testing your app

After you've created an app, you'll want to test and run it.

If you haven't already done so in the Anatomy of an app section, create the /dev_tutorial directory structure and populate it with the Example source code.

Typically, you would download an app from SplunkBase using the Manage apps option of the App menu or create a local .spl file, where the app would be installed in the $SPLUNKBASE/etc/apps directory. For demonstration purposes and initial debugging before your app is available on SplunkBase, it is easier to manually install the app, which is what this section describes.

Packaging and Installing
Running
Debugging

Packaging and Installing

The example dev_tutorial app has the following directory structure, in the $SPLUNK_HOME/etc/apps directory:



  1. Create a dev_tutorial directory, locally.
  2. Populate dev_tutorial with the directories shown in the figure and the Example source code files.
  3. Copy the whole dev_tutorial directory to the $SPLUNK_HOME/etc/apps directory, where all of your other apps are located.

Your app is now available to run.

Note: You can also compress your app in a tarball file with a .spl extension and use the App Manager to install your app.

Running

Run the dev_tutorial app the same way you would run any other Splunk app:

  1. Start splunkWeb and, if needed, login.
  2. Click the App drop-down menu and select the App Framework Tutorial app.
  3. Click the Examples drop-down menu in the upper-left and select the example you want to run. For Getting started, select Example: Using a Custom Module

Note: Make sure your app status is enabled .

Debugging

Debugging on your local machine, you can conveniently change your app code, in $SPLUNK_HOME/etc/apps/dev_tutorial, and rerun your app.

The way you restart your app depends on what code you changed. If you changed only client-side code, it is sufficient to upgrade the version number, using _bump, and re-run your app:

http://localhost:8000/en-US/_bump

Note: Make sure you clear the browser cache before re-running your app.

If you made changes to your XML files and need to reload configuration data, use debug/refresh in addition to _bump to refresh all EAI handlers that support reload:

http://localhost:8000/en-US/debug/refresh

If you changed server-side code, you need to restart Splunk and SplunkWeb:

  1. On the command line, type splunk restart.
  2. Login to SplunkWeb.
  3. Start App Framework Tutorial from the App menu.

Tip: You can specify global settings in your web.conf file, in the /default directory, that can be helpful for testing and debugging. For example, setting the JavaScript and CSS minify options. (See Admin Manual > web.conf)

Debugging JavaScript

You can use your favorite browser JavaScript debugger plugin, such as Firebug.

You'll notice that your JavaScript code is minified so you might want to expand it.

Note: Use console.debug("Your debug message"); to log messages to your debugger console.

Debugging Python

On the server, you can use the built-in Python logging facilities for debugging.

import logging
logger = logging.getLogger('splunk.module.CustomResultsTable')
   

You can enable debug logging, as described in Enable debug logging, and use the debug logging level:

logger.debug('your debug message')
   

For simple printf-style debugging, you'll find it easier to use the info logging level:

logger.info('your informative message')
   

Informative messages are logged in the $SPLUNK_HOME/var/log/splunk/web_service.log file.

You'll find most error messages, including Python execution errors, in the log file:

$SPLUNK_HOME/var/log/splunk/web_service.log