Removing jruby server and gemfiles

This commit is contained in:
Chris Cowan 2015-01-06 17:29:04 -07:00
parent 2410b60667
commit 26fed84187
21 changed files with 0 additions and 931 deletions

View file

@ -1,9 +0,0 @@
source "https://rubygems.org"
gem 'sinatra', :require => 'sinatra/base'
gem 'sinatra-contrib'
gem 'puma'
gem 'warbler'
gem 'elasticsearch'
gem 'rack-reverse-proxy', :require => 'rack/reverse_proxy'
gem 'colorize'

View file

@ -1,62 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
backports (3.6.0)
colorize (0.7.3)
elasticsearch (1.0.4)
elasticsearch-api (= 1.0.4)
elasticsearch-transport (= 1.0.4)
elasticsearch-api (1.0.4)
multi_json
elasticsearch-transport (1.0.4)
faraday
multi_json
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
jruby-jars (1.7.13)
jruby-rack (1.1.16)
multi_json (1.10.1)
multipart-post (2.0.0)
puma (2.9.0)
rack (>= 1.1, < 2.0)
puma (2.9.0-java)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-reverse-proxy (0.4.4)
rack (>= 1.0.0)
rack-test (0.6.2)
rack (>= 1.0)
rake (10.1.0)
rubyzip (1.1.6)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
tilt (1.4.1)
warbler (1.4.4)
jruby-jars (>= 1.5.6, < 2.0)
jruby-rack (>= 1.0.0)
rake (>= 0.9.6)
rubyzip (>= 0.9, < 1.2)
PLATFORMS
java
ruby
DEPENDENCIES
colorize
elasticsearch
puma
rack-reverse-proxy
sinatra
sinatra-contrib
warbler

View file

@ -1,19 +0,0 @@
# Kibana @@version
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elasticsearch.
## Installation
* Download: http://www.elasticsearch.org/overview/kibana/installation/
* Run **bin/kibana** on unix, or **bin/kibana.bat** on Windows.
* Visit http://localhost:5601
## Need Help?
Need help? Try #elasticsearch or #logstash on Freenode IRC. You can also find help on the elasticsearch-users@googlegroups.com or logstash-users@googlegroups.com mailing lists.
You can also find documentation at http://www.elasticsearch.com/guide/en/kibana/current
## Contributing
If you have a bugfix or new feature that you would like to contribute to Kibana, please find or open an issue about it first. Kibana is an open source project that is available on Github: https://github.com/elasticsearch/kibana

View file

@ -1,7 +0,0 @@
source "https://rubygems.org"
gem 'sinatra', :require => 'sinatra/base'
gem 'sinatra-contrib'
gem 'puma'
gem 'rack-reverse-proxy', :require => 'rack/reverse_proxy'
gem 'colorize'

View file

@ -1,40 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
backports (3.6.0)
colorize (0.7.3)
multi_json (1.10.1)
puma (2.9.0)
rack (>= 1.1, < 2.0)
puma (2.9.0-java)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-reverse-proxy (0.4.4)
rack (>= 1.0.0)
rack-test (0.6.2)
rack (>= 1.0)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
tilt (1.4.1)
PLATFORMS
java
ruby
DEPENDENCIES
colorize
puma
rack-reverse-proxy
sinatra
sinatra-contrib

View file

