From this blog :
$ git clone https://github.com/elastic/logstash
$ cd logstash
$ git checkout 2.1
$ rake bootstrap
$ rake test:install-core
Instead of checking branch 2.1, you should probably check the marked version of logstash that you are actually running, for example. v2.3.2 (note the "v").
After executing the above commands, you can run bin/rspec /some/path/your_filter_spec.rblogstash in the repository.
It is important . I found that an encoding string is required # encoding: utf-8, otherwise the match will fail.
Sample test file:
require "spec_helper"
describe "simple request log" do
config (<<-CONFIG)
filter {
grok {
match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
}
}
CONFIG
sample '55.3.244.1 GET /index.html 15824 0.043' do
insist { subject['client'] } == '55.3.244.1'
insist { subject['method'] } == 'GET'
insist { subject['request'] } == '/index.html'
insist { subject['bytes'] } == '15824'
insist { subject['duration'] } == '0.043'
end
end
source
share