Splunk integration example
With IBM Cloud Pak® for AIOps, you can add custom tools to the topology viewer, such as a custom tool integration with Splunk. The following example creates a custom tool for searching a Splunk repository. This tool can be accessed from the right-click context menu on the topology viewer when you are viewing a resource topology.
Note: You must install Splunk Enterprise and Splunk Forwarder before you can define a custom tool with the following example. The following example was tested with Splunk 8.1.0. For more information, see Splunk .
About this example
The following example code creates a custom tool that can be accessed from the right-click context menu. With this tool, you can use the properties of the resource that is selected in a topology when you click to open the tool to search a specific Splunk repository. This specific tool searches Splunk for logs that match the name of an IBM Cloud Pak for AIOps resource. This search can help you determine whether Splunk has registered any log information about the selected resource.
If you want to customize the following example code, you can change the values for the following properties:
-
splunkUrl
The base URL of your Splunk instance
-
splunkRepository
The Splunk repository you want to search
-
searchValue
The dynamically created
searchTerm
used in Splunk
In addition, you can use any IBM Cloud Pak for AIOps properties that are associated with the resource to create your tool. You can also define the tool response for when a search is unsuccessful.
Example
// Set the Splunk instance url
var splunkUrl = 'host:port';
// This will store the value that you want to search in Splunk
var searchValue = '';
// This will search results for defined period
// 0 = all time
// -15m = last 15 mins
// -24h = last 24 hours
// -7d = last 7 days
var searchEarliest = "0";
// This flag is set if you find a valid search value
var foundValidSearchValue = false;
if (asmProperties && asmProperties.name) {
searchValue = "\"" + asmProperties.name + "\"";
foundValidSearchValue = true;
} else {
var status = 'critical';
var message = 'Unable to find name property for Splunk search request';
asmFunctions.showToasterMessage(status, message);
}
// DO NOT MODIFY THE LINES BELOW
if (foundValidSearchValue) {
var searchLatest = '';
if(searchEarliest!="0") {
searchLatest="now"
}
var encodedSearchValue = encodeURI(searchValue);
var searchQuery = '/en-US/app/search/search?q=search%20index%3D*%20'+encodedSearchValue+"&earliest="+searchEarliest+"&latest="+searchLatest;
window.open(splunkUrl+searchQuery);
}