How to use the C# snippets

Another feature of the Splunk extension for Visual Studio is built-in code snippets that allow you to quickly add complete, validated code for common scenarios to your project.

To use the code snippets:

  1. Position your cursor at the place in your code you want to insert the snippet.

  2. Type spl. IntelliSense will display a list of the available Splunk snippets, as shown here:

    Screen shot of a contextual menu in Visual Studio displaying the available code snippets
  3. Select the one you want, and then press the Tab key twice. Visual Studio pastes the snippet into your code.

Here is a list of all the installed snippets, including descriptions of what they do. Of course, the best way to find out what the snippets do is to invoke them yourself.

Shortcut Name Description
splconnect Connect to Splunk server Connects to a Splunk Enterprise server and runs a task using that connection.
spldispatch Get a job from a saved search Retrieves a report (saved search in Splunk Enterprise 5), looks up its history, and then dispatches either the last job run or a new job.
spljob Create a search job Creates a new search job.
spllistjobs List jobs Iterates through the jobs defined on the Splunk Enterprise server (for the current user).
spllistsavedsearches List saved searches Iterates through the reports (saved searches in Splunk Enterprise 5), defined on the Splunk Enterprise server (for the current user).
splnewsavedsearch Create a saved search Creates a new report (saved search in Splunk Enterprise 5).
splnonreportingexport Export from a nonreporting search Creates a new export search and iterates through the search results.
sploneshot Iterate over results of a oneshot search Creates a new one-shot search and iterates through the search results.
splrealtime Run a realtime search Creates a real-time search and iterates through the search results.
splreportingexport Export from a reporting search Creates a new export search and sets up a subscription to its preview results.
splresults Iterate over search results Sets up logic to iterate through the search results for a given job.

To view the list of Splunk SDK for C# code snippets, on the Tools menu, click Code Snippets Manager. In the Code Snippets Manager window under Language, choose Visual C#. Then, under Location, expand the triangle next to Splunk. The installed snippets are listed, as shown in the following screen shot.

Screen shot of a contextual menu in Visual Studio displaying the available code snippets

Click each snippet to see what it does (Description) and how to invoke it (Shortcut).