public void VerifyAllConfigOptionsMappedToConfigObject()
        {
            var pipelineConfigObj = new Dictionary <string, object>
            {
                ["inputs"] = new List <Dictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        ["logLevel"] = "Verbose"
                    }
                }
            };

            using (var configFile = new TemporaryFile())
            {
                var pipelineConfig = JsonConvert.SerializeObject(pipelineConfigObj, EventFlowJsonUtilities.GetDefaultSerializerSettings());

                configFile.Write(pipelineConfig);
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddJsonFile(configFile.FilePath);
                var configuration       = configBuilder.Build();
                var inputsConfigSection = configuration.GetSection("inputs");
                var configFragments     = inputsConfigSection.GetChildren().ToList();

                var l4nInputConfiguration = new Log4netConfiguration();
                configFragments[0].Bind(l4nInputConfiguration);

                Assert.Equal("Verbose", l4nInputConfiguration.LogLevel);
            }
        }
示例#2
0
        public void VerifyAllConfigOptionsMappedToConfigObject()
        {
            var pipelineConfigObj = new Dictionary <string, object>
            {
                ["outputs"] = new List <Dictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        ["type"]                            = "ElasticSearch",
                        ["indexNamePrefix"]                 = "myprefix",
                        ["serviceUri"]                      = "http://localhost:1000;http://localhost:1001;http://localhost:1002",
                        ["basicAuthenticationUserName"]     = "******",
                        ["basicAuthenticationUserPassword"] = "******",
                        ["numberOfShards"]                  = 10,
                        ["numberOfReplicas"]                = 20,
                        ["refreshInterval"]                 = "60s",
                        ["useSniffingConnectionPooling"]    = "true",
                        ["mappings"]                        = new Dictionary <string, object>
                        {
                            ["properties"] = new Dictionary <string, object>
                            {
                                ["timestamp"] = new Dictionary <string, object>
                                {
                                    ["type"] = "date_nanos"
                                }
                            }
                        }
                    }
                }
            };

            using (var configFile = new TemporaryFile())
            {
                var pipelineConfig = JsonConvert.SerializeObject(pipelineConfigObj, EventFlowJsonUtilities.GetDefaultSerializerSettings());

                configFile.Write(pipelineConfig);
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddJsonFile(configFile.FilePath);
                var configuration       = configBuilder.Build();
                var outputConfigSection = configuration.GetSection("outputs");
                var configFragments     = outputConfigSection.GetChildren().ToList();

                var esOutputConfiguration = new ElasticSearchOutputConfiguration();
                configFragments[0].Bind(esOutputConfiguration);

                Assert.Equal("myprefix", esOutputConfiguration.IndexNamePrefix);
                Assert.Equal("http://localhost:1000;http://localhost:1001;http://localhost:1002", esOutputConfiguration.ServiceUri);
                Assert.Equal("myesuser", esOutputConfiguration.BasicAuthenticationUserName);
                Assert.Equal("myespass", esOutputConfiguration.BasicAuthenticationUserPassword);
                Assert.Equal(10, esOutputConfiguration.NumberOfShards);
                Assert.Equal(20, esOutputConfiguration.NumberOfReplicas);
                Assert.Equal("60s", esOutputConfiguration.RefreshInterval);

                Assert.NotNull(esOutputConfiguration.Mappings);
                Assert.NotNull(esOutputConfiguration.Mappings.Properties);
                Assert.NotNull(esOutputConfiguration.Mappings.Properties["timestamp"]);

                Assert.Equal("date_nanos", esOutputConfiguration.Mappings.Properties["timestamp"].Type);
            }
        }
示例#3
0
 public StdOutput(IHealthReporter healthReporter)
 {
     Requires.NotNull(healthReporter, nameof(healthReporter));
     this.healthReporter = healthReporter;
     SerializerSettings  = EventFlowJsonUtilities.GetDefaultSerializerSettings();
     this.writeOutput    = Console.WriteLine;
 }
示例#4
0
        // The Initialize method is not thread-safe. Please only call this on one thread and do so before the pipeline starts sending
        // data to this output
        private void Initialize()
        {
            Debug.Assert(this.healthReporter != null);

            this.clients = new IEventHubClient[ConcurrentConnections];
            for (uint i = 0; i < this.clients.Length; i++)
            {
                this.clients[i] = this.eventHubClientFactory(this.outputConfiguration);
            }

            SerializerSettings = EventFlowJsonUtilities.GetDefaultSerializerSettings();
        }
示例#5
0
        private void Initialize(HttpOutputConfiguration configuration, Implementation.IHttpClient httpClient)
        {
            string errorMessage;

            Debug.Assert(configuration != null);
            Debug.Assert(this.healthReporter != null);

            this.httpClient    = httpClient ?? new StandardHttpClient();
            this.configuration = configuration;

            if (string.IsNullOrWhiteSpace(this.configuration.ServiceUri))
            {
                var errMsg = $"{nameof(HttpOutput)}: no ServiceUri configured";
                healthReporter.ReportProblem(errMsg);
                throw new Exception(errMsg);
            }

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

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

            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
            {
                string httpAuthValue = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", userName, password)));
                this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", httpAuthValue);
            }

            switch (this.configuration.Format)
            {
            case HttpOutputFormat.Json:
            case HttpOutputFormat.JsonLines:
                if (string.IsNullOrWhiteSpace(this.configuration.HttpContentType))
                {
                    this.configuration.HttpContentType = "application/json";
                }
                break;
            }

            foreach (KeyValuePair <string, string> header in configuration.Headers)
            {
                this.httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
            }

            SerializerSettings = EventFlowJsonUtilities.GetDefaultSerializerSettings();
        }
