コード例 #1
0
        public static int Main()
        {
            ElasticsearchVersion v = null;


//			var clusterConfiguration = new EphemeralClusterConfiguration("6.0.0", numberOfNodes: 2);
//			var ephemeralCluster = new EphemeralCluster(clusterConfiguration);
//			var nodeConfiguration = new NodeConfiguration(clusterConfiguration, 9200);
//			var elasticsearchNode = new ElasticsearchNode(nodeConfiguration);
////

//			using (var node = new ElasticsearchNode("5.5.1"))
//			{
//				node.Subscribe(new ConsoleOutColorWriter());
//				node.WaitForStarted(TimeSpan.FromMinutes(2));
//			}
//
//			using (var node = new ElasticsearchNode("6.0.0-beta2", @"c:\Data\elasticsearch-6.0.0-beta2"))
//			{
//				node.Subscribe();
//				node.WaitForStarted(TimeSpan.FromMinutes(2));
//				Console.ReadKey();
//			}

//			using (var cluster = new EphemeralCluster("6.0.0"))
//			{
//				cluster.Start();
//			}

            var config = new EphemeralClusterConfiguration("6.2.3", XPack | Security | SSL, null, 1)
            {
                PrintYamlFilesInConfigFolder        = true,
                ShowElasticsearchOutputAfterStarted = true
            };

            using (var cluster = new EphemeralCluster(config))
            {
                cluster.Start();

                var nodes          = cluster.NodesUris();
                var connectionPool = new StaticConnectionPool(nodes);
                var settings       = new ConnectionSettings(connectionPool).EnableDebugMode();
                if (config.EnableSecurity && !config.EnableSsl)
                {
                    settings = settings.BasicAuthentication(ClusterAuthentication.Admin.Username, ClusterAuthentication.Admin.Password);
                }
                if (config.EnableSsl)
                {
                    settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll);
                    settings = settings.ClientCertificate(new X509Certificate2(config.FileSystem.ClientCertificate));
                }

                var client = new ElasticClient(settings);

                Console.Write(client.XPackInfo().DebugInformation);
            }
//
//			Console.WriteLine($".. DONE ...");
            return(0);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var clusterConfiguration = new EphemeralClusterConfiguration("7.9.0");

            using var cluster = new EphemeralCluster(clusterConfiguration);

            cluster.Start(TimeSpan.FromMinutes(2));
            var uri = cluster.NodesUris().First();


            var nestIndex = "logs-from-nest";

            Announce("NEST + Elastic.CommonSchema", nestIndex);
            var settings = new ConnectionSettings(uri).EnableDebugMode();
            var client   = new ElasticClient(settings);


            var bulkAll = client.BulkAll(GetEcsEvents(10_000), b => b
                                         .Index(nestIndex)
                                         .Size(1_000)
                                         .RefreshOnCompleted()
                                         .BufferToBulk((bulk, items) => bulk.CreateMany(items))
                                         );

            bulkAll.Wait(TimeSpan.FromMinutes(2), r => Console.WriteLine("Indexed 1000 events"));

            Check(client, nestIndex);


            // Using Serilog ElasticsearchSink
            var sinkIndex = "logs-from-sink";

            Announce("Elastic.CommonSchema.Serilog", sinkIndex);
            var options = new ElasticsearchSinkOptions(uri)
            {
                CustomFormatter            = new EcsTextFormatter(),
                IndexFormat                = sinkIndex + "-{0:yyyy-MM-dd}",
                DetectElasticsearchVersion = true,
                BatchAction                = ElasticOpType.Create,
                BatchPostingLimit          = 1_000,
            };
            var logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Elasticsearch(options)
                         .CreateLogger();

            Log.Logger = logger;

            foreach (var e in GetEcsEvents(10_000))
            {
                Log.Debug("Reusing {field1} by {another_field}: {message}", "some value", true, e.Message);
            }

            Log.CloseAndFlush();

            Check(client, $"{sinkIndex}-*");
        }
