#!/usr/bin/env ruby require "rubygems" require "optparse" $:.unshift "#{File.dirname(__FILE__)}/../lib" $:.unshift "#{File.dirname(__FILE__)}/../test" #require "logstash/test_syntax" #require "logstash/filters/test_date" #require "logstash/filters/test_multiline" def check_lib(lib, provider, optional=true, message=nil) begin require lib puts "+ Found #{optional ? "optional" : "required"} library '#{lib}'" return { :optional => optional, :found => true } rescue LoadError => e puts "- Missing #{optional ? "optional" : "required"} library '#{lib}' - try 'gem install #{provider}'#{optional ? " if you want this library" : ""}. #{message}" return { :optional => optional, :found => false } end end def report_ruby_version puts "Running #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} on #{RUBY_PLATFORM}" end def check_libraries results = [] results << check_lib("em-http-request", "em-http-request", true, "needed for ElasticSearch input, output, and logstash-web support.") results << check_lib("em-mongo", "em-mongo", true, "needed for the mongodb output.") results << check_lib("grok", "jls-grok", true, "needed for the grok filter.") results << check_lib("em-websocket", "em-websocket", true, "needed for websocket output") results << check_lib("rack", "rack", true, "needed for logstash-web") results << check_lib("amqp", "amqp", true, "needed for AMQP input and output") results << check_lib("sinatra/async", "async_sinatra", true, "needed for logstash-web") results << check_lib("uuidtools", "uuidtools", true, "needed for AMQP input and output") results << check_lib("ap", "awesome_print", true, "improve logstash debug logging output") results << check_lib("eventmachine", "eventmachine", false, "required for logstash to function") missing_required = results.count { |r| !r[:optional] and !r[:found] } if missing_required == 0 puts "All required libraries found :)" else suffix = (missing_required > 1) ? "ies" : "y" puts "FATAL: Missing #{missing_required} required librar#{suffix}" return false end return true end def run_tests require "#{File.dirname(__FILE__)}/../test/run" return Test::Unit::AutoRunner.run end def main(args) report_ruby_version if !check_libraries puts "Library check failed." return 1 end if !run_tests puts "Test suite failed." return 1 end return 0 end exit(main(ARGV))