Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
Support for KIbana 4
Browse files Browse the repository at this point in the history
  • Loading branch information
vvanholl committed May 10, 2015
1 parent 7b5eb59 commit afa21c8
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 11 deletions.
31 changes: 30 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
network:
- ["forwarded_port", {guest: 80, host: 8080}]
- ["forwarded_port", {guest: 8080, host: 8080}]

platforms:
- name: ubuntu-12.04
Expand All @@ -30,6 +30,8 @@ suites:
attributes:
kibana:
version: '3'
nginx:
listen_http: 8080
- name: kibana3_nginx
run_list:
- 'recipe[kibana]'
Expand All @@ -46,4 +48,31 @@ suites:
attributes:
kibana:
version: '3'
nginx:
listen_http: 8080
install_method: 'source'
- name: kibana4
run_list:
- 'recipe[kibana]'
attributes:
kibana:
version: '4'
- name: kibana4_nginx
run_list:
- 'recipe[kibana]'
- 'recipe[nginx]'
- 'recipe[kibana::nginx]'
- 'recipe[java]'
- 'recipe[elasticsearch]'
attributes:
kibana:
version: '4'
nginx:
listen_http: 8080
- name: kibana4_source
run_list:
- 'recipe[kibana]'
attributes:
kibana:
version: '4'
install_method: 'source'
2 changes: 2 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ group :vagrant do
cookbook 'apt'
cookbook 'apache2'
cookbook 'nginx'
cookbook 'java'
cookbook 'elasticsearch'
end
31 changes: 26 additions & 5 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Encoding: utf-8

#<> Kibana version
#<> Kibana major version
default['kibana']['version'] = '2'
#<> Kibana3 exact version
default['kibana']['kibana3_version'] = '3.0.0'
#<> Kibana4 exact version
default['kibana']['kibana4_version'] = '4.0.2'
#<> The base directory of kibana.
default['kibana']['base_dir'] = '/opt/kibana'
#<> The user under which Kibana is installed.
Expand All @@ -12,10 +14,15 @@
default['kibana']['group'] = 'kibana'
#<> Install method. Can be source or release
default['kibana']['install_method'] = 'release'

url_version = node['kibana']["kibana#{node['kibana']['version']}_version"] || node['kibana']['version']
#<> Url of tarball
default['kibana']['url'] = "https://download.elasticsearch.org/kibana/kibana/kibana-#{node['kibana']['kibana3_version']}.tar.gz"
default['kibana']['url'] = Kibana::Url.new(node, url_version).get
#<> Checksum of the tarball
default['kibana']['checksum'] = 'df25bc0cc02385edcac446ef8cbd83b896cdc910a0fa1b0a7bd2a958164593a8'
#<> Checksum of the tarball (for Kibana4)
default['kibana']['kibana4_checksum'] = '4cc36e5c6ca7c495667319df75feda1facb7c43a3d9686841f07a2522adec294'

#<> The URL to Kibana repository.
default['kibana']['git']['url'] = if node['kibana']['version'] > '2'
'https://github.com/elasticsearch/kibana.git'
Expand All @@ -32,7 +39,11 @@
default['kibana']['rubyversion'] = '1.9.1'

#<> The interface on which to bind.
default['kibana']['interface'] = node['ipaddress']
default['kibana']['interface'] = '127.0.0.1'
unless node['kibana']['version'] =~ /^3/
default['kibana']['interface'] = node['ipaddress']
end

#<> The port on which to bind.
default['kibana']['port'] = 5601
#<> An Array of the elasticsearch service hosts.
Expand All @@ -43,9 +54,9 @@
default['kibana']['default_fields'] = '["@message"]'
#<> The operator used if no explicit operator is specified.
default['kibana']['default_operator'] = 'OR'
#<> The cookbook from which config.js template is taken
#<> The cookbook from which configuration template is taken
default['kibana']['config']['cookbook'] = nil
#<> The template from which config.js is generated from
#<> The template from which configuration is generated from
default['kibana']['config']['source'] = nil
#<> Fields specifiers which default to @message (may need to be changed for newer logstash)
default['kibana']['highlighted_field'] = '@message'
Expand Down Expand Up @@ -103,3 +114,13 @@

#<> The virtualhost server name.
default['kibana']['nginx']['server_name'] = 'kibana'

#<> Redirect requests to kibana service
default['kibana']['nginx']['kibana_service'] = nil
unless node['kibana']['version'] =~ /^3/
default['kibana']['nginx']['kibana_service'] = "http://#{node['kibana']['interface']}:#{node['kibana']['port']}"
end

#<> The kibana service configuration source
default['kibana']['service']['source'] = 'upstart.conf.erb'
default['kibana']['service']['cookbook'] = 'kibana'
39 changes: 39 additions & 0 deletions libraries/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Kibana
# All to find correct url to download kibana
class Url
def initialize(node, version)
@node = node
@version = version
end

def get
prefix = 'https://download.elasticsearch.org/kibana/kibana/kibana-'
suffix = case @version
when /^3\./
"#{@version}.#{ext}"
else
"#{@version}-#{@node['os']}#{arch}.#{ext}"
end
prefix + suffix
end

def ext
case @node['os']
when 'windows'
'zip'
else
'tar.gz'
end
end

def arch
return '' if @node['os'] == 'windows'
case @node['kernel']['machine']
when 'x86_64'
'-x64'
else
'-x86'
end
end
end
end
2 changes: 2 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
suggests 'authbind'
suggests 'apt'
suggests 'nginx'
suggests 'java'
suggests 'elasticsearch'
18 changes: 18 additions & 0 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Encoding: utf-8

