Getting Data In

How to write to CSV file in splunk without using a search manager

theoborrero
Explorer

Hi ,

We have created a splunk application using HTML format. In our application we have a "Request Alert" button that has a popup which takes user input text fields then writes out to a csv file . The code we are using for this works fine for taking the input field and storing them in a csv file in the local computer. The file location path( we give it works just fine if it is in our local computer , but once we give it the path to where splunk stores all the other csv files that are created , it does not ever work.

Is it possible to write to a csv file in splunk without using a search manager ? I have an example of the code we are using listed below.

   <script>

              function closePopup(){
                document.getElementById('light').style.display='none';
                document.getElementById('fade').style.display='none';
              }
                //Save alert details in CSV file

              function writeToFile(d1, d2, d3, d4, d5){
              var fso = new ActiveXObject("Scripting.FileSystemObject");
              var fileLoc = "C:\\Users\\plm3030\\Desktop\\Splunk Docs\\sample.csv";
              var fh = fso.OpenTextFile(fileLoc, 8, false, 0);

              fh.WriteLine(d1 + ',' + d2 + ',' + d3 +',' + d4+',' + d5);
              fh.Close();
              closePopup();
              alert("Your alert submitted successfully!");
              }
              var submitAlert = document.getElementById("submitAlert");
              submitAlert.onclick = function () {
              var queryVal      = document.getElementById("queryVal").value;
              var poc = document.getElementById("poc").value
              var email = document.getElementById("emailGroup").value;
              var alertName = document.getElementById("alertName").value;
              var details = document.getElementById("details").value;
              writeToFile(queryVal, poc, email, alertName, details);
              }
                //End Alert Details to CSV
            </script>
Tags (1)
0 Karma

woodcock
Esteemed Legend

Check out this app (either use it or figure out how it does it):

https://splunkbase.splunk.com/app/1724/

0 Karma

Yasaswy
Contributor

Hi,
If you are looking for an "out of splunk" solution... you will need some server side scripting. You can use XMLHttpRequest Object in your client script. Check out the basic tutorial here..

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...