Grok RSpec 测试失败
Grok RSpec test failing
我正在尝试让 grok 与 logstash 一起工作,但努力下车。我试图将事情简化为这里的简洁测试:
require "test_utils"
describe "basic grokking" do
extend LogStash::RSpec
config <<-CONFIG
filter {
grok {
match => [ "message", "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" ]
}
}
CONFIG
sample ({'@message' => '55.3.244.1 GET /index.html 15824 0.043'}) do
puts subject.inspect # view http://www.codeshare.io/OhDC0
insist { subject["client"] } == "55.3.244.1"
end
end
我收到以下错误:
1) basic grokking "{"@message":"55.3.244.1 GET /index.html 15824 0.043..." when processed
Failure/Error: Unable to find matching line from backtrace
Insist::Failure:
Expected "55.3.244.1", but got nil
再多的语法调整都没有结果,而且我也不知道如何检查 subject
以找出其中的内容。
最终目的是用grok提取如下HttpRequestId
:
[HttpRequestId = e29041b2-a4a0-4bf3-ba05-2de5e7bcf444] 2015/04/10 08:12:51:632 [DEBUG] ... log message ...
使用这样的东西:
grok {
match => [ "Message", "\[HttpRequestId = %{UUID:HttpRequestId}" ]
}
注意 我已经根据 https://grokdebug.herokuapp.com/ 检查了我的模式并且它们有效。这与我测试的方式有关。
经过广泛调查,这里是 logstash 1.4.2 的 grok 表达式的最小 rspec 测试:
# encoding: utf-8
require "test_utils"
describe "simple test" do
extend LogStash::RSpec
config <<-CONFIG
filter {
grok {
match => { "message" => "am%{GREEDYDATA:foo}" }
}
}
CONFIG
sample 'amessage' do
insist { subject["foo"] } == "essage"
insist { subject["message"] } == "amessage"
end
end
请注意,您必须有 # encoding ...
行,否则您会收到 Expected "essage", but got nil
消息。
此邮件列表消息有帮助:https://groups.google.com/d/msg/logstash-users/rs6jlAxv36M/1ylU-GJ-DVQJ
我正在尝试让 grok 与 logstash 一起工作,但努力下车。我试图将事情简化为这里的简洁测试:
require "test_utils"
describe "basic grokking" do
extend LogStash::RSpec
config <<-CONFIG
filter {
grok {
match => [ "message", "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" ]
}
}
CONFIG
sample ({'@message' => '55.3.244.1 GET /index.html 15824 0.043'}) do
puts subject.inspect # view http://www.codeshare.io/OhDC0
insist { subject["client"] } == "55.3.244.1"
end
end
我收到以下错误:
1) basic grokking "{"@message":"55.3.244.1 GET /index.html 15824 0.043..." when processed
Failure/Error: Unable to find matching line from backtrace
Insist::Failure:
Expected "55.3.244.1", but got nil
再多的语法调整都没有结果,而且我也不知道如何检查 subject
以找出其中的内容。
最终目的是用grok提取如下HttpRequestId
:
[HttpRequestId = e29041b2-a4a0-4bf3-ba05-2de5e7bcf444] 2015/04/10 08:12:51:632 [DEBUG] ... log message ...
使用这样的东西:
grok {
match => [ "Message", "\[HttpRequestId = %{UUID:HttpRequestId}" ]
}
注意 我已经根据 https://grokdebug.herokuapp.com/ 检查了我的模式并且它们有效。这与我测试的方式有关。
经过广泛调查,这里是 logstash 1.4.2 的 grok 表达式的最小 rspec 测试:
# encoding: utf-8
require "test_utils"
describe "simple test" do
extend LogStash::RSpec
config <<-CONFIG
filter {
grok {
match => { "message" => "am%{GREEDYDATA:foo}" }
}
}
CONFIG
sample 'amessage' do
insist { subject["foo"] } == "essage"
insist { subject["message"] } == "amessage"
end
end
请注意,您必须有 # encoding ...
行,否则您会收到 Expected "essage", but got nil
消息。
此邮件列表消息有帮助:https://groups.google.com/d/msg/logstash-users/rs6jlAxv36M/1ylU-GJ-DVQJ