@ -1,97 +0,0 @@
#!/usr/bin/env ruby
require "optparse"
require 'rubygems'
require 'puma/cli'
require "yaml"
HERE = File.expand_path(File.dirname(__FILE__))
module Kibana
def self.global_settings
@settings ||= {}
end
end
# Defaults for the options
options = {
:config => ENV["CONFIG_PATH"] || File.expand_path("#{HERE}/../config/kibana.yml"),
:plugins_folder => ENV["PLUGINS_FOLDER"]
}
# Create a new parser
parser = OptionParser.new do |opts|
opts.on('-e', '--elasticsearch URI', 'Elasticsearch instance') do |arg|
options[:elasticsearch] = arg
end
opts.on('-c', '--config PATH', 'Path to config file') do |arg|
options[:config] = arg
end
opts.on('-p', '--port PORT', 'Kibana port') do |arg|
options[:port] = arg
end
opts.on('-q', '--quiet', 'Turns off logging') do |arg|
options[:quiet] = arg
end
opts.on('-H', '--host HOST', 'Kibana host') do |arg|
options[:host] = arg
end
opts.on('-v', '--version', 'Display version') do |arg|
puts ENV['KIBANA_VERSION'] || 'dev-build'
exit
end
opts.on('--plugins', 'Path to the folder to scan for plugins') do |arg|
options[:plugins_folder] = arg
end
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
# Set the usage banner
parser.banner = "Usage: kibana <options>\n\n"
# Parse the command line arguments
parser.parse! ARGV
# Load the config from default
config = YAML.load(IO.read(options[:config]))
# Set the override for the port
port = (options[:port] || config['port'])
# Set the override for the host
host = (options[:host] || config['host'])
# Set the override for Elasticsaerch
elasticsearch = (options[:elasticsearch] || config['elasticsearch'])
# If the env isn't set we need to set it to development
ENV["RACK_ENV"] = "development" if ENV["RACK_ENV"].nil?
# Set the global_settings that are shared across every app
Kibana.global_settings[:port] = port || 5601
Kibana.global_settings[:host] = host || '0.0.0.0'
Kibana.global_settings[:request_timeout] = config["request_timeout"].nil? ? 60 : config["request_timeout"]
Kibana.global_settings[:shard_timeout] = config["shard_timeout"].nil? ? 30000 : config["shard_timeout"]
Kibana.global_settings[:config] = config
Kibana.global_settings[:elasticsearch] = elasticsearch
Kibana.global_settings[:root] = File.expand_path("#{HERE}/../")
Kibana.global_settings[:quiet] = options[:quiet]
Kibana.global_settings[:external_plugins_folder] = options[:plugins_folder] || nil
# Set the public folder based on whether we are running in production or not.
if ENV['RACK_ENV'] == ('production')
Kibana.global_settings[:public_folder] = File.expand_path("#{HERE}/../public/")
Kibana.global_settings[:bundled_plugins_folder] = File.expand_path("#{HERE}/../public/plugins")
else
Kibana.global_settings[:public_folder] = File.expand_path("#{HERE}/../../kibana/")
Kibana.global_settings[:bundled_plugins_folder] = File.expand_path("#{HERE}/../../kibana/plugins")
end
# Add the root of the project to the load path
$LOAD_PATH.unshift(Kibana.global_settings[:root])
require "lib/server"
Kibana::Server.run(Kibana.global_settings)

View file

@ -1,26 +0,0 @@
@echo off
SETLOCAL
if not defined JAVA_HOME goto java_home_err
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI
set RACK_ENV=production
set CONFIG_PATH=%DIR%\config\kibana.yml
set PLUGINS_FOLDER=%DIR%\plugins
set KIBANA_VERSION=@@version
TITLE Kibana %KIBANA_VERSION%
"%JAVA_HOME%\bin\java" -jar "%DIR%\lib\kibana.jar" %*
:java_home_err
echo JAVA_HOME enviroment variable must be set!
pause
goto finally
:finally
ENDLOCAL

View file