service 'kibana' do
provider Chef::Provider::Service::Upstart
supports start: true, restart: true, stop: true, status: true
action :nothing
end

template '/etc/init/kibana.conf' do
cookbook node['kibana']['service']['cookbook']
source node['kibana']['service']['source']
variables(
version: node['kibana']['version'],
options: '', # TODO
recent_upstart: (node['platform_family'] != 'rhel'),
)
notifies :restart, 'service[kibana]', :delayed
end
35 changes: 35 additions & 0 deletions recipes/kibana4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Encoding: utf-8

include_recipe 'kibana'

if node['kibana']['install_method'] == 'release'
ark 'kibana' do
url node['kibana']['url']
version node['kibana']['kibana4_version']
checksum node['kibana']['kibana4_checksum']
path node['kibana']['base_dir']
home_dir File.join(node['kibana']['base_dir'], 'current')
end
config_path = 'current/config/kibana.yml'
else
Chef::Application.fatal!("Since Kibana version 4, install method can only be only 'release'")
end

# Apply config template
template File.join(node['kibana']['base_dir'], config_path) do
cookbook node['kibana']['config']['cookbook']
source node['kibana']['config']['source']
owner node['kibana']['user']
group node['kibana']['group']
mode '0644'
variables(
es_port: node['kibana']['elasticsearch']['port'],
port: node['kibana']['port'],
bind: node['kibana']['interface'],
es_host: node['kibana']['elasticsearch']['hosts'].first,
)
notifies :restart, 'service[kibana]'
end

# Install service
include_recipe 'kibana::_service'
1 change: 1 addition & 0 deletions recipes/nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'ssl_session_cache' => node['kibana']['nginx']['ssl_session_cache'],
'ssl_session_timeout' => node['kibana']['nginx']['ssl_session_timeout'],
'proxy' => node['kibana']['nginx']['proxy'],
'kibana_service' => node['kibana']['nginx']['kibana_service'],
'auth' => node['kibana']['nginx']['auth'],
'auth_file' => node['kibana']['auth_file']
)
Expand Down
68 changes: 68 additions & 0 deletions templates/default/kibana.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !! Managed by Chef, do not edit !!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# Kibana is served by a back end server. This controls which port to use.
port: <%= @port %>

# The host to bind the server to.
host: "<%= @bind %>"

# The Elasticsearch instance to use for all your queries.
elasticsearch_url: "http://<%= @es_host %>:<%= @es_port %>"

# 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"

# If your Elasticsearch is protected with basic auth, this is the user credentials
# used by the Kibana server to perform maintence on the kibana_index at statup. Your Kibana
# users will still need to authenticate with Elasticsearch (which is proxied thorugh
# the Kibana server)
# kibana_elasticsearch_username: user
# kibana_elasticsearch_password: pass


# The default application to load.
default_app_id: "discover"

# Time in milliseconds to wait for responses from the back end or elasticsearch.
# This must be > 0
request_timeout: 300000

# Time in milliseconds for Elasticsearch to wait for responses from shards.
# Set to 0 to disable.
shard_timeout: 0

# Set to false to have a complete disregard for the validity of the SSL
# certificate.
verify_ssl: true

# If you need to provide a CA certificate for your Elasticsarech instance, put
# the path of the pem file here.
# ca: /path/to/your/CA.pem

# SSL for outgoing requests from the Kibana Server (PEM formatted)
# ssl_key_file: /path/to/your/server.key
# ssl_cert_file: /path/to/your/server.crt

# Set the path to where you would like the process id file to be created.
# pid_file: /var/run/kibana.pid


# Plugins that are included in the build, and no longer found in the plugins/ folder
bundled_plugin_ids:
- plugins/dashboard/index
- plugins/discover/index
- plugins/doc/index
- plugins/kibana/index
- plugins/markdown_vis/index
- plugins/metric_vis/index
- plugins/settings/index
- plugins/table_vis/index
- plugins/vis_types/index
- plugins/visualize/index
3 changes: 3 additions & 0 deletions templates/default/nginx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ server {
auth_basic "Kibana Auth";
auth_basic_user_file <%= @auth_file %>;
<% end %>
<% if @kibana_service %>
proxy_pass <%= @kibana_service %>;
<% end %>
}

<% if @proxy %>
Expand Down
30 changes: 25 additions & 5 deletions templates/default/upstart.conf.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#
# Generated by Chef
#
description "Kibana Server"
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !! Managed by Chef, do not edit !!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
description "Kibana Server"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

<% if @recent_upstart %>
setuid <%= node['kibana']['user'] %>
setgid <%= node['kibana']['group'] %>
<% end %>
respawn limit 15 5
umask 0077

Expand All @@ -16,4 +18,22 @@ pre-start script
end script

chdir <%= node['kibana']['base_dir'] %>
exec <%= node['kibana']['port'] < 1024 ? "/usr/bin/authbind --deep " : "" %>ruby<%= node['kibana']['rubyversion'] %> kibana.rb
<%
command = case @version
when /^2/
"ruby#{node['kibana']['rubyversion']} kibana.rb"
when /^3/
raise "kibana 3 cannot be started as a service"
when /^4/
"current/bin/kibana #{@options}"
end
if node['kibana']['port'] < 1024
command = "/usr/bin/authbind --deep " + command
end
%>

<% if @recent_upstart %>
exec <%= command %>
<% else %>
exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node['kibana']['user'] %> -- <%= command %>
<% end %>

0 comments on commit afa21c8

Please sign in to comment.