Exemple #1
0
        Post(string path, Dictionary <string, object> args)
        {
            RequestMessage request = new RequestMessage("POST");

            if (Count(args) > 0)
            {
                request.Content = Args.Encode(args);
            }
            return(this.Send(path, request));
        }
Exemple #2
0
        Delete(string path, Dictionary <string, object> args)
        {
            if (Count(args) > 0)
            {
                path = path + "?" + Args.Encode(args);
            }
            RequestMessage request = new RequestMessage("DELETE");

            return(this.Send(path, request));
        }
Exemple #3
0
        /// <summary>
        /// Issues an HTTP GET request against the service using a given path
        /// and arguments.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The ResponseMessage.</returns>
        public ResponseMessage Get(string path, Dictionary <string, object> args)
        {
            if (Count(args) > 0)
            {
                path = path + "?" + Args.Encode(args);
            }
            RequestMessage request = new RequestMessage("GET");

            return(this.Send(path, request));
        }
Exemple #4
0
        /// <summary>
        /// Creates a socket to the Splunk server using the named index and
        /// variable arguments.
        /// </summary>
        /// <param name="indexName">The index name.</param>
        /// <param name="args">The variable arguments.</param>
        /// <returns>The socket.</returns>
        public Stream Attach(string indexName, Args args)
        {
            Stream stream;

            if (this.service.Scheme == HttpService.SchemeHttps)
            {
                TcpClient tcp = new TcpClient();
                tcp.Connect(this.service.Host, this.service.Port);
                var sslStream = new SslStreamWrapper(tcp);
                sslStream.AuthenticateAsClient(this.service.Host);
                stream = sslStream;
            }
            else
            {
                Socket socket = this.service.Open(this.service.Port);
                stream = new NetworkStream(socket, true);
            }

            string postUrl = "POST /services/receivers/stream";

            if (indexName != null)
            {
                postUrl = postUrl + "?index=" + indexName;
            }

            if (args != null && args.Count > 0)
            {
                postUrl = postUrl + ((indexName == null) ? "?" : "&");
                postUrl = postUrl + args.Encode();
            }

            string header = string.Format(
                "{0} HTTP/1.1\r\n" +
                "Host: {1}:{2}\r\n" +
                "Accept-Encoding: identity\r\n" +
                "Authorization: {3}\r\n" +
                "X-Splunk-Input-Mode: Streaming\r\n\r\n",
                postUrl,
                this.service.Host,
                this.service.Port,
                this.service.Token);

            var bytes = Encoding.UTF8.GetBytes(header);

            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();

            return(stream);
        }
Exemple #5
0
        /// <summary>
        /// Submits the data to the named index using variable arguments.
        /// </summary>
        /// <param name="indexName">The named index.</param>
        /// <param name="args">The variable arguments.</param>
        /// <param name="data">The data.</param>
        public void Submit(string indexName, Args args, string data)
        {
            string         sendString = string.Empty;
            RequestMessage request    = new RequestMessage("POST");

            request.Content = data;
            if (indexName != null)
            {
                sendString = string.Format("?index={0}", indexName);
            }

            if (args != null && args.Count > 0)
            {
                sendString = sendString + ((indexName == null) ? "?" : "&");
                sendString = sendString + args.Encode();
            }
            this.service.Send(
                this.service.SimpleReceiverEndPoint + sendString, request);
        }