升级到 7.13.3 后 Logstash 出现语法错误
Logstash getting syntax errors after upgrading to 7.13.3
所以我的公司让我将存储库的 Logstash 版本从 6.6.2 升级到 7.13.3。
通过升级修复了其他一些错误后,似乎最后一步是更改配置文件中的 ruby 语法。
但是,我不太熟悉这种语言,也不确定为什么语法不再有效。
这是我们从文件中得到的语法错误之一的示例。
[2021-07-21T16:10:22,524][ERROR][logstash.javapipeline ][main] Pipeline error {
:pipeline_id=>"main",
:exception=>#<RegexpError: unmatched range specifier in char-class: /(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w-.]*)/m>,
:backtrace=>[
"org/jruby/RubyRegexp.java:965:in `initialize'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/jls-grok-0.11.5/lib/grok-pure.rb:127:in `compile'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:282:in `block in register'",
"org/jruby/RubyArray.java:1809:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:276:in `block in register'",
"org/jruby/RubyHash.java:1415:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:271:in `register'",
"org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:75:in `register'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:228:in `block in register_plugins'",
"org/jruby/RubyArray.java:1809:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:227:in `register_plugins'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:586:in `maybe_setup_out_plugins'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:240:in `start_workers'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:185:in `run'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:137:in `block in start'"
],
"pipeline.sources"=>["/Users/808451090/Desktop/app/logstash-7.13.3/devops-jenkins/jenkins.conf"],
:thread=>"#<Thread:0x4fbac51b run>"
}
此错误引用的行:
grok {
match => { "message_string" => "(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w-.]*)" }
}
还有其他行会发生此错误,但它们都具有与此行相似的语法,因此我确定我也可以对这些行应用相同的更改。
如果有人能告诉我如何更改此行以检查此 Logstash 版本在语法上接受的相同表达式。
错误是
unmatched range specifier in char-class
在字符定义中,您可以定义字符范围,例如[a-z]
。在那里使用文字破折号字符时,您必须小心将其转义或确保它明确定义单个字符而不是范围。
在您的示例中,您可以在正则表达式中转义破折号以确保破折号被视为一个可能的字符:
grok {
match => { "message_string" => "(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w\-.]*)" }
}
所以我的公司让我将存储库的 Logstash 版本从 6.6.2 升级到 7.13.3。
通过升级修复了其他一些错误后,似乎最后一步是更改配置文件中的 ruby 语法。
但是,我不太熟悉这种语言,也不确定为什么语法不再有效。
这是我们从文件中得到的语法错误之一的示例。
[2021-07-21T16:10:22,524][ERROR][logstash.javapipeline ][main] Pipeline error {
:pipeline_id=>"main",
:exception=>#<RegexpError: unmatched range specifier in char-class: /(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w-.]*)/m>,
:backtrace=>[
"org/jruby/RubyRegexp.java:965:in `initialize'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/jls-grok-0.11.5/lib/grok-pure.rb:127:in `compile'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:282:in `block in register'",
"org/jruby/RubyArray.java:1809:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:276:in `block in register'",
"org/jruby/RubyHash.java:1415:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/vendor/bundle/jruby/2.5.0/gems/logstash-filter-grok-4.4.0/lib/logstash/filters/grok.rb:271:in `register'",
"org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:75:in `register'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:228:in `block in register_plugins'",
"org/jruby/RubyArray.java:1809:in `each'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:227:in `register_plugins'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:586:in `maybe_setup_out_plugins'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:240:in `start_workers'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:185:in `run'",
"/Users/808451090/Desktop/app/logstash-7.13.3/logstash-core/lib/logstash/java_pipeline.rb:137:in `block in start'"
],
"pipeline.sources"=>["/Users/808451090/Desktop/app/logstash-7.13.3/devops-jenkins/jenkins.conf"],
:thread=>"#<Thread:0x4fbac51b run>"
}
此错误引用的行:
grok {
match => { "message_string" => "(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w-.]*)" }
}
还有其他行会发生此错误,但它们都具有与此行相似的语法,因此我确定我也可以对这些行应用相同的更改。
如果有人能告诉我如何更改此行以检查此 Logstash 版本在语法上接受的相同表达式。
错误是
unmatched range specifier in char-class
在字符定义中,您可以定义字符范围,例如[a-z]
。在那里使用文字破折号字符时,您必须小心将其转义或确保它明确定义单个字符而不是范围。
在您的示例中,您可以在正则表达式中转义破折号以确保破折号被视为一个可能的字符:
grok {
match => { "message_string" => "(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w\-.]*)" }
}