/// <summary>
        /// The main program
        /// </summary>
        /// <param name="argv">The command line arguments</param>
        static async Task Run(Service service)
        {
            Console.WriteLine("Login as admin");
            string username = "******";
            string password = "******";
            await service.LoginAsync(username, password);

            Console.WriteLine("create a  index");
            string indexName  = "user-index";
            string source     = "*\\splunkd.log";
            string sourceType = "splunkd";

            if (service.GetIndexesAsync().Result.Any(a => a.Name == indexName))
            {
                await service.RemoveIndexAsync(indexName);
            }

            Index index = await service.CreateIndexAsync(indexName);

            try
            {
                await index.EnableAsync();

                Receiver     receiver = service.Receiver;
                ReceiverArgs args     = new ReceiverArgs()
                {
                    Index      = indexName,
                    Source     = source,
                    SourceType = sourceType,
                };

                await receiver.SendAsync("Hello World.", args);

                await receiver.SendAsync("Goodbye world.", args);

                SearchResults results = service.SearchOneshotAsync(
                    string.Format(
                        "search index={0}",// source={2} sourcetype={3}",
                        indexName
                        //source,
                        //sourceType
                        )).Result;

                Console.WriteLine(results);
            }
            finally
            {
                service.RemoveIndexAsync(indexName).Wait();
            }
        }
예제 #2
0
        public async Task DefaultIndexArgs()
        {
            string         indexName = "main";
            DateTimeOffset offset    = new DateTimeOffset(DateTime.Now);
            string         now       = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                                       string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                                                     offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            //Receiver receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            Index    index    = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);
            ReceiverArgs    receiverArgs    = new ReceiverArgs()
            {
                Index = index.Name,
            };
            // submit event to default index using variable arguments
            //receiver.Log(indexAttributes, "Hello World. \u0150");
            //receiver.Log(indexAttributes, "Goodbye World. \u0150");
            await receiver.SendAsync("Hello World", receiverArgs);

            await receiver.SendAsync("Hello World 2", receiverArgs);

            // stream event to default index with variable arguments
            //Stream streamArgs = receiver.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();

            UnicodeEncoding uniEncoding = new UnicodeEncoding();

            byte[]       inputString = uniEncoding.GetBytes("stream hello world ");
            MemoryStream stream      = new MemoryStream();

            stream.Write(inputString, 0, inputString.Length);
            await receiver.SendAsync(stream, receiverArgs);

            stream.Close();
        }
예제 #3
0
        /// <summary>
        /// The main program
        /// </summary>
        /// <param name="argv">The command line arguments</param>
        static async Task Run(Service service)
        {
            Console.WriteLine("Login as admin");
            string username = "******";
            string password = "******";
            await service.LoginAsync(username, password);

            Console.WriteLine("create a  index");
            string indexName = "user-index";
            string source = "*\\splunkd.log";
            string sourceType = "splunkd";

            if (service.GetIndexesAsync().Result.Any(a => a.Name == indexName))
            {
                await service.RemoveIndexAsync(indexName);
            }

            Index index = await service.CreateIndexAsync(indexName);
            try
            {
                await index.EnableAsync();

                Receiver receiver = service.Receiver;
                ReceiverArgs args = new ReceiverArgs()
                {
                    Index = indexName,
                    Source = source,
                    SourceType = sourceType,
                };

                await receiver.SendAsync("Hello World.", args);
                await receiver.SendAsync("Goodbye world.", args);

                SearchResults results = service.SearchOneshotAsync(
                    string.Format(
                        "search index={0}",// source={2} sourcetype={3}",
                        indexName
                        //source,
                        //sourceType
                        )).Result;

                Console.WriteLine(results);              
            }
            finally
            {
                service.RemoveIndexAsync(indexName).Wait();
            }
        }