@ -1,44 +0,0 @@
#!/bin/sh
SCRIPT=$0
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; do
ls=$(ls -ld "$SCRIPT")
# Drop everything prior to ->
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=$(dirname "$SCRIPT")/"$link"
fi
done
DIR=$(dirname "${SCRIPT}")
if [ -x "${JAVA_HOME}/bin/java" ]; then
JAVA="${JAVA_HOME}/bin/java"
else
JAVA=$(which java)
fi
if [ ! -x "${JAVA}" ]; then
echo "Could not find any executable Java binary. Please install Java in your PATH or set JAVA_HOME"
exit 1
fi
>&2 echo "The Kibana Backend is starting up... be patient"
JAVA_OPTS="-Xmx512m $JAVA_OPTS"
# Clear gem paths so that we only use the gems inside the kibana.jar
export GEM_HOME=
export GEM_PATH=
# shellcheck disable=SC2086
KIBANA_VERSION=@@version \
CONFIG_PATH=${DIR}/../config/kibana.yml \
PLUGINS_FOLDER=${DIR}/../plugins \
RACK_ENV=production \
exec "${JAVA}" \
$JAVA_OPTS \
-jar "${DIR}/../lib/kibana.jar" "$@"

View file

@ -1,37 +0,0 @@
# Kibana is served by a back end server. This controls which port to use.
port: 5601
# The host to bind the server to.
host: "0.0.0.0"
# The Elasticsearch instance to use for all your queries.
elasticsearch: "http://localhost:9200"
# If your Elasticsearch is protected with basic auth:
# elasticsearch_username: user
# elasticsearch_password: pass
# preserve_elasticsearch_host true will send the hostname specified in `elasticsearch`. If you set it to false,
# then the host you use to connect to *this* Kibana instance will be sent.
elasticsearch_preserve_host: true
# Kibana uses an index in Elasticsearch to store saved searches, visualizations
# and dashboards. It will create a new index if it doesn't already exist.
kibana_index: ".kibana"
# The default application to load.
default_app_id: "discover"
# Time in seconds to wait for responses from the back end or elasticsearch.
# Note this should always be higher than "shard_timeout".
# This must be > 0
request_timeout: 60
# Time in milliseconds for Elasticsearch to wait for responses from shards.
# Note this should always be lower than "request_timeout".
# Set to 0 to disable (not recommended).
shard_timeout: 30000
# Set to false to have a complete disregard for the validity of the SSL
# certificate.
verify_ssl: true

View file

