// [Test(Description = "Test using next")] public void TestMultiline1() { using (StreamReader sr = new StreamReader("Multiline1.txt")) { List<JObject> events = new List<JObject>(); Console.SetIn(sr); Stdin sin = new Stdin(); sin.CodecArguments = new CodecArguments(); sin.CodecArguments.Pattern = "\\\\$"; sin.CodecArguments.What = CodecArguments.WhatType.next; sin.CodecArguments.Type = CodecArguments.CodecType.multiline; var cancelTokenSource = new CancellationTokenSource(); using (var syncHandle = new ManualResetEventSlim()) { try { StdinListener sl = new StdinListener(sin, cancelTokenSource.Token); sl.OnMessageRecieved += o => { events.Add(o); if (events.Count >= 6) cancelTokenSource.Cancel(); }; if (!cancelTokenSource.Token.IsCancellationRequested) syncHandle.Wait(TimeSpan.FromSeconds(10000), cancelTokenSource.Token); } catch (OperationCanceledException) { } } Assert.AreEqual(events.Count, 6); Assert.AreEqual(events[0]["message"].ToString(), "multiline1 \\\nml1_1 \\\nml1_2 \\\nml1_2 "); Assert.AreEqual(events[1]["message"].ToString(), "singleline1"); Assert.AreEqual(events[2]["message"].ToString(), "singleline2"); Assert.AreEqual(events[3]["message"].ToString(), "multiline2 \\\nml2_1 \\\nml2_2"); Assert.AreEqual(events[4]["message"].ToString(), "multiline3 \\\nml3_1 \\\nml3_2"); Assert.AreEqual(events[5]["message"].ToString(), "singleline3"); } }
public void ProcessConfiguration(CancellationToken cancelToken, Configuration config) { // Read the Configuration file if (config != null) { if (OnConfigurationProcessed != null) OnConfigurationProcessed(config); if (config.StatsDOutputs != null) { foreach (var ro in config.StatsDOutputs) { var output = new StatsDOutput(this, ro, cancelToken); Outputs.Add(output); } } if (config.RedisOutputs != null) { foreach (var ro in config.RedisOutputs) { var redis = new RedisOutput(this, ro, cancelToken); Outputs.Add(redis); } } if (config.ElasticsearchOutputs != null) { foreach (var ro in config.ElasticsearchOutputs) { var els = new ElasticsearchOutput(this, ro, cancelToken); Outputs.Add(els); } } if (config.StdoutOutputs != null) { foreach (var ro in config.StdoutOutputs) { var stdout = new StdoutOutput(this, ro, cancelToken); Outputs.Add(stdout); } } if (config.FileOutputs != null) { foreach (var ro in config.FileOutputs) { var output = new FileOutput(this, ro, cancelToken); Outputs.Add(output); } } foreach (Parser.IISW3CLogParameters iisw3cConfig in config.IISW3C) { var elistner = new IISW3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (Parser.W3CLogParameters iisw3cConfig in config.W3C) { var elistner = new W3CInputListener(iisw3cConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (Parser.WindowsEvent eventConfig in config.Events) { var elistner = new WindowsEvtInputListener(eventConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var logConfig in config.Logs) { var elistner = new LogsListener(logConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var logConfig in config.TailFiles) { var elistner = new TailFileListener(logConfig, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var tcp in config.Tcps) { var elistner = new TcpInputListener(tcp, cancelToken, tcp.Port); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var udp in config.Udps) { var elistner = new UdpInputListener(udp, cancelToken, udp.Port); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var stdin in config.Stdins) { var elistner = new StdinListener(stdin, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } foreach (var stdin in config.Generators) { var elistner = new GeneratorInput(stdin, cancelToken); Listeners.Add(elistner); foreach (var output in Outputs) output.Connect(elistner); } var computerName = System.Environment.MachineName + "." + Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\services\Tcpip\Parameters") .GetValue("Domain", "") .ToString(); foreach (var output in Outputs) { var name = Assembly.GetExecutingAssembly().GetName(); JObject json = new JObject( new JProperty("TimberWinR", new JObject( new JProperty("version", Assembly.GetEntryAssembly().GetName().Version.ToString()), //GetAssemblyByName("TimberWinR.ServiceHost").GetName().Version.ToString()), new JProperty("host", computerName), new JProperty("output", output.Name), new JProperty("initialized", DateTime.UtcNow) ))); json.Add(new JProperty("type", "Win32-TimberWinR")); json.Add(new JProperty("host", computerName)); output.Startup(json); } } }
// [Test(Description = "Test using previous")] public void TestMultiline2() { using (StreamReader sr = new StreamReader("Multiline2.txt")) { List<JObject> events = new List<JObject>(); Console.SetIn(sr); Stdin sin = new Stdin(); sin.CodecArguments = new CodecArguments(); sin.CodecArguments.Pattern = "^(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2},\\d{3})(.*)$"; sin.CodecArguments.What = CodecArguments.WhatType.previous; sin.CodecArguments.Type = CodecArguments.CodecType.multiline; sin.CodecArguments.Negate = true; var cancelTokenSource = new CancellationTokenSource(); using (var syncHandle = new ManualResetEventSlim()) { try { StdinListener sl = new StdinListener(sin, cancelTokenSource.Token); sl.OnMessageRecieved += o => { events.Add(o); if (events.Count >= 4) cancelTokenSource.Cancel(); }; if (!cancelTokenSource.Token.IsCancellationRequested) syncHandle.Wait(TimeSpan.FromSeconds(10000), cancelTokenSource.Token); } catch (OperationCanceledException) { } } Assert.AreEqual(events.Count, 4); Assert.AreEqual(events[0]["message"].ToString(), "2015-01-07 13:14:26,572 TEST DEBUG [THREAD : 25] - Sending message to TServer - tcp://10.1111.11.111:1111\n'RequestAttachUserData' ('30')\nmessage attributes:\nAttributeConnID [long] = 00890\nAttributeReferenceID [int] = 88\nAttributeThisDN [str] = \"2214\"\nAttributeUserData [bstr] = KVList: \n\t\t'ActivityID' [str] = \"1-XXXXXX\""); Assert.AreEqual(events[1]["message"].ToString(), "2015-01-07 13:14:26,574 TEST DEBUG [THREAD : 25] - Writing message RequestAttachUserData in 'proxy1' via '.StatePrimary proxy: proxy1'"); Assert.AreEqual(events[2]["message"].ToString(), "2015-01-07 13:14:26,575 TEST DEBUG [THREAD : 25] - sending RequestAttachUserData to Test.Platform.Commons.Connection.CommonConnection"); Assert.AreEqual(events[3]["message"].ToString(), "2015-01-07 13:20:31,665 TEST DEBUG [THREAD : SelectorThread] - Proxy got message 'EventOnHook' ('87')\nmessage attributes:\nAttributeEventSequenceNumber [long] = 4899493\nTime = ComplexClass(TimeStamp):\n\tAttributeTimeinuSecs [int] = 573000\n\tAttributeTimeinSecs [int] = 1420644031\nAttributeThisDN [str] = \"2214\"\n. Processing with state .StatePrimary proxy: proxy1"); } }