JSFiddle - React, Tailwind, and code Playground

by John Doe

HTML

<html>

  <head>
    <meta charset="utf-8">
    <title>How to start a Splunk session</title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="splunk.js"></script>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

    <script type="text/javascript" charset="utf-8">
      var http = new splunkjs.ProxyHttp("/proxy");

      // Create a Service instance and log in 
      var service = new splunkjs.Service(http, {
        username: "admin",
        password: "changeme",
        scheme: "https",
        host: "localhost",
        port: "8089",
        version: "5.0"
      });
      // Search everything and return the first 10 results
      var searchQuery = ["search sourcetype=firewall | stats count by SRC | sort -count | head 2", "search sourcetype=firewall | stats count by DST | sort -count | head 2"];


      function displayApps(e) {

        var val = "";
        var val1 = "";
        var val2 = "";
        // Set the search parameters--specify a time range
        var searchParams = {
          earliest_time: "2011-06-19T12:00:00.000-07:00"
        };

        // Run a oneshot search that returns the job's results
        service.oneshotSearch(
          e,
          searchParams,
          function(err, results) {
            // Display the results
            var fields = results.fields;
            var rows = results.rows;
            var myApps = "";



            for (var i = 0; i < rows.length; i++) {
              //testing
              val = rows[i];
              //val1 removes first index and keeps all other indexes
              val1 += val.slice(1) + ',';
              //splits values by ',' and stores into array
              val1 = val1.split(',');
              //converts val1 string values into integers
              val1 = val1.map(Number);
              //val2 keeps index 0 and removes last index
              val2 += val.slice(0, 1) + ',';
    ...