diff --git a/TimberWinR.UnitTests/Configuration.cs b/TimberWinR.UnitTests/Configuration.cs index 207bf5e..a31dda9 100644 --- a/TimberWinR.UnitTests/Configuration.cs +++ b/TimberWinR.UnitTests/Configuration.cs @@ -5,18 +5,339 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TimberWinR; +using TimberWinR.Inputs; namespace TimberWinR.UnitTests { [TestFixture] public class ConfigurationTest { + Configuration c = new Configuration("testconf.xml"); + + public void OutputEvents() + { + foreach (var evt in c.Events.ToArray()) + { + Console.WriteLine(evt); + } + } + + public void OutputLogs() + { + foreach (var log in c.Logs.ToArray()) + { + Console.WriteLine(log); + } + } + + public void OutputIIS() + { + foreach (var iis in c.IIS.ToArray()) + { + Console.WriteLine(iis); + } + } + + public void OutputIISW3C() + { + foreach (var iisw3c in c.IISW3C.ToArray()) + { + Console.WriteLine(iisw3c); + } + } + + public void OutputGroks() + { + foreach (var grok in c.Groks.ToArray()) + { + Console.WriteLine(grok); + } + } + [Test] public void Test1() { - Configuration c = new Configuration("testconf.xml"); - Console.WriteLine(c.Logs.ToArray()); Assert.AreEqual(c.Logs.ToArray()[1].Name, "Second Set"); } + + [Test] + public void NumOfEvents() + { + Assert.AreEqual(1, c.Events.ToArray().Length); + } + + [Test] + public void NumOfLogs() + { + Assert.AreEqual(3, c.Logs.ToArray().Length); + } + + [Test] + public void NumOfIIS() + { + Assert.AreEqual(0, c.IIS.ToArray().Length); + } + + [Test] + public void NumOfIISW3C() + { + Assert.AreEqual(1, c.IISW3C.ToArray().Length); + } + + [Test] + public void NumOfGroks() + { + Assert.AreEqual(1, c.Groks.ToArray().Length); + } + + [Test] + public void FieldsOfEvents() + { + Dictionary fields = new Dictionary() + { + { "EventLog", typeof(string) }, + { "RecordNumber", typeof(int) }, + { "TimeGenerated", typeof(DateTime) }, + { "TimeWritten", typeof(DateTime) }, + { "EventID", typeof(int) }, + { "EventType", typeof(int) }, + { "EventTypeName", typeof(string) }, + { "EventCategory", typeof(int) }, + { "EventCategoryName", typeof(string) }, + { "SourceName", typeof(string) }, + { "Strings", typeof(string) }, + { "ComputerName", typeof(string) }, + { "SID", typeof(string) }, + { "Message", typeof(string) }, + { "Data", typeof(string) } + }; + foreach (FieldDefinition field in c.Events.ToArray()[0].Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + } + + [Test] + public void FieldsOfLogs() + { + Dictionary fields = new Dictionary() + { + { "LogFilename", typeof(string) }, + { "Index", typeof(int) }, + { "Text", typeof(string) } + }; + foreach (FieldDefinition field in c.Logs.ToArray()[0].Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + foreach (FieldDefinition field in c.Logs.ToArray()[1].Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + foreach (FieldDefinition field in c.Logs.ToArray()[2].Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + + } + + [Test] + public void FieldsOfIIS() + { + Dictionary fields = new Dictionary() + { + { "LogFilename", typeof(string) }, + { "LogRow", typeof(int) }, + { "UserIP", typeof(string) }, + { "UserName", typeof(string) }, + { "Date", typeof(DateTime) }, + { "Time", typeof(DateTime) }, + { "ServiceInstance", typeof(string) }, + { "HostName", typeof(string) }, + { "ServerIP", typeof(string) }, + { "TimeTaken", typeof(int) }, + { "BytesSent", typeof(int) }, + { "BytesReceived", typeof(int) }, + { "StatusCode", typeof(int) }, + { "Win32StatusCode", typeof(int) }, + { "RequestType", typeof(string) }, + { "Target", typeof(string) }, + { "Parameters", typeof(string) } + }; + + foreach (var iis in c.IIS.ToArray()) + { + foreach (FieldDefinition field in iis.Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + } + + } + + [Test] + public void FieldsOfIISW3C() + { + Dictionary fields = new Dictionary() + { + { "LogFilename", typeof(string) }, + { "LogRow", typeof(int) }, + { "date", typeof(DateTime) }, + { "time", typeof(DateTime) }, + { "c-ip", typeof(string) }, + { "cs-username", typeof(string) }, + { "s-sitename", typeof(string) }, + { "s-computername", typeof(int) }, + { "s-ip", typeof(string) }, + { "s-port", typeof(int) }, + { "cs-method", typeof(string) }, + { "cs-uri-stem", typeof(string) }, + { "cs-uri-query", typeof(string) }, + { "sc-status", typeof(int) }, + { "sc-substatus", typeof(int) }, + { "sc-win32-status", typeof(int) }, + { "sc-bytes", typeof(int) }, + { "cs-bytes", typeof(int) }, + { "time-taken", typeof(int) }, + { "cs-version", typeof(string) }, + { "cs-host", typeof(string) }, + { "cs(User-Agent)", typeof(string) }, + { "cs(Cookie)", typeof(string) }, + { "cs(Referer)", typeof(string) }, + { "s-event", typeof(string) }, + { "s-process-type", typeof(string) }, + { "s-user-time", typeof(double) }, + { "s-kernel-time", typeof(double) }, + { "s-page-faults", typeof(int) }, + { "s-total-procs", typeof(int) }, + { "s-active-procs", typeof(int) }, + { "s-stopped-procs", typeof(int) } + }; + foreach (FieldDefinition field in c.IISW3C.ToArray()[0].Fields) + { + Assert.Contains(field.Name, fields.Keys); + } + } + + [Test] + public void ParametersOfEvents() + { + string source = "System,Application"; + bool fullText = true; + bool resolveSIDS = true; + bool formatMsg = true; + string msgErrorMode = "MSG"; + bool fullEventCode = false; + string direction = "FW"; + string stringsSep = "|"; + string iCheckpoint; + string binaryFormat = "PRINT"; + + TimberWinR.Configuration.WindowsEvent evt = c.Events.ToArray()[0]; + + Assert.AreEqual(source, evt.Source); + Assert.AreEqual(fullText, evt.FullText); + Assert.AreEqual(resolveSIDS, evt.ResolveSIDS); + Assert.AreEqual(formatMsg, evt.FormatMsg); + Assert.AreEqual(msgErrorMode, evt.MsgErrorMode); + Assert.AreEqual(fullEventCode, evt.FullEventCode); + Assert.AreEqual(direction, evt.Direction); + Assert.AreEqual(stringsSep, evt.StringsSep); + Assert.IsNull(evt.ICheckpoint); + Assert.AreEqual(binaryFormat, evt.BinaryFormat); + } + + [Test] + public void ParametersOfLogs() + { + string name = "First Set"; + string location = @"C:\Logs1\*.log"; + int iCodepage = 0; + int recurse = 0; + bool splitLongLines = false; + string iCheckpoint; + + TimberWinR.Configuration.TextLog log = c.Logs.ToArray()[0]; + + Assert.AreEqual(name, log.Name); + Assert.AreEqual(location, log.Location); + Assert.AreEqual(iCodepage, log.ICodepage); + Assert.AreEqual(recurse, log.Recurse); + Assert.AreEqual(splitLongLines, log.SplitLongLines); + Assert.IsNull(log.ICheckpoint); + + name = "Second Set"; + location = @"C:\Logs2\*.log"; + iCodepage = 0; + recurse = 0; + splitLongLines = false; + + log = c.Logs.ToArray()[1]; + + Assert.AreEqual(name, log.Name); + Assert.AreEqual(location, log.Location); + Assert.AreEqual(iCodepage, log.ICodepage); + Assert.AreEqual(recurse, log.Recurse); + Assert.AreEqual(splitLongLines, log.SplitLongLines); + Assert.IsNull(log.ICheckpoint); + + + name = "Third Set"; + location = @"C:\Logs2\1.log,C:\Logs2\2.log"; + iCodepage = 0; + recurse = 0; + splitLongLines = false; + + log = c.Logs.ToArray()[2]; + + Assert.AreEqual(name, log.Name); + Assert.AreEqual(location, log.Location); + Assert.AreEqual(iCodepage, log.ICodepage); + Assert.AreEqual(recurse, log.Recurse); + Assert.AreEqual(splitLongLines, log.SplitLongLines); + Assert.IsNull(log.ICheckpoint); + } + + [Test] + public void ParametersOfIISW3C() + { + string name = "Default site"; + string location = @"c:\inetpub\logs\LogFiles\W3SVC1\*"; + int iCodepage = -2; + int recurse = 0; + string minDateMod; + bool dQuotes = false; + bool dirTime = false; + bool consolidateLogs = false; + string iCheckpoint; + + TimberWinR.Configuration.IISW3CLog iisw3c = c.IISW3C.ToArray()[0]; + + Assert.AreEqual(name, iisw3c.Name); + Assert.AreEqual(location, iisw3c.Location); + Assert.AreEqual(iCodepage, iisw3c.ICodepage); + Assert.AreEqual(recurse, iisw3c.Recurse); + Assert.IsNull(iisw3c.MinDateMod); + Assert.AreEqual(dQuotes, iisw3c.DQuotes); + Assert.AreEqual(dirTime, iisw3c.DirTime); + Assert.AreEqual(consolidateLogs, iisw3c.ConsolidateLogs); + Assert.IsNull(iisw3c.ICheckpoint); + } + + [Test] + public void ParametersOfGrok() + { + string match = "%{IPAddress:ip1} %{IPAddress:ip2}"; + TimberWinR.Configuration.Pair addField = new TimberWinR.Configuration.Pair("field1", @"%{foo}"); + bool dropIfMatch = true; + string removeField = "ip1"; + + TimberWinR.Configuration.Grok grok = c.Groks.ToArray()[0]; + + Assert.AreEqual(match, grok.Match); + Assert.AreEqual(addField, grok.AddField); + Assert.AreEqual(dropIfMatch, grok.DropIfMatch); + Assert.AreEqual(removeField, grok.RemoveField); + } } } diff --git a/TimberWinR/Configuration.cs b/TimberWinR/Configuration.cs index f07dd76..a4d2f1b 100644 --- a/TimberWinR/Configuration.cs +++ b/TimberWinR/Configuration.cs @@ -1339,9 +1339,9 @@ namespace TimberWinR private int iCodepage = -2; private int recurse = 0; private string minDateMod; - private bool dQuotes; - private bool dirTime; - private bool consolidateLogs; + private bool dQuotes = false; + private bool dirTime = false; + private bool consolidateLogs = false; private string iCheckpoint; public Builder WithICodepage(int value)