示例#6
0
        public void SerializesMethodInfoAsFullyQualifiedName()
        {
            var obj = new
            {
                Name   = "foo",
                Method = typeof(JsonSerializationTests).GetMethod(nameof(SerializesMethodInfoAsFullyQualifiedName))
            };

            string objString = JsonConvert.SerializeObject(obj, EventFlowJsonUtilities.GetDefaultSerializerSettings());

            Assert.Equal(
                @"{
                ""Name"":""foo"",
                ""Method"":""Microsoft.Diagnostics.EventFlow.Core.Tests.JsonSerializationTests.SerializesMethodInfoAsFullyQualifiedName""
            }".RemoveAllWhitespace(), objString);
        }
示例#7
0
        public void UsesIsoDateFormat()
        {
            EventData e = new EventData();

            e.Payload.Add("DateTimeProperty", new DateTime(2017, 4, 19, 10, 15, 23, DateTimeKind.Utc));
            e.Payload.Add("DateTimeOffsetProperty", new DateTimeOffset(2017, 4, 19, 10, 16, 07, TimeSpan.Zero));

            var    messagingData = EventDataExtensions.ToMessagingEventData(e, EventFlowJsonUtilities.GetDefaultSerializerSettings(), out int messageSize);
            string messageBody   = Encoding.UTF8.GetString(messagingData.Body.Array, messagingData.Body.Offset, messagingData.Body.Count);

            var dateTimeRegex = new Regex(@"""DateTimeProperty"" \s* : \s* ""2017-04-19T10:15:23Z""", RegexOptions.IgnorePatternWhitespace, TimeSpan.FromMilliseconds(100));

            Assert.Matches(dateTimeRegex, messageBody);

            var dateTimeOffsetRegex = new Regex(@"""DateTimeOffsetProperty"" \s* : \s* ""2017-04-19T10:16:07\+00:00""", RegexOptions.IgnorePatternWhitespace, TimeSpan.FromMilliseconds(100));

            Assert.Matches(dateTimeOffsetRegex, messageBody);
        }
示例#8
0
        public void VerifyAllConfigOptionsMappedToConfigObject()
        {
            var pipelineConfigObj = new Dictionary <string, object>
            {
                ["outputs"] = new List <Dictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        ["type"]       = "Http",
                        ["format"]     = "JsonLines",
                        ["ServiceUri"] = "http://localhost:1000",
                        ["basicAuthenticationUserName"]     = "******",
                        ["basicAuthenticationUserPassword"] = "******",
                        ["httpContentType"] = "application/x-custom",
                        ["headers"]         = new Dictionary <string, string>
                        {
                            ["X-Foo"] = "example"
                        }
                    }
                }
            };

            using (var configFile = new TemporaryFile())
            {
                var pipelineConfig = JsonConvert.SerializeObject(pipelineConfigObj, EventFlowJsonUtilities.GetDefaultSerializerSettings());

                configFile.Write(pipelineConfig);
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddJsonFile(configFile.FilePath);
                var configuration       = configBuilder.Build();
                var outputConfigSection = configuration.GetSection("outputs");
                var configFragments     = outputConfigSection.GetChildren().ToList();

                var httpOutputConfiguration = new HttpOutputConfiguration();
                configFragments[0].Bind(httpOutputConfiguration);

                Assert.Equal("http://localhost:1000", httpOutputConfiguration.ServiceUri);
                Assert.Equal(HttpOutputFormat.JsonLines, httpOutputConfiguration.Format);
                Assert.Equal("mywebuser", httpOutputConfiguration.BasicAuthenticationUserName);
                Assert.Equal("mywebpass", httpOutputConfiguration.BasicAuthenticationUserPassword);
                Assert.Equal("application/x-custom", httpOutputConfiguration.HttpContentType);
                Assert.Equal("example", httpOutputConfiguration.Headers["X-Foo"]);
            }
        }
示例#9
0
        public void SerializesIPAddress()
        {
            var ipAddress = IPAddress.Parse("127.0.0.1");

            var obj = new
            {
                IpAddress = ipAddress
            };

            // ensure assumption that IPAddress cannot be serialized with default JSON settings
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(obj));

            string objString = JsonConvert.SerializeObject(obj, EventFlowJsonUtilities.GetDefaultSerializerSettings());

            Assert.Equal(
                @"{
                ""IpAddress"":""127.0.0.1""
            }".RemoveAllWhitespace(), objString);
        }
示例#10
0
        // The Initialize method is not thread-safe. Please only call this on one thread and do so before the pipeline starts sending
        // data to this output
        private void Initialize()
        {
            Debug.Assert(this.healthReporter != null);

            if (string.IsNullOrWhiteSpace(this.outputConfiguration.ConnectionString))
            {
                var errorMessage = $"{nameof(EventHubOutput)}: '{nameof(EventHubOutputConfiguration.ConnectionString)}' configuration parameter must be set to a valid connection string";
                healthReporter.ReportProblem(errorMessage, EventFlowContextIdentifiers.Configuration);
                throw new Exception(errorMessage);
            }

            this.clients = new IEventHubClient[ConcurrentConnections];
            for (uint i = 0; i < this.clients.Length; i++)
            {
                this.clients[i] = this.eventHubClientFactory(this.outputConfiguration.ConnectionString);
            }

            SerializerSettings = EventFlowJsonUtilities.GetDefaultSerializerSettings();
        }
 private void Initialize(OmsOutputConfiguration configuration)
 {
     this.connectionData = CreateConnectionData(configuration);
     SerializerSettings  = EventFlowJsonUtilities.GetDefaultSerializerSettings();
 }