@ -1,178 +0,0 @@
# Disable Rake-environment-task framework detection by uncommenting/setting to false
# Warbler.framework_detection = false
# Warbler web application assembly configuration file
Warbler::Config.new do |config|
# Features: additional options controlling how the jar is built.
# Currently the following features are supported:
# - gemjar: package the gem repository in a jar file in WEB-INF/lib
# - executable: embed a web server and make the war executable
# - compiled: compile .rb files to .class files
# config.features = %w(gemjar)
# Application directories to be included in the webapp.
config.dirs = %w(bin config routes lib public)
# Additional files/directories to include, above those in config.dirs
# config.includes = FileList["db"]
# Additional files/directories to exclude
# config.excludes = FileList["lib/tasks/*"]
# Additional Java .jar files to include. Note that if .jar files are placed
# in lib (and not otherwise excluded) then they need not be mentioned here.
# JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your
# own versions if you directly set the value
# config.java_libs += FileList["lib/java/*.jar"]
# Loose Java classes and miscellaneous files to be included.
# config.java_classes = FileList["target/classes/**.*"]
# One or more pathmaps defining how the java classes should be copied into
# the archive. The example pathmap below accompanies the java_classes
# configuration above. See http://rake.rubyforge.org/classes/String.html#M000017
# for details of how to specify a pathmap.
# config.pathmaps.java_classes << "%{target/classes/,}p"
# Bundler support is built-in. If Warbler finds a Gemfile in the
# project directory, it will be used to collect the gems to bundle
# in your application. If you wish to explicitly disable this
# functionality, uncomment here.
# config.bundler = false
# An array of Bundler groups to avoid including in the war file.
# Defaults to ["development", "test", "assets"].
# config.bundle_without = []
# Other gems to be included. If you don't use Bundler or a gemspec
# file, you need to tell Warbler which gems your application needs
# so that they can be packaged in the archive.
# For Rails applications, the Rails gems are included by default
# unless the vendor/rails directory is present.
# config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]
# config.gems << "tzinfo"
# config.gems << "sinatra"
# Uncomment this if you don't want to package rails gem.
# config.gems -= ["rails"]
# The most recent versions of gems are used.
# You can specify versions of gems by using a hash assignment:
# config.gems["rails"] = "2.3.10"
# You can also use regexps or Gem::Dependency objects for flexibility or
# finer-grained control.
# config.gems << /^merb-/
# config.gems << Gem::Dependency.new("merb-core", "= 0.9.3")
# Include gem dependencies not mentioned specifically. Default is
# true, uncomment to turn off.
# config.gem_dependencies = false
# Array of regular expressions matching relative paths in gems to be
# excluded from the war. Defaults to empty, but you can set it like
# below, which excludes test files.
# config.gem_excludes = [/^(test|spec)\//]
# Pathmaps for controlling how application files are copied into the archive
# config.pathmaps.application = ["WEB-INF/%p"]
# Name of the archive (without the extension). Defaults to the basename
# of the project directory.
config.jar_name = "kibana"
# Name of the MANIFEST.MF template for the war file. Defaults to a simple
# MANIFEST.MF that contains the version of Warbler used to create the war file.
# config.manifest_file = "config/MANIFEST.MF"
# When using the 'compiled' feature and specified, only these Ruby
# files will be compiled. Default is to compile all \.rb files in
# the application.
# config.compiled_ruby_files = FileList['app/**/*.rb']
# Determines if ruby files in supporting gems will be compiled.
# Ignored unless compile feature is used.
# config.compile_gems = false
# When set it specify the bytecode version for compiled class files
# config.bytecode_version = "1.6"
# When set to true, Warbler will override the value of ENV['GEM_HOME'] even it
# has already been set. When set to false it will use any existing value of
# GEM_HOME if it is set.
# config.override_gem_home = true
# Allows for specifing custom executables
# config.executable = ["rake", "bin/rake"]
# Sets default (prefixed) parameters for the executables
# config.executable_params = "do:something"
# If set to true, moves jar files into WEB-INF/lib. Prior to version 1.4.2 of Warbler this was done
# by default. But since 1.4.2 this config defaults to false. It may need to be set to true for
# web servers that do not explode the WAR file.
# Alternatively, this option can be set to a regular expression, which will
# act as a jar selector -- only jar files that match the pattern will be
# included in the archive.
# config.move_jars_to_webinf_lib = false
# === War files only below here ===
# Path to the pre-bundled gem directory inside the war file. Default
# is 'WEB-INF/gems'. Specify path if gems are already bundled
# before running Warbler. This also sets 'gem.path' inside web.xml.
# config.gem_path = "WEB-INF/vendor/bundler_gems"
# Files for WEB-INF directory (next to web.xml). This contains
# web.xml by default. If there is an .erb-File it will be processed
# with webxml-config. You may want to exclude this file via
# config.excludes.
# config.webinf_files += FileList["jboss-web.xml"]
# Files to be included in the root of the webapp. Note that files in public
# will have the leading 'public/' part of the path stripped during staging.
# config.public_html = FileList["public/**/*", "doc/**/*"]
# Pathmaps for controlling how public HTML files are copied into the .war
# config.pathmaps.public_html = ["%{public/,}p"]
# Embedded webserver to use with the 'executable' feature. Currently supported
# webservers are:
# * <tt>winstone</tt> (default) - Winstone 0.9.10 from sourceforge
# * <tt>jenkins-ci.winstone</tt> - Improved Winstone from Jenkins CI
# * <tt>jetty</tt> - Embedded Jetty from Eclipse
# config.webserver = 'jetty'
# Value of RAILS_ENV for the webapp -- default as shown below
# config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
# Application booter to use, one of :rack, :rails, or :merb (autodetected by default)
# config.webxml.booter = :rails
# Set JRuby to run in 1.9 mode.
# config.webxml.jruby.compat.version = "1.9"
# When using the :rack booter, "Rackup" script to use.
# - For 'rackup.path', the value points to the location of the rackup
# script in the web archive file. You need to make sure this file
# gets included in the war, possibly by adding it to config.includes
# or config.webinf_files above.
# - For 'rackup', the rackup script you provide as an inline string
# is simply embedded in web.xml.
# The script is evaluated in a Rack::Builder to load the application.
# Examples:
# config.webxml.rackup.path = 'WEB-INF/hello.ru'
# config.webxml.rackup = %{require './lib/demo'; run Rack::Adapter::Camping.new(Demo)}
# config.webxml.rackup = require 'cgi' && CGI::escapeHTML(File.read("config.ru"))
# Control the pool of Rails runtimes. Leaving unspecified means
# the pool will grow as needed to service requests. It is recommended
# that you fix these values when running a production server!
# If you're using threadsafe! mode, you probably don't want to set these values,
# since 1 runtime(default for threadsafe mode) will be enough.
# config.webxml.jruby.min.runtimes = 2
# config.webxml.jruby.max.runtimes = 4
# JNDI data source name
# config.webxml.jndi = 'jdbc/rails'
end

