Implemented DateFilter.cs

This commit is contained in:
Jonathan Preddy
2014-07-22 11:42:22 -04:00
parent b15f36d33c
commit fa9de3cfef
3 changed files with 161 additions and 81 deletions

View File

@@ -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<XElement> elements)
static TimberWinR.Filters.GrokFilter.Params_Grok parseParams_Grok(IEnumerable<XElement> 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
};
}
}
}
}
}

View File

@@ -12,9 +12,84 @@ namespace TimberWinR.Filters
public bool ConvertToUTC { get; private set; }
public List<string> 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<string> Pattern { get; private set; }
public class Builder
{
private string field;
private string target;
private bool convertToUTC = false;
private List<string> 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
};
}
}
}
}
}

View File

@@ -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
};
}
}
}
}
}