I want to create a new lookup file. In transforms.conf, that's pretty simple, it should look something like this:
[myLookup6]
filename = myLookup.csv
But how do I do that from SplunkJS?
I've found the appropriate docs, but haven't been able to divine the answer:
http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.Configurations.html
http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.8.0/splunkjs.Service.ConfigurationFile.ht...
http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.ConfigurationStanza.ht...
After a lot of trial and error, and then the help of a partner who had done even more trial and error (and is a better programmer than me), I got the answer.
The overall process is:
Here is the code that worked for me, on Splunk 6.5:
function dvtest(){
var appscope={}
appscope['owner'] = Splunk.util.getConfigValue("USERNAME");
appscope['app'] = utils.getCurrentApp()
appscope['sharing'] = "app"
var mystanza = []
mystanza['filename'] = "myLookup.csv"
var svc = mvc.createService();
var files = svc.configurations(appscope);
var fileDeferred = $.Deferred();
files.fetch({ 'search': 'name=transforms"' }, function(err, files) {
var transformsFile = files.item("transforms");
if (!transformsFile) {
// Create the file here
transformsFile = files.create('transforms', function(err, transformsFile) {
if (err) {
// Error case, throw an exception dialog to user here.
return;
}
fileDeferred.resolve(transformsFile);
});
}
else {
fileDeferred.resolve(transformsFile)
}
});
fileDeferred.done(function(transformsFile) {
transformsFile.create("myLookup6", mystanza, function(err, stanza) {
// Stanza now created -- go check transforms.conf if you don't believe me
}
)});
}
Hi there David,
Please take a look at this example application that has been built.
Developer Guidance - Setup View Example For Splunk:
https://splunkbase.splunk.com/app/3728/
Source code can be found here:
https://github.com/splunk/Developer_Guidance_Setup_View_Example
This app uses a setup view to configure Splunk configuration files. While the goal is different, the solution is the same, and much of the code can be reused in the goal you're seeking to accomplish.
It is meant to serve as a point of reference.
Please let me know if that's not sufficient.
After a lot of trial and error, and then the help of a partner who had done even more trial and error (and is a better programmer than me), I got the answer.
The overall process is:
Here is the code that worked for me, on Splunk 6.5:
function dvtest(){
var appscope={}
appscope['owner'] = Splunk.util.getConfigValue("USERNAME");
appscope['app'] = utils.getCurrentApp()
appscope['sharing'] = "app"
var mystanza = []
mystanza['filename'] = "myLookup.csv"
var svc = mvc.createService();
var files = svc.configurations(appscope);
var fileDeferred = $.Deferred();
files.fetch({ 'search': 'name=transforms"' }, function(err, files) {
var transformsFile = files.item("transforms");
if (!transformsFile) {
// Create the file here
transformsFile = files.create('transforms', function(err, transformsFile) {
if (err) {
// Error case, throw an exception dialog to user here.
return;
}
fileDeferred.resolve(transformsFile);
});
}
else {
fileDeferred.resolve(transformsFile)
}
});
fileDeferred.done(function(transformsFile) {
transformsFile.create("myLookup6", mystanza, function(err, stanza) {
// Stanza now created -- go check transforms.conf if you don't believe me
}
)});
}