View file

@ -1,44 +0,0 @@
require "rack/commonlogger"
require "colorize"
class ColorLogger < Rack::CommonLogger
def log(env, status, header, begin_at)
now = Time.now
length = extract_content_length(header)
case status
when 300..399
statusColor = :yellow
when 400..499
statusColor = :red
when 500..599
statusColor = :magenta
else
statusColor = :green
end
msg = (now.strftime('%b %d, %Y @ %H:%M:%S.%L')).light_black << ' '
msg << env["REQUEST_METHOD"].light_blue << ' '
msg << env["PATH_INFO"]
msg << (env["QUERY_STRING"].empty? ? '' : "?#{env["QUERY_STRING"]}" ) << ' '
msg << status.to_s.send(statusColor) << ' '
msg << ((now - begin_at) * 1000).to_i.to_s << 'ms - ' << length
msg << "\n"
# If there is an error then we need to append the stack
if env['sinatra.error'] && status != 404
error = env['sinatra.error']
msg << "#{error.message}\n #{error.backtrace.join("\n ")}".send(statusColor)
msg << "\n"
end
logger = @logger || env['rack.errors']
if logger.respond_to?(:write)
logger.write(msg)
else
logger << msg
end
end
end

View file

@ -1,14 +0,0 @@
# This monkeypatch is needed to ensure the X-Frame-Options header is
# never set by rack-protection.
#
# http://stackoverflow.com/a/19232793/296172
#
module Rack
module Protection
class FrameOptions < Base
def call(env)
@app.call(env)
end
end
end
end

View file

@ -1,46 +0,0 @@
require "rack/commonlogger"
class JSONLogger < Rack::CommonLogger
def log(env, status, header, begin_at)
now = Time.now
length = extract_content_length(header)
data = {
"@timestamp" => now.iso8601,
:status => status.to_s[0..3],
:level => status < 399 ? "INFO" : 'ERROR',
:name => "Kibana",
:request_method => env["REQUEST_METHOD"],
:request => env["PATH_INFO"] + (env["QUERY_STRING"].empty? ? "" : "#{env['QUERY_STRING']}"),
:path => env["PATH_INFO"],
:query_string => env["QUERY_STRING"],
:remote_addr => env['HTTP_X_FORWARD_FOR'] || env["REMOTE_ADDR"],
:remote_user => env["REMOTE_USER"],
:http_version => env["HTTP_VERSION"],
:content_length => length,
:response_time => ((now - begin_at) * 1000).to_i # convert to milliseconds
}
# If there is an error then we need to append the stack
if env['sinatra.error']
error = env['sinatra.error']
data[:error] = {
:name => error.class.to_s,
:message => error.message,
:stack => error.backtrace
}
end
data[:message] = "#{data[:request_method]} #{data[:path]+(data[:query_string].empty? ? '' : '?'+data[:query_string])} #{data[:status]} #{data[:response_time]}ms - #{data[:content_length].empty? ? '-' : data[:content_length]}"
logger = @logger || env['rack.errors']
msg = data.to_json+"\n"
if logger.respond_to?(:write)
logger.write(msg)
else
logger << msg
end
end
end