コード例 #3
0
        private static void ManualConfigRun()
        {
            ElasticVersion version = "latest";

            var plugins =
                new ElasticsearchPlugins(ElasticsearchPlugin.IngestGeoIp, ElasticsearchPlugin.IngestAttachment);
            var features = Security | XPack | SSL;
            var config   = new EphemeralClusterConfiguration(version, features, plugins, numberOfNodes: 1)
            {
                HttpFiddlerAware = true,
                ShowElasticsearchOutputAfterStarted = true,
                CacheEsHomeInstallation             = false,
                TrialMode = XPackTrialMode.Trial,
                NoCleanupAfterNodeStopped = false,
            };

            using (var cluster = new EphemeralCluster(config))
            {
                cluster.Start();

                var nodes          = cluster.NodesUris();
                var connectionPool = new StaticConnectionPool(nodes);
                var settings       = new ConnectionSettings(connectionPool).EnableDebugMode();
                if (config.EnableSecurity)
                {
                    settings = settings.BasicAuthentication(ClusterAuthentication.Admin.Username,
                                                            ClusterAuthentication.Admin.Password);
                }
                if (config.EnableSsl)
                {
                    settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll);
                }

                var client = new ElasticClient(settings);

                var clusterConfiguration = new Dictionary <string, object>()
                {
                    { "cluster.routing.use_adaptive_replica_selection", true },
                    { "cluster.remote.remote-cluster.seeds", "127.0.0.1:9300" }
                };


                var putSettingsResponse = client.ClusterPutSettings(new ClusterPutSettingsRequest
                {
                    Transient = clusterConfiguration
                });


                Console.Write(client.XPackInfo().DebugInformation);
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Console.WriteLine("Exitting..");
            }

            Console.WriteLine("Done!");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: wyspianski93/ecs-dotnet
        private static ElasticClient CreateClient(EphemeralCluster cluster)
        {
            var nodes          = cluster.NodesUris();
            var connectionPool = new StaticConnectionPool(nodes);
            var settings       = new ConnectionSettings(connectionPool)
                                 //.Proxy(new Uri("http://localhost:8080"), "", "")
                                 .EnableDebugMode();

            return(new ElasticClient(settings));
        }
コード例 #5
0
        private static void ManualConfigRun()
        {
            ElasticVersion version = "latest-7";

            var plugins =
                new ElasticsearchPlugins(ElasticsearchPlugin.IngestGeoIp, ElasticsearchPlugin.AnalysisKuromoji);
            var features = Security | XPack | SSL;
            var config   = new EphemeralClusterConfiguration(version, features, null, numberOfNodes: 1)
            {
                HttpFiddlerAware = true,
                ShowElasticsearchOutputAfterStarted = true,
                CacheEsHomeInstallation             = true,
                TrialMode = XPackTrialMode.Trial,
                NoCleanupAfterNodeStopped = false,
            };

            using (var cluster = new EphemeralCluster(config))
            {
                cluster.Start();

                var nodes          = cluster.NodesUris();
                var connectionPool = new StaticConnectionPool(nodes);
                var settings       = new ConnectionSettings(connectionPool).EnableDebugMode();
                if (config.EnableSecurity)
                {
                    settings = settings.BasicAuthentication(ClusterAuthentication.Admin.Username,
                                                            ClusterAuthentication.Admin.Password);
                }
                if (config.EnableSsl)
                {
                    settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll);
                }

                var client = new ElasticClient(settings);

                Console.Write(client.XPackInfo().DebugInformation);
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Console.WriteLine("Exitting..");
            }

            Console.WriteLine("Done!");
        }
コード例 #6
0
        public static void Run()
        {
            var plugins  = new ElasticsearchPlugins(ElasticsearchPlugin.IngestGeoIp, ElasticsearchPlugin.AnalysisKuromoji);
            var versions = new string[] { "7.0.0-beta1", "latest", "latest-7", "latest-6", "957e3089:7.2.0", "6.6.1", "5.6.15" };
            var features = new[]
            {
                ClusterFeatures.None,
//				ClusterFeatures.XPack,
//				ClusterFeatures.XPack | ClusterFeatures.Security,
                ClusterFeatures.XPack | ClusterFeatures.SSL | ClusterFeatures.Security
            };

            foreach (var v in versions)
            {
                foreach (var f in features)
                {
                    Console.Clear();
                    var reset = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine($"{v} {f}");

                    Console.ForegroundColor = reset;
                    var config = new EphemeralClusterConfiguration(v, f, plugins, numberOfNodes: 1)
                    {
                        HttpFiddlerAware = true,
                    };

                    using (var cluster = new EphemeralCluster(config))
                    {
                        try
                        {
                            cluster.Start();

                            var nodes          = cluster.NodesUris();
                            var connectionPool = new StaticConnectionPool(nodes);
                            var settings       = new ConnectionSettings(connectionPool).EnableDebugMode();
                            if (config.EnableSecurity)
                            {
                                settings = settings.BasicAuthentication(ClusterAuthentication.Admin.Username, ClusterAuthentication.Admin.Password);
                            }
                            if (config.EnableSsl)
                            {
                                settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll);
                            }

                            var client = new ElasticClient(settings);
                            Console.WriteLine(client.RootNodeInfo().Version.Number);
                            cluster.Dispose();
                            cluster.WaitForExit(TimeSpan.FromMinutes(1));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.WriteLine($"{v} {f}");

                            Console.ForegroundColor = reset;

                            throw;
                        }
                    }
                }
            }
            Console.WriteLine("Done!");
        }