public void TestTextDecoration(string sinkId) { string id = sinkId + (Utility.IsWindow ? string.Empty : TestUtility.LINUX); MemoryLogger logger = new MemoryLogger(null); MockEventSource <string> mockEventSource = CreateEventsource <string>("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(id, logger); mockEventSource.Subscribe(sink); string data = "some text"; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data, timestamp); Assert.Equal($"{ComputerOrHostName}:::{timestamp.ToString("yyyy-MM-dd HH:mm:ss")}:::{data}", sink.Records[0]); }
public void TestLocalVariableJObject(string sinkId) { MemoryLogger logger = new MemoryLogger(null); MockEventSource <JObject> mockEventSource = CreateEventsource <JObject>("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(sinkId, logger); //"TextDecoration": "{$myvar2}" mockEventSource.Subscribe(sink); var data1 = JObject.Parse("{\"myvar1\": \"myval1\"}"); var data2 = JObject.Parse("{\"myvar2\": \"myval2\"}"); DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data1, timestamp); Assert.Empty(sink.Records); mockEventSource.MockEvent(data2, timestamp); Assert.Equal("myval2", sink.Records[0]); }
public void ConvertsPowerShellSource() { var records = new List <Envelope <JObject> > { new Envelope <JObject>(JObject.Parse("{\"ComputerName\":\"MyComputer\",\"Name\":\"TrustedInstaller\",\"Status\":\"Running\"}")), new Envelope <JObject>(JObject.Parse("{\"ComputerName\":\"MyComputer\",\"Name\":\"WinRM\",\"Status\":\"Stopped\"}")) }; var config = TestUtility.GetConfig("Pipes", "PSEMFTestPipe"); using (var logger = new MemoryLogger(nameof(EMFPipeTests))) { var context = new PluginContext(config, logger, null); var source = new MockEventSource <JObject>(context); var sink = new MockEventSink(context); context.ContextData[PluginContext.SOURCE_TYPE] = source.GetType(); context.ContextData[PluginContext.SOURCE_OUTPUT_TYPE] = source.GetOutputType(); context.ContextData[PluginContext.SINK_TYPE] = sink.GetType(); var pipe = new EMFPipe <JObject>(context); source.Subscribe(pipe); pipe.Subscribe(sink); foreach (var r in records) { source.MockEvent(r.Data); } Assert.Equal(2, sink.Records.Count); var jo = JObject.Parse(sink.Records.First()); Assert.Equal("PSNamespace", jo["_aws"]["CloudWatchMetrics"][0]["Namespace"].ToString()); Assert.Equal("ServiceStatus", jo["_aws"]["CloudWatchMetrics"][0]["Metrics"][0]["Name"].ToString()); Assert.Equal(1, jo["ServiceStatus"].ToObject <int>()); Assert.Equal("Running", jo["Status"].ToString()); Assert.Equal("TrustedInstaller", jo["Name"].ToString()); var dims = jo["_aws"]["CloudWatchMetrics"][0]["Dimensions"][0].ToArray().Select(i => i.ToString()).ToList(); Assert.Equal(3, dims.Count); Assert.Contains("Name", dims); Assert.Contains("ComputerName", dims); Assert.Contains("Status", dims); jo = JObject.Parse(sink.Records.Last()); Assert.Equal("Stopped", jo["Status"].ToString()); Assert.Equal("WinRM", jo["Name"].ToString()); } }
public void TextDecorationWithFileName(string sinkId) { string id = sinkId + (Utility.IsWindows ? string.Empty : TestUtility.LINUX); MemoryLogger logger = new MemoryLogger(null); MockEventSource <string> mockEventSource = CreateEventsource <string>("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(id, logger); mockEventSource.Subscribe(sink); string data = "some text"; DateTime timestamp = DateTime.UtcNow; string filePath = Path.Combine(TestUtility.GetTestHome(), "test.log"); long position = 11; long lineNumber = 1; mockEventSource.MockLogEvent(data, timestamp, data, filePath, position, lineNumber); Assert.Equal($"{ComputerOrHostName}:::{Path.GetFileName(filePath)}:::{position}:::{data}", sink.Records[0]); }
public void TestStringPipe() { var config = TestUtility.GetConfig("Pipes", "TestPipe"); var context = new PluginContext(config, null, null); var source = new MockEventSource <string>(context); var sink = new MockEventSink(context); context.ContextData[PluginContext.SOURCE_TYPE] = source.GetType(); context.ContextData[PluginContext.SINK_TYPE] = sink.GetType(); var pipe = new PipeFactory().CreateInstance(PipeFactory.REGEX_FILTER_PIPE, context); source.Subscribe(pipe); pipe.Subscribe(sink); string record1 = "24,09/29/17,00:00:04,Database Cleanup Begin,,,,,0,6,,,,,,,,,0"; source.MockEvent(record1); source.MockEvent("25,09/29/17,00:00:04,0 leases expired and 0 leases deleted,,,,,0,6,,,,,,,,,0"); Assert.Single(sink.Records); Assert.Equal(record1, sink.Records[0]); }
public void TestObjectDecoration(string sinkId) { string id = sinkId + (Utility.IsWindows ? string.Empty : TestUtility.LINUX); MemoryLogger logger = new MemoryLogger(null); MockEventSource <IDictionary <string, string> > mockEventSource = CreateEventsource <IDictionary <string, string> >("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(id, logger); mockEventSource.Subscribe(sink); string text = "some text"; Dictionary <string, string> data = new Dictionary <string, string>() { { "data", text } }; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data, timestamp); string result = sink.Records[0]; Assert.Equal($"{{\"data\":\"{text}\",\"ComputerName\":\"{ComputerOrHostName}\",\"DT\":\"{timestamp.ToString("yyyy-MM-dd HH:mm:ss")}\"}}", result); }
public void TestLocalVariableDictionary(string sinkId) { MemoryLogger logger = new MemoryLogger(null); MockEventSource <IDictionary <string, string> > mockEventSource = CreateEventsource <IDictionary <string, string> >("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(sinkId, logger); //"TextDecoration": "{$myvar2}" mockEventSource.Subscribe(sink); var data1 = new Dictionary <string, string>() { { "myvar1", "myval1" } }; var data2 = new Dictionary <string, string>() { { "myvar2", "myval2" } }; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data1, timestamp); Assert.Empty(sink.Records); mockEventSource.MockEvent(data2, timestamp); Assert.Equal("myval2", sink.Records[0]); }
public void TestLocalVariableAnonymousObject() { MemoryLogger logger = new MemoryLogger(null); MockEventSource <object> mockEventSource = CreateEventsource <object>("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink("TextDecorationLocalVariable", logger); //"TextDecoration": "{$myvar2}" mockEventSource.Subscribe(sink); var data1 = new { myvar1 = "myval1" }; var data2 = new { myvar2 = "myval2" }; DateTime timestamp = DateTime.UtcNow; mockEventSource.MockEvent(data1, timestamp); Assert.Empty(sink.Records); mockEventSource.MockEvent(data2, timestamp); Assert.Equal("myval2", sink.Records[0]); }
public void TestObjectDecorationWithFileName(string sinkId) { string id = sinkId + (Utility.IsWindows ? string.Empty : TestUtility.LINUX); MemoryLogger logger = new MemoryLogger(null); MockEventSource <IDictionary <string, string> > mockEventSource = CreateEventsource <IDictionary <string, string> >("InitialPositionUnspecified"); MockEventSink sink = CreateEventSink(id, logger); mockEventSource.Subscribe(sink); string text = "some text"; Dictionary <string, string> data = new Dictionary <string, string>() { { "data", text } }; DateTime timestamp = DateTime.UtcNow; string filePath = Path.Combine(TestUtility.GetTestHome(), "test.log"); long position = 11; long lineNumber = 1; mockEventSource.MockLogEvent(data, timestamp, text, filePath, position, lineNumber); string result = sink.Records[0]; Assert.Equal($"{{\"data\":\"{text}\",\"ComputerName\":\"{ComputerOrHostName}\",\"FileName\":\"{Path.GetFileName(filePath)}\",\"Position\":\"{position}\"}}", result); }