diff --git a/TimberWinR/Configuration.cs b/TimberWinR/Configuration.cs index c3bee3e..5f12f39 100644 --- a/TimberWinR/Configuration.cs +++ b/TimberWinR/Configuration.cs @@ -110,51 +110,27 @@ namespace TimberWinR DumpInvalidNodes(child); } - static void parseConfInput(string xmlConfFile) { XDocument config = XDocument.Load(xmlConfFile, LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); - // Begin parsing the xml configuration file. + XElement allInputs = config.Root.Element(InputBase.TagName); + if (allInputs == null) + throw new TimberWinR.ConfigurationErrors.MissingRequiredTagException(InputBase.TagName); + + createInput(allInputs, WindowsEvent.ParentTagName, WindowsEvent.TagName, _events, WindowsEvent.Parse); + createInput(allInputs, TailFileInput.ParentTagName, TailFileInput.TagName, _logs, TailFileInput.Parse); + createInput(allInputs, IISLog.ParentTagName, IISLog.TagName, _iislogs, IISLog.Parse); + createInput(allInputs, IISW3CLog.ParentTagName, IISW3CLog.TagName, _iisw3clogs, IISW3CLog.Parse); + } + + static void createInput(XElement allInputs, string parentTagName, string tagName, List inputList, Action, XElement> parse) + { IEnumerable inputs = - from el in config.Root.Elements("Inputs") + from el in allInputs.Elements(parentTagName).Elements(tagName) select el; - - string tagName = "Inputs"; - if (inputs.Count() == 0) - throw new TimberWinR.ConfigurationErrors.MissingRequiredTagException(tagName); - - // WINDOWS EVENTS - IEnumerable xml_events = - from el in inputs.Elements("WindowsEvents").Elements("Event") - select el; - - foreach (XElement e in xml_events) - WindowsEvent.Parse(_events, e); - - // TEXT LOGS - IEnumerable xml_logs = - from el in inputs.Elements("Logs").Elements("Log") - select el; - - foreach (XElement e in xml_logs) - TailFileInput.Parse(_logs, e); - - // IIS LOGS - IEnumerable xml_iis = - from el in inputs.Elements("IISLogs").Elements("IISLog") - select el; - - foreach (XElement e in xml_iis) - IISLog.Parse(_iislogs, e); - - // IISW3C LOGS - IEnumerable xml_iisw3c = - from el in inputs.Elements("IISW3CLogs").Elements("IISW3CLog") - select el; - - foreach (XElement e in xml_iisw3c) - IISW3CLog.Parse(_iisw3clogs, e); + foreach (XElement input in inputs) + parse(inputList, input); } static void parseConfFilter(string xmlConfFile) @@ -162,7 +138,7 @@ namespace TimberWinR XDocument config = XDocument.Load(xmlConfFile, LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); IEnumerable filters = - from el in config.Root.Elements("Filters") + from el in config.Root.Elements(FilterBase.TagName) select el; foreach (XElement e in filters.Elements()) diff --git a/TimberWinR/Filters/FilterBase.cs b/TimberWinR/Filters/FilterBase.cs index 0b36282..5d53ac6 100644 --- a/TimberWinR/Filters/FilterBase.cs +++ b/TimberWinR/Filters/FilterBase.cs @@ -9,6 +9,8 @@ namespace TimberWinR.Filters { public abstract class FilterBase { + public const string TagName = "Filters"; + public abstract void Apply(JObject json); protected static string ParseStringAttribute(XElement e, string attributeName, string defaultValue="") diff --git a/TimberWinR/Inputs/IISLog.cs b/TimberWinR/Inputs/IISLog.cs index 11b0698..b4ca4c6 100644 --- a/TimberWinR/Inputs/IISLog.cs +++ b/TimberWinR/Inputs/IISLog.cs @@ -8,6 +8,9 @@ namespace TimberWinR.Inputs { public class IISLog : InputBase { + public const string ParentTagName = "IISLogs"; + public const string TagName = "IISLog"; + public string Name { get; private set; } public string Location { get; private set; } public int ICodepage { get; private set; } diff --git a/TimberWinR/Inputs/IISW3CLog.cs b/TimberWinR/Inputs/IISW3CLog.cs index fd07863..dd01721 100644 --- a/TimberWinR/Inputs/IISW3CLog.cs +++ b/TimberWinR/Inputs/IISW3CLog.cs @@ -7,6 +7,9 @@ namespace TimberWinR.Inputs { public class IISW3CLog : InputBase { + public const string ParentTagName = "IISW3CLogs"; + public const string TagName = "IISW3CLog"; + public string Name { get; private set; } public string Location { get; private set; } public int ICodepage { get; private set; } diff --git a/TimberWinR/Inputs/InputBase.cs b/TimberWinR/Inputs/InputBase.cs index 622c227..a5dfea6 100644 --- a/TimberWinR/Inputs/InputBase.cs +++ b/TimberWinR/Inputs/InputBase.cs @@ -10,6 +10,8 @@ namespace TimberWinR.Inputs { public abstract class InputBase { + public const string TagName = "Inputs"; + internal List parseFields(XElement parent, Dictionary allPossibleFields) { IEnumerable xml_fields = diff --git a/TimberWinR/Inputs/TailFileInput.cs b/TimberWinR/Inputs/TailFileInput.cs index 35147aa..1be09f1 100644 --- a/TimberWinR/Inputs/TailFileInput.cs +++ b/TimberWinR/Inputs/TailFileInput.cs @@ -7,6 +7,9 @@ namespace TimberWinR.Inputs { public class TailFileInput : InputBase { + public const string ParentTagName = "Logs"; + public const string TagName = "Log"; + public string Name { get; private set; } public string Location { get; private set; } public int ICodepage { get; private set; } diff --git a/TimberWinR/Inputs/WindowsEvent.cs b/TimberWinR/Inputs/WindowsEvent.cs index 4a457c2..2dd9a7d 100644 --- a/TimberWinR/Inputs/WindowsEvent.cs +++ b/TimberWinR/Inputs/WindowsEvent.cs @@ -8,6 +8,9 @@ namespace TimberWinR.Inputs { public class WindowsEvent : InputBase { + public const string ParentTagName = "WindowsEvents"; + public const string TagName = "Event"; + public string Source { get; private set; } public bool FullText { get; private set; } public bool ResolveSIDS { get; private set; }