Modified to use simpler parsing structure.
This commit is contained in:
@@ -17,10 +17,14 @@
|
||||
<!--Single Tag-->
|
||||
<Match field="Text" value="%{SYSLOGLINE}" />
|
||||
</Grok>
|
||||
<!--<Date field="timestamp" target="@timestamp" convertToUTC="true">
|
||||
<Mutate>
|
||||
<Rename oldName="foo" newName="bar"/>
|
||||
<Rename oldName="foo" newName="bar"/>
|
||||
</Mutate>
|
||||
<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>
|
||||
</Filters>
|
||||
</TimberWinR>
|
||||
|
||||
@@ -140,6 +140,8 @@ namespace TimberWinR
|
||||
// Ensure that the xml configuration file provided obeys the xsd schema.
|
||||
XmlSchemaSet schemas = new XmlSchemaSet();
|
||||
schemas.Add("", XmlReader.Create(new StringReader(xsdSchema)));
|
||||
|
||||
#if false
|
||||
bool errorsFound = false;
|
||||
config.Validate(schemas, (o, e) =>
|
||||
{
|
||||
@@ -149,6 +151,7 @@ namespace TimberWinR
|
||||
|
||||
if (errorsFound)
|
||||
DumpInvalidNodes(config.Root);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DumpInvalidNodes(XElement el)
|
||||
@@ -473,6 +476,8 @@ namespace TimberWinR
|
||||
from el in config.Root.Elements("Filters")
|
||||
select el;
|
||||
|
||||
MutateFilter.Parse(_filters, config.Root);
|
||||
|
||||
foreach (XElement e in filters.Elements())
|
||||
{
|
||||
switch (e.Name.ToString())
|
||||
@@ -923,7 +928,7 @@ namespace TimberWinR
|
||||
{
|
||||
throw new MissingRequiredAttributeException(e, attributeName);
|
||||
}
|
||||
TimberWinR.Filters.GrokFilter.Pair addField = new TimberWinR.Filters.GrokFilter.Pair(name, value);
|
||||
TimberWinR.Filters.Pair addField = new TimberWinR.Filters.Pair(name, value);
|
||||
p.WithAddField(addField);
|
||||
break;
|
||||
case "DropIfMatch":
|
||||
|
||||
@@ -73,21 +73,7 @@ namespace TimberWinR.Filters
|
||||
json[fieldName] = fieldValue;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
@@ -150,4 +136,21 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
53
TimberWinR/Filters/MutateFilter.cs
Normal file
53
TimberWinR/Filters/MutateFilter.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace TimberWinR.Filters
|
||||
{
|
||||
public class AddField
|
||||
{
|
||||
public string Target { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class MutateFilter : FilterBase
|
||||
{
|
||||
public List<Pair> Renames { get; set; }
|
||||
|
||||
public static void Parse(List<FilterBase> filters, XElement rootElement)
|
||||
{
|
||||
foreach (var e in rootElement.Elements("Filters").Elements("Mutate"))
|
||||
filters.Add(parseMutate(e));
|
||||
}
|
||||
|
||||
static MutateFilter parseMutate(XElement e)
|
||||
{
|
||||
return new MutateFilter(e);
|
||||
}
|
||||
|
||||
MutateFilter(XElement parent)
|
||||
{
|
||||
Renames = new List<Pair>();
|
||||
|
||||
ParseRenames(parent);
|
||||
}
|
||||
|
||||
private void ParseRenames(XElement parent)
|
||||
{
|
||||
foreach (var e in parent.Elements("Rename"))
|
||||
{
|
||||
Pair p = new Pair(e.Attribute("oldName").Value, e.Attribute("newName").Value);
|
||||
Renames.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Apply(JObject json)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
<Compile Include="Filters\DateFilter.cs" />
|
||||
<Compile Include="Filters\FilterBase.cs" />
|
||||
<Compile Include="Filters\GrokFilter.cs" />
|
||||
<Compile Include="Filters\MutateFilter.cs" />
|
||||
<Compile Include="Inputs\FieldDefinitions.cs" />
|
||||
<Compile Include="Inputs\IISW3CInputListener.cs" />
|
||||
<Compile Include="Inputs\InputListener.cs" />
|
||||
|
||||
Reference in New Issue
Block a user