<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I create a transforms.conf stanza from SplunkJS? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270403#M3393</link>
    <description>&lt;P&gt;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. &lt;/P&gt;

&lt;P&gt;The overall process is:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Create a service object&lt;/LI&gt;
&lt;LI&gt;Instantiate the configurations object with your scope (app, user, etc.)&lt;/LI&gt;
&lt;LI&gt;Fetch the existing configurations for your file&lt;/LI&gt;
&lt;LI&gt;Create a ConfigurationFile object with a blank config, or pull the existing one &lt;/LI&gt;
&lt;LI&gt;With your file, create a new stanza&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here is the code that worked for me, on Splunk 6.5:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;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
         }
    )});
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Jan 2017 13:01:36 GMT</pubDate>
    <dc:creator>David</dc:creator>
    <dc:date>2017-01-31T13:01:36Z</dc:date>
    <item>
      <title>How can I create a transforms.conf stanza from SplunkJS?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270402#M3392</link>
      <description>&lt;P&gt;I want to create a new lookup file. In transforms.conf, that's pretty simple, it should look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[myLookup6]
filename = myLookup.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But how do I do that from SplunkJS?&lt;/P&gt;

&lt;P&gt;I've found the appropriate docs, but haven't been able to divine the answer:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.Configurations.html"&gt;http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.Configurations.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.8.0/splunkjs.Service.ConfigurationFile.html"&gt;http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.8.0/splunkjs.Service.ConfigurationFile.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.ConfigurationStanza.html"&gt;http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.1/splunkjs.Service.ConfigurationStanza.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 12:51:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270402#M3392</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2017-01-31T12:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a transforms.conf stanza from SplunkJS?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270403#M3393</link>
      <description>&lt;P&gt;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. &lt;/P&gt;

&lt;P&gt;The overall process is:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Create a service object&lt;/LI&gt;
&lt;LI&gt;Instantiate the configurations object with your scope (app, user, etc.)&lt;/LI&gt;
&lt;LI&gt;Fetch the existing configurations for your file&lt;/LI&gt;
&lt;LI&gt;Create a ConfigurationFile object with a blank config, or pull the existing one &lt;/LI&gt;
&lt;LI&gt;With your file, create a new stanza&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here is the code that worked for me, on Splunk 6.5:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;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
         }
    )});
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 13:01:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270403#M3393</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2017-01-31T13:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a transforms.conf stanza from SplunkJS?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270404#M3394</link>
      <description>&lt;P&gt;Hi there David,&lt;/P&gt;

&lt;P&gt;Please take a look at this example application that has been built.&lt;/P&gt;

&lt;P&gt;Developer Guidance - Setup View Example For Splunk:&lt;BR /&gt;
&lt;A href="https://splunkbase.splunk.com/app/3728/"&gt;https://splunkbase.splunk.com/app/3728/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Source code can be found here:&lt;BR /&gt;
&lt;A href="https://github.com/splunk/Developer_Guidance_Setup_View_Example"&gt;https://github.com/splunk/Developer_Guidance_Setup_View_Example&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;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.&lt;/P&gt;

&lt;P&gt;It is meant to serve as a point of reference.&lt;/P&gt;

&lt;P&gt;Please let me know if that's not sufficient.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 04:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-can-I-create-a-transforms-conf-stanza-from-SplunkJS/m-p/270404#M3394</guid>
      <dc:creator>lknecht_splunk</dc:creator>
      <dc:date>2017-09-25T04:55:09Z</dc:date>
    </item>
  </channel>
</rss>

