/// <summary>
        /// Returns the namespace of an <see cref="AtomEntry"/> based on the
        /// eai::acl field.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/>.</param>
        /// <returns>The namespace.</returns>
        private Args SplunkNamespace(AtomEntry entry)
        {
            Args splunkNamespace = new Args();

            // no content? return an empty namespace.
            if (entry.Content == null)
            {
                return(splunkNamespace);
            }

            Dictionary <string, object> entityMetadata =
                (Dictionary <string, object>)entry.Content["eai:acl"];

            if (entityMetadata.ContainsKey("owner"))
            {
                splunkNamespace.Set(
                    "owner", entityMetadata["owner"]);
            }
            if (entityMetadata.ContainsKey("app"))
            {
                splunkNamespace.Set(
                    "app", entityMetadata["app"]);
            }
            if (entityMetadata.ContainsKey("sharing"))
            {
                splunkNamespace.Set(
                    "sharing", entityMetadata["sharing"]);
            }
            return(splunkNamespace);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Authenticates the <see cref="Service"/> instance with a username
        /// and password.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>The service instance.</returns>
        public Service Login(string username, string password)
        {
            this.Username = username;
            this.Password = password;

            Args args = new Args();

            args.Set("username", username);
            args.Set("password", password);

            ResponseMessage response     = Post("/services/auth/login", args);
            StreamReader    streamReader = new StreamReader(response.Content);
            XmlDocument     doc          = new XmlDocument();

            doc.LoadXml(streamReader.ReadToEnd());
            string sessionKey = doc
                                .SelectSingleNode("/response/sessionKey")
                                .InnerText;

            this.Token = "Splunk " + sessionKey;

            this.Version = this.GetInfo().Version;
            if (!this.Version.Contains("."))
            {
                // internal build
                this.Version = "6.0";
            }
            if (this.VersionCompare("4.3") >= 0)
            {
                this.PasswordEndPoint = "storage/passwords";
            }

            return(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a simplified synchronous search using search arguments.
        /// </summary>
        /// <param name="query">The search string.</param>
        /// <param name="inputArgs">The variable arguments.</param>
        /// <param name="outputArgs">The output arguments.</param>
        /// <returns>The stream handle of the search.</returns>
        /// <remarks>
        /// Use this method for simple searches.
        /// </remarks>
        public Stream Search(string query, Args inputArgs, Args outputArgs)
        {
            inputArgs = Args.Create(inputArgs);
            inputArgs.Set("search", query);
            // always block until results are ready.
            inputArgs.Set("exec_mode", "blocking");
            Job job = this.GetJobs().Create(query, inputArgs);

            return(job.Results(outputArgs));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Resource"/> class,
        /// adding optional arguments for namespace and other endpoint
        /// arguments.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="path">The path of this resource.</param>
        /// <param name="args">The variable arguments.</param>
        public Resource(Service service, string path, Args args)
        {
            this.Service = service;

            /* Pull out namespace items (app, owner, sharing) from the args, and
             * then use to create the full path.
             */
            Args clonedArgs      = new Args(args);
            Args splunkNamespace = new Args();

            if (args.ContainsKey("app"))
            {
                splunkNamespace.Set("app", args["app"].ToString());
                clonedArgs.Remove("app");
            }
            if (args.ContainsKey("owner"))
            {
                splunkNamespace.Set("owner", args["owner"].ToString());
                clonedArgs.Remove("owner");
            }
            if (args.ContainsKey("sharing"))
            {
                splunkNamespace.Set(
                    "sharing", args["sharing"].ToString());
                clonedArgs.Remove("sharing");
            }
            if (!clonedArgs.ContainsKey("count"))
            {
                clonedArgs.Set("count", "-1");
            }

            this.RefreshArgs = clonedArgs;
            this.Path        = service.Fullpath(
                path, splunkNamespace.Count == 0 ? null : splunkNamespace);
            this.MaybeValid = false;
        }