View file

@ -1,36 +0,0 @@
require "rack/file"
PATH_INFO = 'PATH_INFO'
module Kibana
class MultiStatic
def initialize(app, options={})
@app = app
@prefix = options[:prefix] || '/'
@servers = (options[:paths] || []).map {|p| Rack::File.new(File.expand_path(p)) }
end
def call(env)
resp = nil
orig_path = env[PATH_INFO]
if orig_path.start_with? @prefix
env[PATH_INFO] = orig_path.sub @prefix, '/'
else
return @app.call(env)
end
@servers.each do |server|
resp = server.call(env)
resp = nil if resp[0] == 404
break if resp
end
return resp if resp
env[PATH_INFO] = orig_path
@app.call(env)
end
end
end

View file

@ -1,63 +0,0 @@
# Add the root of the project to the $LOAD_PATH, For some reason it seems
# to be getting lost when we use warble to make the jar. This fixes it :D
$LOAD_PATH.unshift(Kibana.global_settings[:root])
require "logger"
require "json"
require "lib/JSONLogger"
require "lib/ColorLogger"
require "routes/home"
require "sinatra/json"
require "routes/proxy"
require "lib/FrameOptions"
require "routes/plugins"
# require "rack/deflater"
class Logger
alias_method :write, :<<
end
module Kibana
class App < Sinatra::Base
helpers Sinatra::JSON
configure do
logger = Logger.new(STDOUT)
logger.formatter = proc do |severity, datetime, progname, msg|
data = {
'@timestamp' => datetime.iso8601,
:level => severity,
:name => progname || "Kibana",
:message => msg
}
data.to_json + "\n"
end
set :logger, logger
end
configure :production do
use JSONLogger, settings.logger unless Kibana.global_settings[:quiet]
end
configure :quiet do
set :logger, false
end
configure :development do
use ColorLogger, settings.logger unless Kibana.global_settings[:quiet]
end
not_found do
json :status => 404, :message => "Not Found"
end
# use Rack::Deflater
# Routes go here
use Routes::Home
use Routes::Proxy
use Routes::Plugins
end
end

View file

@ -1,7 +0,0 @@
module Kibana
module Helpers
def doSomething()
"Do it!"
end
end
end

View file

@ -1,68 +0,0 @@
require "rubygems"
require "bundler/setup"
require "puma"
require "colorize"
require "json"
require "#{Kibana.global_settings[:root]}/lib/app"
# Require the application
module Kibana
module Server
DEFAULTS = {
:host => '0.0.0.0',
:port => 5601,
:threads => '0:16',
:verbose => false
}
def self.log(msg)
return if Kibana.global_settings[:quiet]
if ENV['RACK_ENV'] == 'production'
data = {
"@timestamp" => Time.now.iso8601,
:level => 'INFO',
:name => 'Kibana',
:message => msg
}
puts data.to_json
else
message = (Time.now.strftime('%b %d, %Y @ %H:%M:%S.%L')).light_black << ' '
message << msg.yellow
puts message
end
end
def self.run(options = {})
options = DEFAULTS.merge(options)
min, max = options[:threads].split(':', 2)
app = Kibana::App.new()
server = Puma::Server.new(app)
# Configure server
begin
server.add_tcp_listener(options[:host], options[:port])
rescue Errno::EADDRINUSE
log("tcp://#{options[:host]}:#{options[:port]} is in use")
exit(1)
end
server.min_threads = min
server.max_threads = max
begin
log("Kibana server started on tcp://#{options[:host]}:#{options[:port]} in #{ENV['RACK_ENV']} mode.")
server.run.join
rescue Interrupt
log("Kibana server gracefully stopping, waiting for requests to finish")
server.stop(true)
log("Kibana server stopped.")
end
end
end
end

