Skip to content

Latest commit

 

History

History
 
 

README.md

Hello World Examples

This folder contains several "Hello World"-style examples. These examples do not have any command-line processing or complicated logic. Instead, all of the examples hard-code the connection information for splunkjs.

One note is that we do test the examples in our test harness, so there is a way to sideload connection information. However, you can safely ignore this.

These files demonstrate working with the splunkjs.Service.Applications collection and splunkjs.Service.Application entity. It will list all the apps, and for each one print its name.

The only difference between the two files is that the latter uses the built-in splunkjs.Async module to make asynchronous control-flow easier.

This example will show you how to add a new REST API endpoint to the Splunk SDK for JavaScript.

These files demonstrate working with the splunkjs.Service.FiredAlerts collection and splunkjs.Service.AlertGroup entity. It will list all the alert groups, and for each one print its name and the search query associated with it.

The only difference between the two files is that the latter uses the built-in splunkjs.Async module to make asynchronous control-flow easier.

These files demonstrate how to create and delete splunkjs.Service.AlertGroup entities.

The only difference between the two files is that the latter uses the built-in splunkjs.Async module to make asynchronous control-flow easier.

These files demonstrate working with the splunkjs.Service.SavedSearches collection and splunkjs.Service.SavedSearch entity. It will list all the saved searches, and for each one print its name and the search query associated with it.

The only difference between the two files is that the latter uses the built-in splunkjs.Async module to make asynchronous control-flow easier.

These files demonstrate how to create and delete splunkjs.Service.SavedSearch entities.

These files demonstrate running searches on Splunk using the SDK. They will run the search, print out progress (if available), search statistics (if available), and finally, print out the search results (including some key-value fields).

These examples go over the space of possible search types:

  • search_normal.js: execute a search with exec_mode=normal, wait untli the job is done, and then print out job statistics and the search results.

  • search_blocking.js: execute a search with exec_mode=blocking, which will not return from the REST call until the job is done. Once it is done, it will print out job statistics and the search results.

  • search_oneshot.js: execute a search with exec_mode=oneshot, which will not return the REST call until the job is done, and then it will simply return the search results, rather than the search job ID. Once it is done, we print out the results.

This example shows how to work with realtime searches. It will execute a realtime search that will collect statistics about all events from "now" to infinity (as noted by the use of earliest_time=rt and latest_time=rt).

Once the job is created, it will poll the results every second, and print them out.

Since a realtime search is never "done", we only iterate for 5 times before we terminate the loop.

Files: get_job.js

This example will show how to get a Job by it's sid without fetching a collection of Jobs.

Files: log.js

This example shows how you can send data to Splunk over HTTP from within your application by using the Service.log method in the JavaScript SDK.

We create a utility Logger class that encapsulates various logging levels, and we can then simply call logger.log, logger.error, etc.