Fixed problem with WindowsEvent Files and wildcards.
This commit is contained in:
@@ -54,7 +54,7 @@ TimberWinR reads a JSON configuration file, an example file is shown here:
|
||||
"Filters": [
|
||||
{
|
||||
"grok": {
|
||||
"condition": "[type] == \"Win32-Eventlog\"",
|
||||
"condition": "\"[type]\" == \"Win32-Eventlog\"",
|
||||
"match": [
|
||||
"Message",
|
||||
""
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"Filters": [
|
||||
{
|
||||
"grok": {
|
||||
"condition": "[type] == \"Win32-Eventlog\"",
|
||||
"condition": "\"[type]\" == \"Win32-Eventlog\"",
|
||||
"match": [
|
||||
"Message",
|
||||
""
|
||||
@@ -63,7 +63,7 @@
|
||||
},
|
||||
{
|
||||
"date": {
|
||||
"condition": "[type] == \"Win32-FileLog\"",
|
||||
"condition": "\"[type]\" == \"Win32-FileLog\"",
|
||||
"match": [
|
||||
"timestamp",
|
||||
"MMM d HH:mm:sss",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"Inputs": {
|
||||
"WindowsEvents": [
|
||||
{
|
||||
"source": "Application",
|
||||
"source": "Application,System",
|
||||
"binaryFormat": "PRINT",
|
||||
"resolveSIDS": true
|
||||
}
|
||||
@@ -15,13 +15,25 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"Filters":[
|
||||
{
|
||||
"grok":{
|
||||
"condition": "[EventTypeName] == \"Information Event\"",
|
||||
"match":[
|
||||
"Text",
|
||||
""
|
||||
],
|
||||
"drop": "true"
|
||||
}
|
||||
}]
|
||||
},
|
||||
"Outputs": {
|
||||
"Redis": [
|
||||
{
|
||||
"_comment": "Change the host to your Redis instance",
|
||||
"port": 6379,
|
||||
"host": [
|
||||
"tstlexiceapp006.vistaprint.svc"
|
||||
"logaggregator.vistaprint.svc"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -79,7 +79,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -129,7 +129,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -147,7 +147,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type].Contains(\""Win32-FileLog\"")"",
|
||||
""condition"": ""\""[type]\"".Contains(\""Win32-FileLog\"")"",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -166,7 +166,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type].Contains(\""Win32-Filelog\"")"",
|
||||
""condition"": ""\""[type]\"".Contains(\""Win32-Filelog\"")"",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -217,7 +217,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -248,7 +248,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -274,7 +274,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -300,7 +300,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
@@ -330,7 +330,7 @@ namespace TimberWinR.UnitTests
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""condition"": ""\""[type]\"" == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace TimberWinR.Parser
|
||||
|
||||
if (Matches(json))
|
||||
{
|
||||
if (DropIfMatch)
|
||||
return false;
|
||||
|
||||
AddFields(json);
|
||||
AddTags(json);
|
||||
RemoveFields(json);
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace TimberWinR.Inputs
|
||||
|
||||
LogManager.GetCurrentClassLogger().Info("WindowsEvent Input Listener Ready");
|
||||
|
||||
|
||||
// Instantiate the Event Log Input Format object
|
||||
var iFmt = new EventLogInputFormat()
|
||||
{
|
||||
@@ -82,21 +83,40 @@ namespace TimberWinR.Inputs
|
||||
resolveSIDs = _arguments.ResolveSIDS
|
||||
};
|
||||
|
||||
var qcount = string.Format("SELECT max(RecordNumber) as MaxRecordNumber FROM {0}", location);
|
||||
var rcount = oLogQuery.Execute(qcount, iFmt);
|
||||
var qr = rcount.getRecord();
|
||||
var lastRecordNumber = qr.getValueEx("MaxRecordNumber");
|
||||
|
||||
oLogQuery = null;
|
||||
|
||||
Dictionary<string, Int64> logFileMaxRecords = new Dictionary<string, Int64>();
|
||||
|
||||
|
||||
// Execute the query
|
||||
while (!CancelToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
oLogQuery = new LogQuery();
|
||||
|
||||
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
|
||||
|
||||
oLogQuery = new LogQuery();
|
||||
var qfiles = string.Format("SELECT Distinct [EventLog] FROM {0}", location);
|
||||
var rsfiles = oLogQuery.Execute(qfiles, iFmt);
|
||||
for (; !rsfiles.atEnd(); rsfiles.moveNext())
|
||||
{
|
||||
var record = rsfiles.getRecord();
|
||||
string logName = record.getValue("EventLog") as string;
|
||||
if (!logFileMaxRecords.ContainsKey(logName))
|
||||
{
|
||||
var qcount = string.Format("SELECT max(RecordNumber) as MaxRecordNumber FROM {0}", logName);
|
||||
var rcount = oLogQuery.Execute(qcount, iFmt);
|
||||
var qr = rcount.getRecord();
|
||||
var lrn = (Int64)qr.getValueEx("MaxRecordNumber");
|
||||
logFileMaxRecords[logName] = lrn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (string fileName in logFileMaxRecords.Keys.ToList())
|
||||
{
|
||||
var lastRecordNumber = logFileMaxRecords[fileName];
|
||||
var query = string.Format("SELECT * FROM {0} where RecordNumber > {1}", location, lastRecordNumber);
|
||||
|
||||
var rs = oLogQuery.Execute(query, iFmt);
|
||||
@@ -114,7 +134,8 @@ namespace TimberWinR.Inputs
|
||||
json.Add(new JProperty(field.Name, v));
|
||||
}
|
||||
|
||||
lastRecordNumber = record.getValueEx("RecordNumber");
|
||||
var lrn = (Int64)record.getValueEx("RecordNumber");
|
||||
logFileMaxRecords[fileName] = lrn;
|
||||
|
||||
record = null;
|
||||
ProcessJson(json);
|
||||
@@ -126,6 +147,7 @@ namespace TimberWinR.Inputs
|
||||
rs.close();
|
||||
rs = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.GetCurrentClassLogger().Error(ex);
|
||||
|
||||
@@ -124,7 +124,10 @@ namespace TimberWinR.Outputs
|
||||
protected override void MessageReceivedHandler(JObject jsonMessage)
|
||||
{
|
||||
if (_manager.Config.Filters != null)
|
||||
ApplyFilters(jsonMessage);
|
||||
{
|
||||
if (ApplyFilters(jsonMessage))
|
||||
return;
|
||||
}
|
||||
|
||||
var message = jsonMessage.ToString();
|
||||
LogManager.GetCurrentClassLogger().Debug(message);
|
||||
@@ -135,13 +138,19 @@ namespace TimberWinR.Outputs
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyFilters(JObject json)
|
||||
private bool ApplyFilters(JObject json)
|
||||
{
|
||||
bool drop = false;
|
||||
foreach (var filter in _manager.Config.Filters)
|
||||
{
|
||||
filter.Apply(json);
|
||||
if (!filter.Apply(json))
|
||||
{
|
||||
LogManager.GetCurrentClassLogger().Debug("Dropping: {0}", json.ToString());
|
||||
drop = true;
|
||||
}
|
||||
}
|
||||
return drop;
|
||||
}
|
||||
|
||||
//
|
||||
// Pull off messages from the Queue, batch them up and send them all across
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace TimberWinR.Parser
|
||||
|
||||
IList<string> keys = json.Properties().Select(p => p.Name).ToList();
|
||||
foreach (string key in keys)
|
||||
cond = cond.Replace(string.Format("[{0}]", key), string.Format("\"{0}\"", json[key].ToString()));
|
||||
cond = cond.Replace(string.Format("[{0}]", key), string.Format("{0}", json[key].ToString()));
|
||||
|
||||
var compiler = new CSharpCodeProvider();
|
||||
|
||||
@@ -511,7 +511,7 @@ namespace TimberWinR.Parser
|
||||
[JsonProperty("condition")]
|
||||
public string Condition { get; set; }
|
||||
|
||||
[JsonProperty("drop_if_match")]
|
||||
[JsonProperty("drop")]
|
||||
public bool DropIfMatch { get; set; }
|
||||
|
||||
[JsonProperty("match")]
|
||||
|
||||
@@ -34,7 +34,7 @@ Given this configuration
|
||||
"Filters": [
|
||||
{
|
||||
"date": {
|
||||
"condition": "[type] == \"Win32-FileLog\"",
|
||||
"condition": "\"[type]\" == \"Win32-FileLog\"",
|
||||
"match": [
|
||||
"timestamp",
|
||||
"MMM d HH:mm:sss",
|
||||
@@ -56,7 +56,7 @@ then the operation(s) will be executed in order.
|
||||
"Filters": [
|
||||
{
|
||||
"grok": {
|
||||
"condition": "[type] == \"Win32-EventLog\""
|
||||
"condition": "\"[type]\" == \"Win32-EventLog\""
|
||||
"add_field": [
|
||||
"ComputerName", "%{Host}"
|
||||
]
|
||||
@@ -72,7 +72,7 @@ The fields must be in pairs with fieldName first and value second.
|
||||
"Filters": [
|
||||
{
|
||||
"date": {
|
||||
"condition": "[type] == \"Win32-FileLog\"",
|
||||
"condition": "\"[type]\" == \"Win32-FileLog\"",
|
||||
"match": [
|
||||
"timestamp",
|
||||
"MMM d HH:mm:sss",
|
||||
@@ -92,7 +92,7 @@ If true and the filter matches, the time parsed will be converted to UTC
|
||||
"Filters": [
|
||||
{
|
||||
"date": {
|
||||
"condition": "[type] == \"Win32-FileLog\"",
|
||||
"condition": "\"[type]\" == \"Win32-FileLog\"",
|
||||
"match": [
|
||||
"timestamp",
|
||||
"MMM d HH:mm:sss",
|
||||
|
||||
@@ -12,7 +12,7 @@ Example Input:
|
||||
"Filters": [
|
||||
{
|
||||
"grok": {
|
||||
"condition": "[type] == \"Win32-Eventlog\"",
|
||||
"condition": "\"[type]\" == \"Win32-Eventlog\"",
|
||||
"match": [
|
||||
"Message",
|
||||
""
|
||||
@@ -35,7 +35,7 @@ Example Input:
|
||||
},
|
||||
{
|
||||
"date": {
|
||||
"condition": "[type] == \"Win32-FileLog\"",
|
||||
"condition": "\"[type]\" == \"Win32-FileLog\"",
|
||||
"match": [
|
||||
"timestamp",
|
||||
"MMM d HH:mm:sss",
|
||||
|
||||
@@ -83,7 +83,7 @@ then the operation(s) will be executed in order.
|
||||
"Filters": [
|
||||
{
|
||||
"grok": {
|
||||
"condition": "[type] == \"Win32-EventLog\""
|
||||
"condition": "\"[type]\" == \"Win32-EventLog\""
|
||||
"add_field": [
|
||||
"ComputerName", "%{Host}"
|
||||
]
|
||||
|
||||
@@ -20,7 +20,7 @@ then the operation(s) will be executed in order.
|
||||
"Filters": [
|
||||
{
|
||||
"mutate": {
|
||||
"condition": "[type] == \"Win32-EventLog\""
|
||||
"condition": "\"[type]\" == \"Win32-EventLog\""
|
||||
"rename": [
|
||||
"ComputerName", "Host"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user