예제 #4
0
        public async Task IndexArgs()
        {
            string         indexName = "sdk-tests2";
            DateTimeOffset offset    = new DateTimeOffset(DateTime.Now);
            string         now       = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                                       string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                                                     offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            Index   index   = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);

            //ClearIndex(service, indexName, index);

            // submit event to index using variable arguments
            //index.Submit(indexAttributes, now + " Hello World. \u0150");
            //index.Submit(indexAttributes, now + " Goodbye World. \u0150");
            //WaitUntilEventCount(index, 2, 45);

            await ClearIndex(service, indexName, index);

            // stream event to index with variable arguments
            //Stream streamArgs = index.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();
            //WaitUntilEventCount(index, 2, 45);

            // submit event using ReceiverSubmitArgs
            const string Source     = "splunk-sdk-tests";
            const string SourceType = "splunk-sdk-test-event";
            const string Host       = "test-host";
            var          args       = new ReceiverArgs
            {
                Index      = indexName,
                Host       = Host,
                Source     = Source,
                SourceType = SourceType,
            };

            //var receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            //receiver.Submit(args, "Hello World.");
            //receiver.Submit(args, "Goodbye world.");
            await receiver.SendAsync("Hello World.", args);

            await receiver.SendAsync("Goodbye world.", args);

            //WaitUntilEventCount(index, 4, 45);
            // verify the fields of events in the index matching the args.
            //using (var stream =
            //    service.Oneshot(
            //        string.Format(
            //            "search index={0} host={1} source={2} sourcetype={3}",
            //            indexName,
            //            Host,
            //            Source,
            //            SourceType)))

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

            //using (var reader = new ResultsReaderXml(stream))
            //{
            //    Assert.Equal(2, reader.Count());
            //}
            Assert.Equal(2, result.FieldNames.Count);
            await index.GetAsync();

            Assert.Equal(2, index.TotalEventCount);

            await ClearIndex(service, indexName, index);

            //index.Clean(180);
            //Assert.Equal(0, index.TotalEventCount, "Expected the total event count to be 0");
        }
예제 #5
0
        public async Task DefaultIndexArgs()
        {
            string indexName = "main";
            DateTimeOffset offset = new DateTimeOffset(DateTime.Now);
            string now = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                         string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                             offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            //Receiver receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            Index index = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);
            ReceiverArgs receiverArgs = new ReceiverArgs() { Index = index.Name, };
            // submit event to default index using variable arguments
            //receiver.Log(indexAttributes, "Hello World. \u0150");
            //receiver.Log(indexAttributes, "Goodbye World. \u0150");
            await receiver.SendAsync("Hello World", receiverArgs);
            await receiver.SendAsync("Hello World 2", receiverArgs);

            // stream event to default index with variable arguments
            //Stream streamArgs = receiver.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(" Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();

            UnicodeEncoding uniEncoding = new UnicodeEncoding();
            byte[] inputString = uniEncoding.GetBytes("stream hello world ");
            MemoryStream stream = new MemoryStream();
            stream.Write(inputString, 0, inputString.Length);
            await receiver.SendAsync(stream, receiverArgs);
            stream.Close();
        }
예제 #6
0
        public async Task IndexArgs()
        {
            string indexName = "sdk-tests2";
            DateTimeOffset offset = new DateTimeOffset(DateTime.Now);
            string now = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                         string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"),
                             offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            Index index = await service.GetIndexAsync(indexName);

            //index.Enable();
            Assert.False(index.Disabled);

            IndexAttributes indexAttributes = GetIndexAttributes(index);

            //ClearIndex(service, indexName, index);

            // submit event to index using variable arguments
            //index.Submit(indexAttributes, now + " Hello World. \u0150");
            //index.Submit(indexAttributes, now + " Goodbye World. \u0150");
            //WaitUntilEventCount(index, 2, 45);

            await ClearIndex(service, indexName, index);

            // stream event to index with variable arguments
            //Stream streamArgs = index.Attach(indexAttributes);
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Hello World again. \u0150\r\n"));
            //streamArgs.Write(Encoding.UTF8.GetBytes(now + " Goodbye World again.\u0150\r\n"));
            //streamArgs.Close();
            //WaitUntilEventCount(index, 2, 45);

            // submit event using ReceiverSubmitArgs
            const string Source = "splunk-sdk-tests";
            const string SourceType = "splunk-sdk-test-event";
            const string Host = "test-host";
            var args = new ReceiverArgs
            {
                Index = indexName,
                Host = Host,
                Source = Source,
                SourceType = SourceType,
            };

            //var receiver = service.GetReceiver();
            Receiver receiver = new Receiver();
            //receiver.Submit(args, "Hello World.");
            //receiver.Submit(args, "Goodbye world.");
            await receiver.SendAsync("Hello World.", args);
            await receiver.SendAsync("Goodbye world.", args);
            //WaitUntilEventCount(index, 4, 45);
            // verify the fields of events in the index matching the args.
            //using (var stream =
            //    service.Oneshot(
            //        string.Format(
            //            "search index={0} host={1} source={2} sourcetype={3}",
            //            indexName,
            //            Host,
            //            Source,
            //            SourceType)))

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

            //using (var reader = new ResultsReaderXml(stream))
            //{
            //    Assert.Equal(2, reader.Count());
            //}
            Assert.Equal(2, result.FieldNames.Count);
            await index.GetAsync();
            Assert.Equal(2, index.TotalEventCount);

            await ClearIndex(service, indexName, index);
            //index.Clean(180);
            //Assert.Equal(0, index.TotalEventCount, "Expected the total event count to be 0");
        }