Exemple #1
0
        private string GetIndexName(ElasticSearchConnectionData connectionData)
        {
            var now    = DateTimeOffset.UtcNow;
            var retval = connectionData.IndexNamePrefix + now.Year + Dot + now.Month + Dot + now.Day;

            return(retval);
        }
        private string GetIndexName(ElasticSearchConnectionData connectionData)
        {
            DateTimeOffset now    = DateTimeOffset.UtcNow;
            string         retval = connectionData.IndexNamePrefix + now.Year.ToString() + Dot + now.Month.ToString() + Dot + now.Day.ToString();

            return(retval);
        }
        private string GetIndexName(ElasticSearchConnectionData connectionData)
        {
            DateTimeOffset now    = DateTimeOffset.UtcNow;
            string         retval = connectionData.Configuration.IndexNamePrefix + now.ToString("yyyy" + Dot + "MM" + Dot + "dd");

            return(retval);
        }
        private void Initialize(ElasticSearchOutputConfiguration esOutputConfiguration)
        {
            Debug.Assert(esOutputConfiguration != null);
            Debug.Assert(this.healthReporter != null);

            this.connectionData = new ElasticSearchConnectionData
            {
                Configuration = esOutputConfiguration
            };

            string userName = esOutputConfiguration.BasicAuthenticationUserName;
            string password = esOutputConfiguration.BasicAuthenticationUserPassword;
            bool   credentialsIncomplete = string.IsNullOrWhiteSpace(userName) ^ string.IsNullOrWhiteSpace(password);

            if (credentialsIncomplete)
            {
                var errorMessage = $"{nameof(ElasticSearchOutput)}: for basic authentication to work both user name and password must be specified";
                healthReporter.ReportWarning(errorMessage, EventFlowContextIdentifiers.Configuration);
                userName = password = null;
            }

            IConnectionPool    pool = esOutputConfiguration.GetConnectionPool(healthReporter);
            ConnectionSettings connectionSettings = new ConnectionSettings(pool);

            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
            {
                connectionSettings = connectionSettings.BasicAuthentication(userName, password);
            }

            this.connectionData.Client        = new ElasticClient(connectionSettings);
            this.connectionData.LastIndexName = null;

            if (string.IsNullOrWhiteSpace(esOutputConfiguration.IndexNamePrefix))
            {
                esOutputConfiguration.IndexNamePrefix = string.Empty;
            }
            else
            {
                string lowerCaseIndexNamePrefix = esOutputConfiguration.IndexNamePrefix.ToLowerInvariant();
                if (lowerCaseIndexNamePrefix != esOutputConfiguration.IndexNamePrefix)
                {
                    healthReporter.ReportWarning($"{nameof(ElasticSearchOutput)}: The chosen index name prefix '{esOutputConfiguration.IndexNamePrefix}' "
                                                 + "contains uppercase characters, which are not allowed by Elasticsearch. The prefix will be converted to lowercase.",
                                                 EventFlowContextIdentifiers.Configuration);
                }
                esOutputConfiguration.IndexNamePrefix = lowerCaseIndexNamePrefix + Dash;
            }

            if (string.IsNullOrWhiteSpace(esOutputConfiguration.EventDocumentTypeName))
            {
                string warning = $"{nameof(ElasticSearchOutput)}: '{nameof(ElasticSearchOutputConfiguration.EventDocumentTypeName)}' configuration parameter "
                                 + "should not be empty";
                healthReporter.ReportWarning(warning, EventFlowContextIdentifiers.Configuration);
                esOutputConfiguration.EventDocumentTypeName = ElasticSearchOutputConfiguration.DefaultEventDocumentTypeName;
            }
        }
        private void CreateConnectionData(object sender)
        {
            IConfigurationProvider configurationProvider = (IConfigurationProvider) sender;

            this.connectionData = new ElasticSearchConnectionData();
            this.connectionData.Client = this.CreateElasticClient(configurationProvider);
            this.connectionData.LastIndexName = null;
            string indexNamePrefix = configurationProvider.GetValue("indexNamePrefix");
            this.connectionData.IndexNamePrefix = string.IsNullOrWhiteSpace(indexNamePrefix) ? string.Empty : indexNamePrefix + Dash;
        }
        private void CreateConnectionData(object sender)
        {
            IConfigurationProvider configurationProvider = (IConfigurationProvider)sender;

            this.connectionData               = new ElasticSearchConnectionData();
            this.connectionData.Client        = this.CreateElasticClient(configurationProvider);
            this.connectionData.LastIndexName = null;
            string indexNamePrefix = configurationProvider.GetValue("indexNamePrefix");

            this.connectionData.IndexNamePrefix = string.IsNullOrWhiteSpace(indexNamePrefix) ? string.Empty : indexNamePrefix + Dash;
        }
        private void Initialize(ElasticSearchOutputConfiguration esOutputConfiguration)
        {
            Debug.Assert(esOutputConfiguration != null);
            Debug.Assert(this.healthReporter != null);

            this.connectionData = new ElasticSearchConnectionData
            {
                Configuration = esOutputConfiguration
            };

            var esServiceUris = esOutputConfiguration.ServiceUri
                                .Split(';')
                                .Where(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
                                .Select(x => new Uri(x))
                                .ToList();

            string errorMessage;

            if (!esServiceUris.Any())
            {
                errorMessage =
                    $"{nameof(ElasticSearchOutput)}:  required 'serviceUri' configuration parameter is invalid";
                this.healthReporter.ReportProblem(errorMessage, EventFlowContextIdentifiers.Configuration);
                throw new Exception(errorMessage);
            }

            string userName = esOutputConfiguration.BasicAuthenticationUserName;
            string password = esOutputConfiguration.BasicAuthenticationUserPassword;
            bool   credentialsIncomplete = string.IsNullOrWhiteSpace(userName) ^ string.IsNullOrWhiteSpace(password);

            if (credentialsIncomplete)
            {
                errorMessage = $"{nameof(ElasticSearchOutput)}: for basic authentication to work both user name and password must be specified";
                healthReporter.ReportWarning(errorMessage, EventFlowContextIdentifiers.Configuration);
                userName = password = null;
            }

            IConnectionPool    pool = esOutputConfiguration.UseSniffingConnectionPooling? new SniffingConnectionPool(esServiceUris) : new StaticConnectionPool(esServiceUris);
            ConnectionSettings connectionSettings = new ConnectionSettings(pool);

            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
            {
                connectionSettings = connectionSettings.BasicAuthentication(userName, password);
            }

            this.connectionData.Client        = new ElasticClient(connectionSettings);
            this.connectionData.LastIndexName = null;

            if (string.IsNullOrWhiteSpace(esOutputConfiguration.IndexNamePrefix))
            {
                esOutputConfiguration.IndexNamePrefix = string.Empty;
            }
            else
            {
                string lowerCaseIndexNamePrefix = esOutputConfiguration.IndexNamePrefix.ToLowerInvariant();
                if (lowerCaseIndexNamePrefix != esOutputConfiguration.IndexNamePrefix)
                {
                    healthReporter.ReportWarning($"{nameof(ElasticSearchOutput)}: The chosen index name prefix '{esOutputConfiguration.IndexNamePrefix}' "
                                                 + "contains uppercase characters, which are not allowed by Elasticsearch. The prefix will be converted to lowercase.",
                                                 EventFlowContextIdentifiers.Configuration);
                }
                esOutputConfiguration.IndexNamePrefix = lowerCaseIndexNamePrefix + Dash;
            }

            if (string.IsNullOrWhiteSpace(esOutputConfiguration.EventDocumentTypeName))
            {
                string warning = $"{nameof(ElasticSearchOutput)}: '{nameof(ElasticSearchOutputConfiguration.EventDocumentTypeName)}' configuration parameter "
                                 + "should not be empty";
                healthReporter.ReportWarning(warning, EventFlowContextIdentifiers.Configuration);
                esOutputConfiguration.EventDocumentTypeName = ElasticSearchOutputConfiguration.DefaultEventDocumentTypeName;
            }
        }
 private string GetIndexName(ElasticSearchConnectionData connectionData)
 {
     DateTimeOffset now = DateTimeOffset.UtcNow;
     string retval = connectionData.IndexNamePrefix + now.Year.ToString() + Dot + now.Month.ToString() + Dot + now.Day.ToString();
     return retval;
 }