Converted Filters to FilterBase class

This commit is contained in:
Eric Fontana
2014-07-22 10:56:22 -04:00
parent 613faaf49f
commit dc08f8c6bb
7 changed files with 89 additions and 57 deletions

View File

@@ -15,26 +15,12 @@
<Filters>
<Grok>
<!--Single Tag-->
<Match field="Text" value="%{SYSLOGLINE}" />
<DropIfMatch value="true" />
<!--Multiple Tag allowed -->
<AddField name="field1" value="%{foo}" />
<AddField name="field2" value="%{foo}" />
<RemoveField value="ip1" />
<RemoveField value="ip2" />
<!--Verify field 'name' is unique also target unique -->
<Date field="timestamp" target="@timestamp" convertToUTC="true">
<Pattern>MMM d HH:mm:ss</Pattern>
<Pattern>MMM dd HH:mm:ss</Pattern>
<Pattern>ISO8601</Pattern>
</Date>
<Date field="timestamp2" target="@timestamp2" convertToUTC="false">
<Pattern>MMM d HH:mm:ss</Pattern>
<Pattern>MMM dd HH:mm:ss</Pattern>
<Pattern>ISO8601</Pattern>
</Date>
<Match field="Text" value="%{SYSLOGLINE}" />
</Grok>
<Date field="timestamp" target="@timestamp" convertToUTC="true">
<Pattern>MMM d HH:mm:ss</Pattern>
<Pattern>MMM dd HH:mm:ss</Pattern>
<Pattern>ISO8601</Pattern>
</Date>
</Filters>
</TimberWinR>

View File

@@ -332,7 +332,7 @@ namespace TimberWinR.UnitTests
bool dropIfMatch = true;
string removeField = "ip1";
TimberWinR.Configuration.Grok grok = c.Groks.ToArray()[0];
TimberWinR.Filters.GrokFilter grok = c.Groks.ToArray()[0];
Assert.AreEqual(match, grok.Match);
Assert.AreEqual(addField, grok.AddField);

View File

@@ -8,6 +8,7 @@ using System.Xml.Linq;
using System.IO;
using System.Globalization;
using TimberWinR.Inputs;
using TimberWinR.Filters;
using System.Xml.Schema;
using NLog;
@@ -115,9 +116,9 @@ namespace TimberWinR
get { return _iisw3clogs; }
}
private static List<Grok> _groks = new List<Grok>();
private static List<GrokFilter> _groks = new List<GrokFilter>();
public IEnumerable<Grok> Groks
public IEnumerable<GrokFilter> Groks
{
get { return _groks; }
}
@@ -476,7 +477,7 @@ namespace TimberWinR
{
case "Grok":
Params_Grok args = parseParams_Grok(e.Elements());
Grok grok = new Grok(args);
GrokFilter grok = new GrokFilter(args);
_groks.Add(grok);
break;
case "Mutate":
@@ -1476,39 +1477,7 @@ namespace TimberWinR
}
}
public class 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 Grok(Params_Grok args)
{
Match = args.Match;
Field = args.Field;
AddField = args.AddField;
DropIfMatch = args.DropIfMatch;
RemoveField = args.RemoveField;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("Grok\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 class Params_Grok
{
public string Match { get; private set; }

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TimberWinR.Filters
{
public class DateFilter : FilterBase
{
public override void Apply(Newtonsoft.Json.Linq.JObject json)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
namespace TimberWinR.Filters
{
public abstract class FilterBase
{
public abstract void Apply(JObject json);
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TimberWinR.Filters
{
public class GrokFilter : FilterBase
{
public string Match { get; private set; }
public string Field { get; private set; }
public TimberWinR.Configuration.Pair AddField { get; private set; }
public bool DropIfMatch { get; private set; }
public string RemoveField { get; private set; }
public GrokFilter(TimberWinR.Configuration.Params_Grok args)
{
Match = args.Match;
Field = args.Field;
AddField = args.AddField;
DropIfMatch = args.DropIfMatch;
RemoveField = args.RemoveField;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("Grok\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();
}
}
}

View File

@@ -64,6 +64,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="Filters\DateFilter.cs" />
<Compile Include="Filters\FilterBase.cs" />
<Compile Include="Filters\GrokFilter.cs" />
<Compile Include="Inputs\FieldDefinitions.cs" />
<Compile Include="Inputs\IISW3CInputListener.cs" />
<Compile Include="Inputs\InputListener.cs" />