From fa9de3cfef6cb494785aebc28724fbf1e8dd0871 Mon Sep 17 00:00:00 2001 From: Jonathan Preddy Date: Tue, 22 Jul 2014 11:42:22 -0400 Subject: [PATCH] Implemented DateFilter.cs --- TimberWinR/Configuration.cs | 83 ++----------------------------- TimberWinR/Filters/DateFilter.cs | 75 ++++++++++++++++++++++++++++ TimberWinR/Filters/GrokFilter.cs | 84 ++++++++++++++++++++++++++++++-- 3 files changed, 161 insertions(+), 81 deletions(-) diff --git a/TimberWinR/Configuration.cs b/TimberWinR/Configuration.cs index 4f313ce..e1bbaaf 100644 --- a/TimberWinR/Configuration.cs +++ b/TimberWinR/Configuration.cs @@ -9,6 +9,7 @@ using System.IO; using System.Globalization; using TimberWinR.Inputs; using TimberWinR.Filters; +using TimberWinR.Filters.GrokFilter.Pair; using System.Xml.Schema; using NLog; @@ -476,7 +477,7 @@ namespace TimberWinR switch (e.Name.ToString()) { case "Grok": - Params_Grok args = parseParams_Grok(e.Elements()); + TimberWinR.Filters.GrokFilter.Params_Grok args = parseParams_Grok(e.Elements()); GrokFilter grok = new GrokFilter(args); _filters.Add(grok); break; @@ -867,9 +868,9 @@ namespace TimberWinR return p.Build(); } - static Params_Grok parseParams_Grok(IEnumerable elements) + static TimberWinR.Filters.GrokFilter.Params_Grok parseParams_Grok(IEnumerable elements) { - Params_Grok.Builder p = new Params_Grok.Builder(); + TimberWinR.Filters.GrokFilter.Params_Grok.Builder p = new TimberWinR.Filters.GrokFilter.Params_Grok.Builder(); foreach (XElement e in elements) { @@ -921,7 +922,7 @@ namespace TimberWinR { throw new MissingRequiredAttributeException(e, attributeName); } - Pair addField = new Pair(name, value); + TimberWinR.Filters.GrokFilter.Pair addField = new TimberWinR.Filters.GrokFilter.Pair(name, value); p.WithAddField(addField); break; case "DropIfMatch": @@ -1461,83 +1462,9 @@ namespace TimberWinR } } - public struct Pair - { - public readonly string Name, Value; - - public Pair(string name, string value) - { - Name = name; - Value = value; - } - - public override string ToString() - { - return String.Format("Name:= {0} , Value:= {1}", Name, Value); - } - } - public class Params_Grok - { - public string Match { get; private set; } - public string Field { get; private set; } - public Pair AddField { get; private set; } - public bool DropIfMatch { get; private set; } - public string RemoveField { get; private set; } - public class Builder - { - private string match; - private string field; - private Pair addField; - private bool dropIfMatch = false; - private string removeField; - - public Builder WithField(string value) - { - field = value; - return this; - } - - public Builder WithMatch(string value) - { - match = value; - return this; - } - - public Builder WithAddField(Pair value) - { - addField = value; - return this; - } - - public Builder WithDropIfMatch(bool value) - { - dropIfMatch = value; - return this; - } - - public Builder WithRemoveField(string value) - { - removeField = value; - return this; - } - - public Params_Grok Build() - { - return new Params_Grok() - { - Match = match, - Field = field, - AddField = addField, - DropIfMatch = dropIfMatch, - RemoveField = removeField - }; - } - - } - } } } \ No newline at end of file diff --git a/TimberWinR/Filters/DateFilter.cs b/TimberWinR/Filters/DateFilter.cs index af0b404..ce96832 100644 --- a/TimberWinR/Filters/DateFilter.cs +++ b/TimberWinR/Filters/DateFilter.cs @@ -12,9 +12,84 @@ namespace TimberWinR.Filters public bool ConvertToUTC { get; private set; } public List Pattern { get; private set; } + public DateFilter(Params_DateFilter args) + { + Field = args.Field; + Target = args.Target; + ConvertToUTC = args.ConvertToUTC; + Pattern = args.Pattern; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("DateFilter\n"); + foreach (var prop in this.GetType().GetProperties()) + { + if (prop != null) + { + sb.Append(String.Format("\t{0}: {1}\n", prop.Name, prop.GetValue(this, null))); + } + + } + return sb.ToString(); + } + public override void Apply(Newtonsoft.Json.Linq.JObject json) { throw new NotImplementedException(); } + + public class Params_DateFilter + { + public string Field { get; private set; } + public string Target { get; private set; } + public bool ConvertToUTC { get; private set; } + public List Pattern { get; private set; } + + public class Builder + { + private string field; + private string target; + private bool convertToUTC = false; + private List pattern; + + public Builder WithField(string value) + { + field = value; + return this; + } + + public Builder WithTarget(string value) + { + target = value; + return this; + } + + public Builder WithConvertToUTC(bool value) + { + convertToUTC = value; + return this; + } + + public Builder WithPattern(string value) + { + pattern.Add(value); + return this; + } + + public Params_DateFilter Build() + { + return new Params_DateFilter() + { + Field = field, + Target = target, + ConvertToUTC = convertToUTC, + Pattern = pattern + }; + } + + } + } } } diff --git a/TimberWinR/Filters/GrokFilter.cs b/TimberWinR/Filters/GrokFilter.cs index 287fad4..cbd2c16 100644 --- a/TimberWinR/Filters/GrokFilter.cs +++ b/TimberWinR/Filters/GrokFilter.cs @@ -13,11 +13,11 @@ namespace TimberWinR.Filters { public string Match { get; private set; } public string Field { get; private set; } - public TimberWinR.Configuration.Pair AddField { get; private set; } + public Pair AddField { get; private set; } public bool DropIfMatch { get; private set; } public string RemoveField { get; private set; } - public GrokFilter(TimberWinR.Configuration.Params_Grok args) + public GrokFilter(Params_GrokFilter args) { Match = args.Match; Field = args.Field; @@ -29,7 +29,7 @@ namespace TimberWinR.Filters public override string ToString() { StringBuilder sb = new StringBuilder(); - sb.Append("Grok\n"); + sb.Append("GrokFilter\n"); foreach (var prop in this.GetType().GetProperties()) { if (prop != null) @@ -84,5 +84,83 @@ namespace TimberWinR.Filters } } } + + + public struct Pair + { + public readonly string Name, Value; + + public Pair(string name, string value) + { + Name = name; + Value = value; + } + + public override string ToString() + { + return String.Format("Name:= {0} , Value:= {1}", Name, Value); + } + } + + public class Params_GrokFilter + { + public string Match { get; private set; } + public string Field { get; private set; } + public Pair AddField { get; private set; } + public bool DropIfMatch { get; private set; } + public string RemoveField { get; private set; } + + public class Builder + { + private string match; + private string field; + private Pair addField; + private bool dropIfMatch = false; + private string removeField; + + public Builder WithField(string value) + { + field = value; + return this; + } + + public Builder WithMatch(string value) + { + match = value; + return this; + } + + public Builder WithAddField(Pair value) + { + addField = value; + return this; + } + + public Builder WithDropIfMatch(bool value) + { + dropIfMatch = value; + return this; + } + + public Builder WithRemoveField(string value) + { + removeField = value; + return this; + } + + public Params_GrokFilter Build() + { + return new Params_GrokFilter() + { + Match = match, + Field = field, + AddField = addField, + DropIfMatch = dropIfMatch, + RemoveField = removeField + }; + } + + } + } } } \ No newline at end of file