mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Improve apache common format example
This commit is contained in:
parent
c100edcaf0
commit
a284ef8f00
2 changed files with 38 additions and 8 deletions
|
@ -13,6 +13,16 @@ describe "apache common log format" do
|
|||
sample '198.151.8.4 - - [29/Aug/2012:20:17:38 -0400] "GET /favicon.ico HTTP/1.1" 200 3638 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1"' do
|
||||
it "should not have tag _grokparsefailure" do
|
||||
reject { subject["@tags"] }.include?("_grokparsefailure")
|
||||
insist { subject }.include?("agent")
|
||||
insist { subject }.include?("bytes")
|
||||
insist { subject }.include?("clientip")
|
||||
insist { subject }.include?("httpversion")
|
||||
insist { subject }.include?("timestamp")
|
||||
insist { subject }.include?("verb")
|
||||
insist { subject }.include?("response")
|
||||
insist { subject }.include?("request")
|
||||
|
||||
insist { subject["clientip"] } == "198.151.8.4"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,41 @@
|
|||
require "insist"
|
||||
require "logstash/agent"
|
||||
require "logstash/event"
|
||||
|
||||
module LogStash
|
||||
module RSpec
|
||||
if ENV["DEBUG"]
|
||||
require "cabin"
|
||||
Cabin::Channel.get.level = :debug
|
||||
end
|
||||
|
||||
def config(configstr)
|
||||
require "logstash/config/file"
|
||||
@config = LogStash::Config::File.new(nil, configstr)
|
||||
config = LogStash::Config::File.new(nil, configstr)
|
||||
agent = LogStash::Agent.new
|
||||
@inputs, @filters, @outputs = agent.instance_eval { parse_config(config) }
|
||||
|
||||
[@inputs, @filters, @outputs].flatten.each do |plugin|
|
||||
plugin.register
|
||||
end
|
||||
end # def config
|
||||
|
||||
def sample(event, &block)
|
||||
subject do
|
||||
{
|
||||
"foo" => "bar",
|
||||
"@tags" => [ "foo" ]
|
||||
}
|
||||
filters = @filters
|
||||
describe event do
|
||||
if event.is_a?(String)
|
||||
subject { LogStash::Event.new("@message" => [event]) }
|
||||
else
|
||||
subject { LogStash::Event.new(event) }
|
||||
end
|
||||
|
||||
before :all do
|
||||
filters.each do |filter|
|
||||
filter.filter(subject)
|
||||
end
|
||||
end
|
||||
context("after processing", &block)
|
||||
end
|
||||
context("when processing #{event.inspect}", &block)
|
||||
end # def sample
|
||||
end # module RSpec
|
||||
end # module LogStash
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue