1 Tips:Testing your filters
Aaron Mildenstein edited this page 2014-05-28 12:10:51 -07:00

Testing

You can write tests now for your logstash configs:

You can find examples in the 'spec' directory, such as this example for parsing apache logs:

https://github.com/elasticsearch/logstash/blob/master/spec/examples/parse-apache-logs.rb

Here's a basic stub:

require "test_utils"

describe "apache common log format" do
  extend LogStash::RSpec

  config %q{
    # Your logstash filter config here
  }

  sample "some sample log event here" do
    # Here, 'subject' is the event. You can make assertions about it.
    insist { subject["somefield"] } == "some sample"
  end
end

Save it as something.rb, then you can run the test with the 'rspec' command in logstash (substituting your own spec file for the one below):

% bin/logstash rspec spec/examples/parse-apache-logs.rb
...

Finished in 0.066 seconds
3 examples, 0 failures