logstash在升级到7.13.3后出现语法错误

nhjlsmyf  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(564)

因此,我的公司让我将存储库的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版本在语法上接受的相同表达式。

iecba09b

iecba09b1#

错误是
char类中不匹配的范围说明符
在字符定义中,您可以定义字符范围,例如。 [a-z] . 在此处使用文字破折号字符时,必须小心转义它或确保它明确定义单个字符而不是范围。
在您的示例中,您可以在正则表达式中转义破折号,以确保破折号被视为单个可能的字符:

grok {
  match => { "message_string" => "(?<ucd_environment_name1>(?<=release_ucd_environment_name:)[\w\-.]*)" }
}

相关问题