diff --git a/TimberWinR.UnitTests/Configuration.cs b/TimberWinR.UnitTests/Configuration.cs index 9a12709..bc4fb14 100644 --- a/TimberWinR.UnitTests/Configuration.cs +++ b/TimberWinR.UnitTests/Configuration.cs @@ -8,6 +8,7 @@ using TimberWinR; using TimberWinR.Inputs; using TimberWinR.Filters; using Newtonsoft.Json.Linq; +using TimberWinR.Parser; namespace TimberWinR.UnitTests { @@ -69,7 +70,55 @@ namespace TimberWinR.UnitTests catch (TimberWinR.Parser.Grok.GrokAddTagException ex) { } - } + } + [Test] + public void TestRedisHostCount() + { + string redisJson = @"{ + ""TimberWinR"": + { + ""Outputs"": + { + ""Redis"": + [{ + ""host"": + [ + ""logaggregator.vistaprint.svc"" + ] + }] + } + } + }"; + + + Configuration c = Configuration.FromString(redisJson); + RedisOutput redis = c.RedisOutputs.First() as RedisOutput; + Assert.IsTrue(redis.Host.Length >= 1); + } + + [Test] + public void TestDateFilterMatchCount() + { + string dateJson = @"{ + ""TimberWinR"":{ + ""Filters"":[ + { + ""date"":{ + ""match"":[ + ""timestamp"", + ""MMM d HH:mm:sss"", + ""MMM dd HH:mm:ss"" + ], + } + }] + } + }"; + + + Configuration c = Configuration.FromString(dateJson); + DateFilter date = c.Filters.First() as DateFilter; + Assert.IsTrue(date.Match.Length >= 2); + } } } diff --git a/TimberWinR.UnitTests/GrokFilterTests.cs b/TimberWinR.UnitTests/GrokFilterTests.cs index a255fc3..8c25a51 100644 --- a/TimberWinR.UnitTests/GrokFilterTests.cs +++ b/TimberWinR.UnitTests/GrokFilterTests.cs @@ -179,7 +179,7 @@ namespace TimberWinR.UnitTests } }"; - // Postitive Tests + // Positive Tests Configuration c = Configuration.FromString(grokJson1); Grok grok = c.Filters.First() as Grok; Assert.IsTrue(grok.Apply(json)); @@ -239,5 +239,115 @@ namespace TimberWinR.UnitTests Assert.IsTrue(json["tags"].Children().Count() == 1); Assert.AreEqual(json["tags"][0].ToString(), "tag2"); } + + [Test] + public void TestMatchCount() + { + string grokJson = @"{ + ""TimberWinR"":{ + ""Filters"":[ + { + ""grok"":{ + ""condition"": ""[type] == \""Win32-FileLog\"""", + ""match"":[ + ""Text"", + """" + ], + ""remove_tag"":[ + ""tag1"" + ] + } + }] + } + }"; + + Configuration c = Configuration.FromString(grokJson); + Grok grok = c.Filters.First() as Grok; + Assert.AreEqual(2, grok.Match.Length); + } + + [Test] + public void TestRemoveFieldCount() + { + string grokJson = @"{ + ""TimberWinR"":{ + ""Filters"":[ + { + ""grok"":{ + ""condition"": ""[type] == \""Win32-FileLog\"""", + ""match"":[ + ""Text"", + """" + ], + ""remove_field"":[ + ""ComputerName"" + ] + } + }] + } + }"; + + Configuration c = Configuration.FromString(grokJson); + Grok grok = c.Filters.First() as Grok; + Assert.IsTrue(grok.RemoveField.Length >= 1); + } + + [Test] + public void TestAddFieldCount() + { + string grokJson = @"{ + ""TimberWinR"":{ + ""Filters"":[ + { + ""grok"":{ + ""condition"": ""[type] == \""Win32-FileLog\"""", + ""match"":[ + ""Text"", + """" + ], + ""remove_tag"":[ + ""tag1"" + ], + ""add_field"":[ + ""host"", + ""%{ComputerName}"" + ] + } + }] + } + }"; + + Configuration c = Configuration.FromString(grokJson); + Grok grok = c.Filters.First() as Grok; + Assert.IsTrue(grok.AddField.Length % 2 == 0); + } + + [Test] + public void TestAddTagCount() + { + string grokJson = @"{ + ""TimberWinR"":{ + ""Filters"":[ + { + ""grok"":{ + ""condition"": ""[type] == \""Win32-FileLog\"""", + ""match"":[ + ""Text"", + """" + ], + ""add_tag"":[ + ""rn_%{RecordNumber}"", + ""bar"" + ] + } + }] + } + }"; + + Configuration c = Configuration.FromString(grokJson); + Grok grok = c.Filters.First() as Grok; + Assert.IsTrue(grok.AddTag.Length >= 1); + } + } } diff --git a/TimberWinR/Configuration.cs b/TimberWinR/Configuration.cs index a7309fe..cb4c5c3 100644 --- a/TimberWinR/Configuration.cs +++ b/TimberWinR/Configuration.cs @@ -94,10 +94,15 @@ namespace TimberWinR c._events = x.TimberWinR.Inputs.WindowsEvents.ToList(); c._iisw3clogs = x.TimberWinR.Inputs.IISW3CLogs.ToList(); c._logs = x.TimberWinR.Inputs.Logs.ToList(); - c._redisOutputs = x.TimberWinR.Outputs.Redis.ToList(); + c._tcps = x.TimberWinR.Inputs.Tcps.ToList(); } + if (x.TimberWinR.Outputs != null) + { + c._redisOutputs = x.TimberWinR.Outputs.Redis.ToList(); + } + if (x.TimberWinR.Filters != null) c._filters = x.TimberWinR.AllFilters.ToList();