View file

@ -1,54 +0,0 @@
require "sinatra/base"
require "sinatra/json"
require "yaml"
require "timeout"
require "openssl"
module Kibana
module Routes
class Base < Sinatra::Base
helpers Sinatra::JSON
configure do
config = Kibana.global_settings[:config].clone()
config['elasticsearch'] = Kibana.global_settings[:elasticsearch]
config['port'] = Kibana.global_settings[:port].to_i
config['request_timeout'] = Kibana.global_settings[:request_timeout]
config['shard_timeout'] = Kibana.global_settings[:shard_timeout]
set :root, Kibana.global_settings[:root]
set :public_folder, Kibana.global_settings[:public_folder]
set :bundled_plugins_folder, Kibana.global_settings[:bundled_plugins_folder]
set :external_plugins_folder, Kibana.global_settings[:external_plugins_folder]
set :httponly, true
set :config, config
set :bundled_plugin_ids, config['bundled_plugin_ids'] || []
set :show_exceptions, false
set :raise_errors, false
set :dump_errors, false
end
error do
status 500
end
error OpenSSL::SSL::SSLError do
status 502
json :message => "SSL handshake with Elasticsearch failed"
end
error Errno::ECONNREFUSED do
status 502
json :message => "Unable to connect to Elasticsearch"
end
error Timeout::Error do
status 504
json :message => "Timeout while waiting for Elasticsearch"
end
end
end
end

View file

@ -1,46 +0,0 @@
require "routes/base"
module Kibana
module Routes
class Home < Base
get "/" do
File.read(File.join(settings.public_folder, 'index.html'))
end
get "/config" do
# Clone the settings object and change the elasticsearch attribute
# to the proxy for elasticsearch
data = settings.config.clone()
plugins = external_plugins.concat(bundled_plugins)
data['plugins'] = plugins
# Remove keys we do not want to expose
["elasticsearch", "elasticsearch_username", "elasticsearch_password"].each { |key| data.delete(key) }
json data
end
private
def external_plugins
plugins_ids_in(settings.external_plugins_folder)
end
def bundled_plugins
plugins_ids_in(settings.bundled_plugins_folder).concat(settings.bundled_plugin_ids)
end
def plugins_ids_in(dir)
if dir
indexes = Dir.glob(File.join(dir, '*', 'index.js'))
else
indexes = []
end
indexes.map { |path| path.sub(dir, 'plugins').sub(/\.js$/, '') }
end
end
end
end

View file

@ -1,15 +0,0 @@
require "routes/base"
require "lib/MultiStatic"
module Kibana
module Routes
class Plugins < Base
use Kibana::MultiStatic,
prefix: '/plugins/',
paths: [
settings.bundled_plugins_folder,
settings.external_plugins_folder
].compact
end
end
end

View file

@ -1,19 +0,0 @@
require "routes/base"
require "rack/reverse_proxy"
module Kibana
module Routes
class Proxy < Base
# Rack middleware goes here
config = settings.config
use Rack::ReverseProxy do
reverse_proxy_options timeout: config["request_timeout"]
@global_options[:verify_ssl] = config["verify_ssl"].nil? ? true : config["verify_ssl"]
reverse_proxy(/^\/elasticsearch(.*)$/, "#{config["elasticsearch"]}$1",
username: config["elasticsearch_username"],
password: config["elasticsearch_password"],
preserve_host: config["elasticsearch_preserve_host"].nil? ? true : config["elasticsearch_preserve_host"])
end
end
end
end