public static void Main(string[] args)
        {
            string serverCertificateName = null;
            string serverName            = null;

            if (args == null || args.Length < 1)
            {
                serverName = Environment.MachineName;
            }
            else
            {
                serverName = args[0];
            }

            // User can specify the machine name and server name.
            // Server name must match the name on the server's certificate.
            if (args.Length < 2)
            {
                serverCertificateName = serverName;
            }
            else
            {
                serverCertificateName = args[1];
            }

            // Create a TCP/IP client socket.
            // machineName is the host running the server application.
            TcpClient client = new TcpClient(serverName, 8080);

            Console.WriteLine("Client connected.");
            var sslOverStream = new SslOverTdsStream(client.GetStream());
            // Create an SSL stream that will close the client's stream.
            SslStream sslStream = new SslStreamWrapper(
                sslOverStream, //client.GetStream(),
                false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null
                );

            // The server name must match the name on the server certificate.
            try
            {
                sslStream.AuthenticateAsClient(serverName);
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
                }
                Console.WriteLine("Authentication failed - closing the connection.");
                client.Close();
                return;
            }

            Stream stream = sslStream;

            RunTest(stream);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
        }