<commit_before>input {
#	file {
#    	path => ["C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.30\bin\logs\server.log"]  
#		start_position => "beginning"
#		add_field => { "source" => "Monitoring.RestFacade" }
#	}

	udp {
		port => 17651
		add_field => { "source" => "Performance.InfinniPlatform" }
		add_field => { "layer" => "InfinniPlatform" }
		add_field => { "monitoring" => "Performance" }
	}

	udp {
		port => 17652
		add_field => { "source" => "Events.InfinniPlatform" }
		add_field => { "layer" => "InfinniPlatform" }
		add_field => { "monitoring" => "Events" }
	}	
}

filter {
	if [monitoring] == "Events" {
		grok {
			match => [ "message", "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}\s+%{NOTSPACE:thread}\s+%{NOTSPACE:logger}\s+\[R:%{NOTSPACE:requestId}\s+S:%{NOTSPACE:sessionId}\s+%{NOTSPACE:userId}\s+%{WORD:userName}\] %{GREEDYDATA:body}" ]
		}

#		if [level] =~ /(?i)trace/ { 
#			drop {} 
#		} else if [level] =~ /(?i)debug/ { 
#			drop {}
#		} else {
			json {
				source => "body"
			}

			mutate {
				remove_field => [ "message", "body" ]		
			}
#		}
	}

	if [monitoring] == "Performance" {
		grok {
			patterns_dir => "./patterns"
			match => [ "message", "%{TIMESTAMP_ISO8601:timestamp} %{NOTSPACE:correlationId} %{WORD:component} %{NOTSPACE:userId} %{WORD:userName} %{NOTSPACE:action} %{NONNEGINT:duration} %{GREEDYDATA:result}" ]
		}

		if "_grokparsefailure" in [tags] { drop {} }

		mutate {
			convert => [ "duration", "integer" ]
			add_field => { "qualifiedAction" => "%{component}.%{action}" }
		}

		if [result] =~ "\<null\>" {
			mutate {
				remove_field => [ "result" ]
			}
		}
		
		if [correlationId] =~ "\<null\>" {
			mutate {
				remove_field => [ "correlationId" ]
			}
		}
		
		mutate {
			remove_field => [ "message" ]
		}
	}
}

output {
  elasticsearch { hosts => ["localhost:9200"] }
}<commit_msg>Fix (null) username handling in logstash<commit_after>input {
#	file {
#    	path => ["C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.30\bin\logs\server.log"]
#		start_position => "beginning"
#		add_field => { "source" => "Monitoring.RestFacade" }
#	}

	udp {
		port => 17651
		add_field => { "source" => "Performance.InfinniPlatform" }
		add_field => { "layer" => "InfinniPlatform" }
		add_field => { "monitoring" => "Performance" }
	}

	udp {
		port => 17652
		add_field => { "source" => "Events.InfinniPlatform" }
		add_field => { "layer" => "InfinniPlatform" }
		add_field => { "monitoring" => "Events" }
	}
}

filter {
	if [monitoring] == "Events" {
		grok {
			match => [ "message", "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}\s+%{NOTSPACE:thread}\s+%{NOTSPACE:logger}\s+\[R:%{NOTSPACE:requestId}\s+S:%{NOTSPACE:sessionId}\s+%{NOTSPACE:userId}\s+%{NOTSPACE:userName}\] %{GREEDYDATA:body}" ]
		}

#		if [level] =~ /(?i)trace/ {
#			drop {}
#		} else if [level] =~ /(?i)debug/ {
#			drop {}
#		} else {
			json {
				source => "body"
			}

			mutate {
				remove_field => [ "message", "body" ]
			}
#		}
	}

	if [monitoring] == "Performance" {
		grok {
			patterns_dir => "./patterns"
			match => [ "message", "%{TIMESTAMP_ISO8601:timestamp} %{NOTSPACE:correlationId} %{WORD:component} %{NOTSPACE:userId} %{NOTSPACE:userName} %{NOTSPACE:action} %{NONNEGINT:duration} %{GREEDYDATA:result}" ]
		}

		if "_grokparsefailure" in [tags] { drop {} }

		mutate {
			convert => [ "duration", "integer" ]
			add_field => { "qualifiedAction" => "%{component}.%{action}" }
		}

		if [result] =~ "\<null\>" {
			mutate {
				remove_field => [ "result" ]
			}
		}

		if [correlationId] =~ "\<null\>" {
			mutate {
				remove_field => [ "correlationId" ]
			}
		}

		mutate {
			remove_field => [ "message" ]
		}
	}
}

output {
  elasticsearch { hosts => ["localhost:9200"] }
}
{'fraction_non_alphanumeric': 0.2100773127166089, 'fraction_numerical': 0.01386296987470008, 'mean_word_length': 3.542372881355932, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4716580', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1478, 'n_words': 225}