Пример #1
0
        private static void GenerateDataWaitForIndexingCompletion(SplunkCliWrapper splunk, string indexName, double testStartTime, TraceSource trace)
        {
            // Generate data
            int    eventCounter = GenerateData(trace);
            string searchQuery  = "index=" + indexName;

            Console.WriteLine("{0} events were created, waiting for indexing to complete.", eventCounter);
            splunk.WaitForIndexingToComplete(indexName);
            int eventsFound = splunk.GetSearchCount(searchQuery);

            Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
            // Verify all events were indexed correctly
            Assert.Equal(eventCounter, eventsFound);
            List <string> searchResults = splunk.GetSearchResults(searchQuery);

            Assert.Equal(searchResults.Count, eventsFound);
            for (int eventId = 0; eventId < eventCounter; eventId++)
            {
                string expected = string.Format("This is event {0}", eventId);
                Assert.NotNull(searchResults.FirstOrDefault(s => s.Contains(expected)));
            }
            // Verify metadata
            List <string> metaData = splunk.GetMetadataResults(searchQuery);

            Assert.Equal(metaData[0], "customhostname");
            Assert.Equal(metaData[1], "log");
            Assert.Equal(metaData[2], "host");
        }
Пример #2
0
        static void VerifyEventsAreInOrder()
        {
            string           tokenName     = "verifyeventsareinordertoken";
            string           indexName     = "verifyeventsareinorderindex";
            SplunkCliWrapper splunk        = new SplunkCliWrapper();
            double           testStartTime = SplunkCliWrapper.GetEpochTime();
            string           token         = CreateIndexAndToken(splunk, tokenName, indexName);

            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,
                metadata: meta);

            trace.Listeners.Add(listener);

            // Generate data
            int totalEvents = 1000;

            string[] filer = new string[2];
            filer[0] = new string('s', 1);
            filer[1] = new string('l', 100000);
            for (int i = 0; i < totalEvents; i++)
            {
                trace.TraceInformation(string.Format("TraceInformation. This is event {0}. {1}", i, filer[i % 2]));
            }

            string searchQuery = "index=" + indexName;

            Console.WriteLine("{0} events were created, waiting for indexing to complete.", totalEvents);
            splunk.WaitForIndexingToComplete(indexName);
            int eventsFound = splunk.GetSearchCount(searchQuery);

            Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
            // Verify all events were indexed correctly and in order
            Assert.Equal(totalEvents, eventsFound);
            List <string> searchResults = splunk.GetSearchResults(searchQuery);

            Assert.Equal(searchResults.Count, eventsFound);
            for (int i = 0; i < totalEvents; i++)
            {
                int    id       = totalEvents - i - 1;
                string expected = string.Format("TraceInformation. This is event {0}", id);
                Assert.True(searchResults[i].Contains(expected));
            }
            trace.Close();
        }
        static void VerifyEventsAreInOrder()
        {
            string tokenName = "verifyeventsareinordertoken";
            string indexName = "verifyeventsareinorderindex";
            SplunkCliWrapper splunk = new SplunkCliWrapper();
            double testStartTime = SplunkCliWrapper.GetEpochTime();
            string token = CreateIndexAndToken(splunk, tokenName, indexName);

            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,
                metadata: meta);
            trace.Listeners.Add(listener);

            // Generate data
            int totalEvents = 1000;
            string[] filer = new string[2];
            filer[0] = new string('s', 1);
            filer[1] = new string('l', 100000);
            for (int i = 0; i < totalEvents; i++)
            {
                trace.TraceInformation(string.Format("TraceInformation. This is event {0}. {1}", i, filer[i%2]));
            }

            string searchQuery = "index=" + indexName;
            Console.WriteLine("{0} events were created, waiting for indexing to complete.", totalEvents);
            splunk.WaitForIndexingToComplete(indexName);
            int eventsFound = splunk.GetSearchCount(searchQuery);
            Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
            // Verify all events were indexed correctly and in order
            Assert.Equal(totalEvents, eventsFound);
            List<string> searchResults = splunk.GetSearchResults(searchQuery);
            Assert.Equal(searchResults.Count, eventsFound);
            for (int i = 0; i< totalEvents; i++)
            {
                int id = totalEvents - i - 1;
                string expected = string.Format("TraceInformation. This is event {0}. {1}", id, filer[id % 2]);
                Assert.True(searchResults[i].Contains(expected));
            }
            trace.Close();
        }
 private static void GenerateDataWaitForIndexingCompletion(SplunkCliWrapper splunk, string indexName, double testStartTime, TraceSource trace)
 {
     // Generate data
     int eventCounter = GenerateData(trace);
     string searchQuery = "index=" + indexName;
     Console.WriteLine("{0} events were created, waiting for indexing to complete.", eventCounter);
     splunk.WaitForIndexingToComplete(indexName);
     int eventsFound = splunk.GetSearchCount(searchQuery);
     Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
     // Verify all events were indexed correctly
     Assert.Equal(eventCounter, eventsFound);
     List<string> searchResults = splunk.GetSearchResults(searchQuery);
     Assert.Equal(searchResults.Count, eventsFound);
     for (int eventId = 0; eventId < eventCounter; eventId++)
     {
         string expected = string.Format("This is event {0}", eventId);
         Assert.NotNull(searchResults.FirstOrDefault(s => s.Contains(expected)));
     }
     // Verify metadata
     List<string> metaData = splunk.GetMetadataResults(searchQuery);
     Assert.Equal(metaData[0], "customhostname");
     Assert.Equal(metaData[1], "log");
     Assert.Equal(metaData[2], "host");
 }