Beispiel #1
0
        public static void StallWrite()
        {
            string           tokenName     = "stallwritetoken";
            string           indexName     = "stallwriteindex";
            SplunkCliWrapper splunk        = new SplunkCliWrapper();
            double           testStartTime = SplunkCliWrapper.GetEpochTime();
            string           token         = CreateIndexAndToken(splunk, tokenName, indexName);

            const string baseUrl  = "https://127.0.0.1:8088";
            string       postData = "{ \"event\": { \"data\": \"test event\" } }";

            List <HttpWebRequest> requests = new List <HttpWebRequest>();
            List <Stream>         streams  = new List <Stream>();

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            for (int i = 0; i < 10; i++)
            {
                var request = WebRequest.Create(baseUrl + "/services/collector") as HttpWebRequest;
                requests.Add(request);
                request.Timeout   = 60 * 1000;
                request.KeepAlive = true;
                request.Method    = "POST";
                request.Headers.Add("Authorization", "Splunk " + token);
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length * 2;
                try
                {
                    Stream dataStream = request.GetRequestStream();
                    streams.Add(dataStream);
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }
                catch (WebException webErr)
                {
                    //restart splunk
                    Console.WriteLine("restart splunk due to " + webErr);
                    splunk.StopServer();
                    splunk.StartServer();
                }
            }
        }
Beispiel #2
0
        public void VerifyFlushEvents()
        {
            string           tokenName     = "flusheventtoken";
            string           indexName     = "flusheventdindex";
            SplunkCliWrapper splunk        = new SplunkCliWrapper();
            double           testStartTime = SplunkCliWrapper.GetEpochTime();

            string token = CreateIndexAndToken(splunk, tokenName, indexName);

            splunk.StopServer();
            Thread.Sleep(5 * 1000);

            var trace = new TraceSource("HttpEventCollectorLogger");

            trace.Switch.Level = SourceLevels.All;
            var meta     = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
            var listener = new HttpEventCollectorTraceListener(
                uri: new Uri("https://127.0.0.1:8088"),
                token: token,
                retriesOnError: int.MaxValue,
                metadata: meta);

            trace.Listeners.Add(listener);

            // Generate data, wait a little bit so retries are happenning and start Splunk. Expecting to see all data make it
            const int eventsToGeneratePerLoop = 250;
            const int expectedCount           = eventsToGeneratePerLoop * 7;
            int       eventCounter            = GenerateData(trace, eventsPerLoop: eventsToGeneratePerLoop);

            splunk.StartServer();
            trace.Close();

            // Verify every event made to Splunk
            splunk.WaitForIndexingToComplete(indexName, stabilityPeriod: 30);
            int eventsFound = splunk.GetSearchCount("index=" + indexName);

            Assert.Equal(expectedCount, eventsFound);
        }
        public void VerifyFlushEvents()
        {
            string tokenName = "flusheventtoken";
            string indexName = "flusheventdindex";
            SplunkCliWrapper splunk = new SplunkCliWrapper();
            double testStartTime = SplunkCliWrapper.GetEpochTime();

            string token = CreateIndexAndToken(splunk, tokenName, indexName);
            splunk.StopServer();
            Thread.Sleep(5 * 1000);

            var trace = new TraceSource("HttpEventCollectorLogger");
            trace.Switch.Level = SourceLevels.All;
            var meta = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
            var listener = new HttpEventCollectorTraceListener(
                uri: new Uri("https://127.0.0.1:8088"),
                token: token,
                retriesOnError: int.MaxValue,
                metadata: meta);
            trace.Listeners.Add(listener);

            // Generate data, wait a little bit so retries are happenning and start Splunk. Expecting to see all data make it
            const int eventsToGeneratePerLoop = 250;
            const int expectedCount = eventsToGeneratePerLoop * 7;
            int eventCounter = GenerateData(trace, eventsPerLoop: eventsToGeneratePerLoop);
            splunk.StartServer();
            trace.Close();

            // Verify every event made to Splunk
            splunk.WaitForIndexingToComplete(indexName, stabilityPeriod: 30);
            int eventsFound = splunk.GetSearchCount("index=" + indexName);
            Assert.Equal(expectedCount, eventsFound);
        }