---
title: "splunk test1"
author: "quguilai"
date: "2017-08-14T22:47:13Z"
tags: []
categories: ["行业应用"]
slug: "splunk-test1"
draft: false
lastmod: "2017-08-15T22:59:03Z"
id: 2389688
url: "https://qgl.iteye.com/blog/2389688"
---

curl -k -u admin:changeme  https://localhost:8089/services/auth/login -d username=admin -d password=changeme

http://dev.splunk.com/view/SP-CAAAEWS

http://docs.splunk.com/Documentation/Splunk/6.6.2/RESTREF/RESTaccess#auth.2Flogin

 

 

&lt;!DOCTYPE html&gt;

&lt;html lang="en"&gt;

&lt;head&gt;

    &lt;meta charset="utf-8"&gt;

    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;

    &lt;title&gt;Search Controls: Tokens&lt;/title&gt;

 

    &lt;link rel="stylesheet" type="text/css" href="static/splunkjs/css/bootstrap.css" /&gt;

    &lt;style&gt;

        .main-area {

            padding: 30px;

        }

    &lt;/style&gt;

&lt;/head&gt;

 

&lt;body&gt;

    &lt;div&gt;

        &lt;div class="main-area"&gt;

            &lt;p&gt;This example shows how to set up SearchBar and SearchControls views using Django tags, and sync them with a SearchManager using tokens.&lt;/p&gt;

            &lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; The Timeline view can't be synced using tokens. Use events instead.&lt;/p&gt;

 

            &lt;div id="mysearchbar1"&gt;&lt;/div&gt;

            &lt;div id="mysearchcontrols1"&gt;&lt;/div&gt;

            &lt;div id="mytable1"&gt;&lt;/div&gt;

        &lt;/div&gt;

    &lt;/div&gt;

 

    &lt;script src="static/splunkjs/config.js"&gt;&lt;/script&gt;

 

    &lt;script&gt;

        // Configure SplunkJS Stack

        splunkjs.config({

   scheme: 'https',

   host: '192.168.1.6',

   port: 8089,

   authenticate: {username: 'admin', password: 'abcd'},

});

        /* splunkjs.config({

            scheme: "https",

            host: "localhost",

            port: 8089,

            authenticate: function(done) { 

                require([

                    "jquery",

                    "jquery.cookie"

                ], function($) {

                    // Retrieve the session key and username from cookies

                    var splunkSessionKey = $.cookie("splunk\_sessionkey");

                    var splunkCurrentUser = $.cookie("splunk\_username");

 

                    // Log in using the session key and username

                    if (splunkSessionKey) {

                        done(null, {sessionKey: splunkSessionKey, username: splunkCurrentUser}); 

                    }

                    // If there is no session key, redirect to the login form

                    else {

                        window.location.replace("login\_form.html");

                    }

                });

            }

        }); \*/

        

        // Configure the web site's base URL

        require.config({

            baseUrl: "static/"

        });

 

        // Set up the Web Framework components

        var deps = [

            "splunkjs/ready!",

            "splunkjs/mvc/searchmanager",

            "splunkjs/mvc/searchbarview",

            "splunkjs/mvc/searchcontrolsview",

            "splunkjs/mvc/tableview"

        ];

        require(deps, function(mvc) {

            // Load individual components

            var SearchManager = require("splunkjs/mvc/searchmanager");

            var SearchbarView = require("splunkjs/mvc/searchbarview");

            var SearchControlsView = require("splunkjs/mvc/searchcontrolsview");

            var TableView = require("splunkjs/mvc/tableview");

 

            // Create the search manager and views

            var mysearch = new SearchManager({

                id: "search1",

                search: mvc.tokenSafe("$searchquery$"),

                earliest\_time: mvc.tokenSafe("$earlyval$"),

                latest\_time: mvc.tokenSafe("$lateval$"),

                app: "search",

                preview: true,

                required\_field\_list: "\*",

                status\_buckets: 300

            });

 

            var mysearchbar = new SearchbarView({

                id: "searchbar1",

                managerid: "search1",

                value: mvc.tokenSafe("$searchquery$"),

                timerange\_earliest\_time: mvc.tokenSafe("$earlyval$"),

                timerange\_latest\_time: mvc.tokenSafe("$lateval$"),

                default: "index=\_internal | head 100",

                el: $("#mysearchbar1")

            }).render();

 

            var mysearchcontrols = new SearchControlsView({

                id: "searchcontrols1",

                managerid: "search1",

                el: $("#mysearchcontrols1")

            }).render();

 

            var mytable = new TableView({

                id: "table1",

                managerid: "search1",

                el: $("#mytable1")

            }).render();

        });

    &lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;