Created
March 13, 2019 02:38
-
-
Save webmat/9e41c4deb63cc06ec01b71515e6a58a4 to your computer and use it in GitHub Desktop.
Script to list all fields in Logstash grok patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PATTERNS_GLOB = ENV['PATTERNS_GLOB'] || '~/work/elastic/plugins/logstash-patterns-core/patterns/*' | |
FIELD_MATCHER = /{\w+:([^}]+)}/ | |
ECS = %w(labels agent client cloud container destination ecs error event file | |
geo group host http log network observer organization os process | |
related server service source url user user_agent) | |
field_names = {} | |
puts "File name\tField\tLine\tPosition\tConflict" | |
Dir[PATTERNS_GLOB].each do |file| | |
file_name = File.basename(file) | |
File.open(file) do |f| | |
f.readlines.each_with_index do |line, lineno| | |
line.scan(FIELD_MATCHER).each_with_index do |match, matchno| | |
match = match[0] | |
conflict = ECS.any? { |e| e == match } | |
puts "#{file_name}\t#{match}\t#{lineno}\t#{matchno}\t#{conflict}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment