public async Task <IHttpActionResult> SendDataToSplunk()
        {
            string message    = "some message";
            var    middleware = new HttpEventCollectorResendMiddleware(100);

            // preparing parameters
            Uri    uri   = new Uri("http://localhost:8088");
            string token = "73f4c508-35da-4d14-9d4b-12a8d820935f";

            try
            {
                var ecSender = new HttpEventCollectorSender(uri, token, null, HttpEventCollectorSender.SendMode.Sequential, 0, 0, 0, middleware.Plugin);

                ecSender.OnError += EcSender_OnError;

                ecSender.Send(Guid.NewGuid().ToString(), "INFO", null, new { Foo = message });
                var flushTask = ecSender.FlushAsync();
                flushTask.Start();
                await flushTask;

                return(Ok("data saved to splunk"));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
        public override bool Flush(int millisecondsTimeout)
        {
            var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(millisecondsTimeout));

            Task.Run(async() => await _hecSender.FlushAsync(), cancellationTokenSource.Token).Wait();
            return(true);
        }
        static async void DoIt()
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
            {
                return(true);
            };

            var middleware = new HttpEventCollectorResendMiddleware(100);
            var ecSender   = new HttpEventCollectorSender(new Uri("https://localhost:8088"), "92A93306-354C-46A5-9790-055C688EB0C4", null, HttpEventCollectorSender.SendMode.Sequential, 5000, 0, 0, middleware.Plugin);

            ecSender.OnError += o => Console.WriteLine(o.Message);
            ecSender.Send(DateTime.UtcNow.AddDays(-1), Guid.NewGuid().ToString(), "INFO", null,
                          new { Foo = "Bar", test2 = "Testit2", time = ConvertToEpoch(DateTime.UtcNow.AddHours(-2)).ToString(), anotherkey = "anothervalue" });
            ecSender.Send(Guid.NewGuid().ToString(), "INFO", null,
                          new { Foo = "Bar", test2 = "Testit2", time = ConvertToEpoch(DateTime.UtcNow.AddHours(-2)).ToString(), anotherkey = "anothervalue!!" });
            await ecSender.FlushAsync();
        }
Ejemplo n.º 4
0
        public static async Task LogDataToSplunk(string severity, string message, object data)
        {
            try
            {
                var middleware = new HttpEventCollectorResendMiddleware(100);
                var esSender   = new HttpEventCollectorSender(new Uri("http://localhost:8088"), "73f4c508-35da-4d14-9d4b-12a8d820935f",
                                                              null, HttpEventCollectorSender.SendMode.Sequential, 0, 0, 0, middleware.Plugin);
                esSender.OnError += EsSender_OnError;
                esSender.Send(Guid.NewGuid().ToString(), severity, message, data);

                var flushTask = esSender.FlushAsync();
                flushTask.Start();
                await flushTask;
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 5
0
        // Send Json objects directly to HTTP Event Collector
        private async Task <string> M3()
        {
            try
            {
                var middleware = new HttpEventCollectorResendMiddleware(100);
                var esSender   = new HttpEventCollectorSender(new Uri("http://localhost:8088"), "73f4c508-35da-4d14-9d4b-12a8d820935f",
                                                              null, HttpEventCollectorSender.SendMode.Sequential, 0, 0, 0, middleware.Plugin);
                esSender.OnError += EsSender_OnError;
                esSender.Send(Guid.NewGuid().ToString(), "INFO", "My Message", new Person()
                {
                    FirstName = "Raj 1", LastName = "Konduri"
                });

                var flushTask = esSender.FlushAsync();
                flushTask.Start();
                await flushTask;
                return("Success");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }