Ejemplo n.º 1
0
        /// <summary>
        /// The main program
        /// </summary>
        /// <param name="argv">The command line arguments</param>
        static async Task Run(Service service)
        {
            Console.WriteLine("Login as " + SdkHelper.Splunk.Username);

            await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password);

            Console.WriteLine("Create an index");

            string indexName = "user-index";
            Index  index     = await service.Indexes.GetOrNullAsync(indexName);

            if (index != null)
            {
                await index.RemoveAsync();
            }

            index = await service.Indexes.CreateAsync(indexName);

            Exception exception = null;

            try
            {
                await index.EnableAsync();

                ITransmitter transmitter = service.Transmitter;
                SearchResult result;

                result = await transmitter.SendAsync("Hello World.", indexName);

                result = await transmitter.SendAsync("Goodbye world.", indexName);

                using (var results = await service.SearchOneShotAsync(string.Format("search index={0}", indexName)))
                {
                    foreach (SearchResult task in results)
                    {
                        Console.WriteLine(task);
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }

            await index.RemoveAsync();

            if (exception != null)
            {
                throw exception;
            }
        }
Ejemplo n.º 2
0
 protected void Forward(TRecipient recipient, TOutput obj)
 {
     if (recipient == null)
     {
         throw new ArgumentNullException(nameof(recipient));
     }
     _child.SendAsync(recipient, obj);
 }
Ejemplo n.º 3
0
        private async Task Run(Service service, string jsonObject, string indexName)
        {
            try
            {
                await service.LogOnAsync(_settings.Username, _settings.Password);

                Index index = await service.Indexes.GetOrNullAsync(indexName) ??
                              await service.Indexes.CreateAsync(indexName);

                await index.EnableAsync();

                ITransmitter transmitter = service.Transmitter;

                await transmitter.SendAsync(jsonObject, indexName);
            }
            catch (Exception exception)
            {
                Console.Write(exception.Message);
            }
        }
        public async Task Transmitter1()
        {
            string indexName = string.Format("delete-me-{0}", Guid.NewGuid());

            using (var service = await SdkHelper.CreateService())
            {
                Index index = await service.Indexes.RecreateAsync(indexName);

                Assert.False(index.Disabled);

                await Task.Delay(2000);

                // Submit event using TransmitterArgs

                const string Source     = "splunk-sdk-tests";
                const string SourceType = "splunk-sdk-test-event";
                const string Host       = "test-host";

                var transmitterArgs = new TransmitterArgs
                {
                    Host       = Host,
                    Source     = Source,
                    SourceType = SourceType,
                };

                ITransmitter transmitter = service.Transmitter;
                SearchResult result;

                //// TODO: Check contentss
                result = await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("1, {0}, {1}, simple event", DateTime.Now, indexName)),
                    indexName, transmitterArgs);

                Assert.NotNull(result);

                result = await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("2, {0}, {1}, simple event", DateTime.Now, indexName)),
                    indexName, transmitterArgs);

                Assert.NotNull(result);

                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 4096, leaveOpen: true))
                    {
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("1, {0}, {1}, stream event", DateTime.Now, indexName)));
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("2, {0}, {1}, stream event", DateTime.Now, indexName)));
                    }

                    stream.Seek(0, SeekOrigin.Begin);

                    await transmitter.SendAsync(stream, indexName, transmitterArgs);
                }

                await index.PollForUpdatedEventCount(4);

                var search = string.Format(
                    "search index={0} host={1} source={2} sourcetype={3}",
                    indexName,
                    Host,
                    Source,
                    SourceType);

                using (SearchResultStream stream = await service.SearchOneShotAsync(search))
                {
                    Assert.Equal(0, stream.FieldNames.Count);
                    Assert.False(stream.IsFinal);
                    Assert.Equal(0, stream.ReadCount);

                    foreach (SearchResult record in stream)
                    {
                        var fieldNames = stream.FieldNames;

                        Assert.Equal(14, fieldNames.Count);
                        Assert.Equal(14, record.FieldNames.Count);
                        Assert.Equal(fieldNames.AsEnumerable(), record.FieldNames.AsEnumerable());

                        var memberNames  = record.GetDynamicMemberNames();
                        var intersection = fieldNames.Intersect(memberNames);

                        Assert.Equal(memberNames, intersection);
                    }

                    Assert.Equal(14, stream.FieldNames.Count);
                    Assert.Equal(4, stream.ReadCount);
                }
            }
        }