From da765573db085a138242d5b0680dd61042d7fd96 Mon Sep 17 00:00:00 2001 From: paulczar Date: Sun, 13 Jul 2014 11:32:15 -0500 Subject: [PATCH] ready for merge --- .kitchen.yml | 2 + README.md | 98 +++++++--------------------------- attributes/apache.rb | 2 + attributes/default.rb | 36 ++++++++++--- attributes/nginx.rb | 2 + providers/install.rb | 2 +- recipes/default.rb | 72 +++++++++++++++++++++++++ test/unit/spec/default_spec.rb | 9 +++- 8 files changed, 135 insertions(+), 88 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 69b84d6..212e0b5 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -14,3 +14,5 @@ suites: - recipe[apt::default] - recipe[kibana::install] attributes: + kibana: + legacy_mode: false diff --git a/README.md b/README.md index a1ee21c..0e2a1a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ kibana Cookbook =============== -A stand-alone cookbook for Kibana3 + +A stand-alone cookbook for Kibana3. + +This is a library cookbook, you can use you included `kibana::install` recipe to install kibana, or you can call the LWRPs directly. + +If you are upgrading from the previous (< 1.3) cookbook you can set `node['kibana']['legacy_mode'] = true` which should continue working. This will be removed at some point and you'll be expected to use it as a library cookbook. + +This cookbook is tested and works well with the `logstash` and the `elasticsearch` cookbooks found on the chef community site. Requirements ------------ @@ -15,59 +22,23 @@ Attributes ---------- As with most cookbooks I write, this one is hopefully flexible enough to be wrapped by allowing you to override as much as possible -#### kibana::default - -- `node['kibana']['install_type']` - The type of install we are going to use either `git` or `zipfile` -- `node['kibana']['git']['url']` - The url for the git repo to use for Kibana3 -- `node['kibana']['git']['branch']` - The sha or branch name to use -- `node['kibana']['file']['type']` - the type of archive file. `zip` only at this stage -- `node['kibana']['file']['url']` - The zipfile URL for the latest kibana build -- `node['kibana']['file']['checksum']` - The sha256 of the kibana zipfile -- `node['kibana']['install_path']` - The root directory where kibana will be installed -- `node['kibana']['install_dir']` - The directory to checkout into. A `current` symlink will be created in this directory as well. -- `node['kibana']['es_server']` - The ipaddress or hostname of your elasticsearch server -- `node['kibana']['es_port']` - The port of your elasticsearch server's http interface -- `node['kibana']['es_role']` - **unused** eventually for wiring up discovery of your elasticsearch server -- `node['kibana']['es_scheme']` - Scheme helper if elasticsearch is outside of this cookbook `http://` or `https://` -- `node['kibana']['user']` - The user who will own the files from the git checkout. (default: the web server user) -- `node['kibana']['config_template']` - The template to use for kibana's `config.js` -- `node['kibana']['config_cookbook']` - The cookbook that contains said config template -- `node['kibana']['webserver']` - Which webserver to use: apache, nginx or '' -- `node['kibana']['webserver_hostname']` - The primary vhost the web server will use for kibana -- `node['kibana']['webserver_aliases']` - Array of any secondary hostnames that are valid vhosts -- `node['kibana']['webserver_listen']` - The ip address the web server will listen on -- `node['kibana']['webserver_port']` - The port the webserver will listen on -- `node['kibana']['webserver_scheme']` - Scheme helper if webserver is outside of this cookbook `http://` or `https://` -- `node['kibana']['config']['elasticsearch']` - The URL or a javascript expression with for the elasticsearch server to connect to - -#### kibana::nginx - -- `node['kibana']['nginx']['template']` - The template file to use for the nginx site configuration -- `node['kibana']['nginx']['template_cookbook']` - The cookbook containing said template -- `node['kibana']['nginx']['enable_default_site']` - Should we disable the nginx default site (default: true) -- `node['kibana']['nginx']['install_method']` - nginx install method: `source` or `package` (default: package) - -#### kibana::apache - -- `node['kibana']['apache']['template']` - The template file to use for the apache site configuration -- `node['kibana']['apache']['template_cookbook']` - The cookbook containing said template -- `node['kibana']['apache']['enable_default_site']` - Should we disable the apache default site (default: true) +See `attributes/*.rb` for attributes ( documented inline ) Usage ----- #### kibana::default -The default recipe does nothing except for allow access to the LWRPs. +The default recipe does nothing except for allow access to the LWRPs unless `legacy_mode` is turned on in which case it attempts to install kibana +in the old fashioned way. #### kibana::install -The install recipe will: +This is designed to be an example recipe to show you how you might write a wrapper cookbook. However it should be usable for a +simple install of kibana. - install kibana3 from `master` into `/opt/kibana/master` and create a symlink called `current` in the same directory to `master` - install `nginx` and serve the kibana application -If you want to use the zipfile distribution of Kibana update `node['kibana']['install_type']` attribute to `zipfile`. Set `node['kibana']['zipfile_checksum']` to appropriate sha256 value of latest zipfile. - If you wish to swap `apache` for `nginx`, simply set `node['kibana']['webserver']` to `apache` in a role/environment/node somewhere. If you don't want this cookbook to handle the webserver config simply set `node['kibana']['webserver']` to `''` in a role/environment/node somewhere. @@ -86,50 +57,21 @@ If you would like to modify the `nginx` or `apache` parameters, you should: #### kibana::examples -The examples cookbook lists further examples using the LWRPs to install and configure kibana. +The examples cookbook lists further examples using the LWRPs to install and configure kibana and is definately _not_ intended to be run. Testing ------- -#### Vagrant - -Requires Vagrant >= 1.2 with the following plugins : - -* vagrant-berkshef -* vagrant-omnibus - -``` -$ vagrant up ubuntu1204 -``` +#### kitchen -If you get the following error then run `vagrant provision ubuntu1204`. For some reason on my box it's occasionally failing to launch the shell provisioner. - -``` -[ubuntu1204] Running: inline script -stdin: is not a tty -The following SSH command responded with a non-zero exit status. -Vagrant assumes that this means the command failed! - -chmod +x /tmp/vagrant-shell && /tmp/vagrant-shell -``` - -#### Vagabond - -This should be a quicker test suite than Vagrant. However I'm currently hitting -this bug : https://github.com/chrisroberts/vagabond/issues/40. In theory the following should work - -``` -vagabond up ubuntu1204 -``` - - -#### Strainer ``` $ bundle install $ bundle exec berks install -$ bundle exec strainer test +$ bundle exec rake style spec # spec and style checks +$ bundle exec rake kitchen # integration testing ``` + Contributing ------------ - Fork the repository on Github @@ -142,9 +84,10 @@ Contributing License and Authors ------------------- -Primary author: +Primary authors: - John E. Vincent +- Paul Czarkowski Contributors: @@ -154,7 +97,6 @@ Contributors: - Chris Ferry (@chrisferry) - Ian Neubert (@ianneub) - kellam (@klamontagne) -- Paul Czarkowski (@paulczar) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/attributes/apache.rb b/attributes/apache.rb index c7a5709..271020b 100644 --- a/attributes/apache.rb +++ b/attributes/apache.rb @@ -1,3 +1,5 @@ +# Apache variables. + default['kibana']['apache']['template'] = 'kibana-apache.conf.erb' default['kibana']['apache']['template_cookbook'] = 'kibana' default['kibana']['apache']['enable_default_site'] = false diff --git a/attributes/default.rb b/attributes/default.rb index 00a674a..6bd7e70 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,30 +1,50 @@ +# The method used to install kibana. `git` will clone the git repo, +# `file` will download from elasticsearch.org default['kibana']['install_type'] = 'file' # git | file + +# Values to use for git method of installation default['kibana']['git']['url'] = 'https://github.com/elasticsearch/kibana' default['kibana']['git']['branch'] = 'master' default['kibana']['git']['type'] = 'sync' # checkout | sync -default['kibana']['file']['type'] = 'tgz' # zip + +# Values to use for file method of installation +default['kibana']['file']['type'] = 'tgz' # zip | tgz default['kibana']['file']['url'] = 'https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz' default['kibana']['file']['version'] = '3.1.0' # must match version number of above default['kibana']['file']['checksum'] = '059a4b6b507b9ff771901d12035e499b0e8d1cae7d9e5284633e19da6c294e07' # sha256 ( shasum -a 256 FILENAME ) -default['kibana']['webserver'] = 'nginx' + +# Which webserver to use, and webserver options. +default['kibana']['webserver'] = 'nginx' # nginx or apache +default['kibana']['webserver_hostname'] = node.name +default['kibana']['webserver_aliases'] = [node.ipaddress] +default['kibana']['webserver_listen'] = node.ipaddress +default['kibana']['webserver_port'] = 80 +default['kibana']['webserver_scheme'] = 'http://' + +# parent directory of install_dir. This is required because of the `file` method. default['kibana']['install_path'] = '/opt' + +# the actual installation directory of kibana. If using the `file` method this should be left as is. default['kibana']['install_dir'] = "#{node['kibana']['install_path']}/kibana" + +# used to configure proxy information for the webserver to proxy ES calls. default['kibana']['es_server'] = '127.0.0.1' default['kibana']['es_port'] = '9200' default['kibana']['es_role'] = 'elasticsearch_server' default['kibana']['es_scheme'] = 'http://' + +# user to install kibana files as. if left blank will use the default webserver user. default['kibana']['user'] = '' + +# config template location and variables. default['kibana']['config_template'] = 'config.js.erb' default['kibana']['config_cookbook'] = 'kibana' -default['kibana']['webserver_hostname'] = node.name -default['kibana']['webserver_aliases'] = [node.ipaddress] -default['kibana']['webserver_listen'] = node.ipaddress -default['kibana']['webserver_port'] = 80 -default['kibana']['webserver_scheme'] = 'http://' default['kibana']['config']['kibana_index'] = 'kibana-int' default['kibana']['config']['panel_names'] = %w(histogram map pie table filtering timepicker text fields hits dashcontrol column derivequeries trends bettermap query terms) default['kibana']['config']['default_route'] = '/dashboard/file/logstash.json' - # include quote inside this next variable if not using window.location style variables... # e.g. = "'http://elasticsearch.example.com:9200'" default['kibana']['config']['elasticsearch'] = "window.location.protocol+\"//\"+window.location.hostname+\":\"+window.location.port" + +# Enables legacy mode for people upgrading from ealier version of cookbook. +default['kibana']['legacy_mode'] = false diff --git a/attributes/nginx.rb b/attributes/nginx.rb index 2e4d33d..728ef80 100644 --- a/attributes/nginx.rb +++ b/attributes/nginx.rb @@ -1,3 +1,5 @@ +# nginx variables. + default['kibana']['nginx']['template'] = 'kibana-nginx.conf.erb' default['kibana']['nginx']['template_cookbook'] = 'kibana' default['kibana']['nginx']['enable_default_site'] = false diff --git a/providers/install.rb b/providers/install.rb index 82e4bd7..7aa80cf 100644 --- a/providers/install.rb +++ b/providers/install.rb @@ -56,7 +56,7 @@ def load_current_resource when 'file' @run_context.include_recipe 'libarchive::default' case kb_args[:file_type] - when 'tgz' + when 'tgz', 'zip' rf = remote_file "#{Chef::Config[:file_cache_path]}/kibana_#{kb_args[:name]}.tar.gz" do checksum kb_args[:file_checksum] source kb_args[:file_url] diff --git a/recipes/default.rb b/recipes/default.rb index 49bce69..b73df83 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -16,3 +16,75 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +if node['kibana']['legacy_mode'] + # Temporarily here to allow to use the old way. + include_recipe 'git' + + unless Chef::Config[:solo] + es_server_results = search(:node, "roles:#{node['kibana']['es_role']} AND chef_environment:#{node.chef_environment}") + unless es_server_results.empty? + node.set['kibana']['es_server'] = es_server_results[0]['ipaddress'] + end + end + + if node['kibana']['user'].empty? + if !node['kibana']['webserver'].empty? + webserver = node['kibana']['webserver'] + kibana_user = node[webserver]['user'] + else + kibana_user = 'nobody' + end + else + kibana_user = node['kibana']['user'] + end + + directory node['kibana']['install_dir'] do + recursive true + owner kibana_user + mode '0755' + end + + case node['kibana']['install_type'] + when 'git' + git "#{node['kibana']['install_dir']}/#{node['kibana']['git']['branch']}" do + repository node['kibana']['git']['url'] + reference node['kibana']['git']['branch'] + action node['kibana']['git']['type'].to_sym + user kibana_user + end + link "#{node['kibana']['install_dir']}/current" do + to "#{node['kibana']['install_dir']}/#{node['kibana']['git']['branch']}" + end + node.set['kibana']['web_dir'] = "#{node['kibana']['install_dir']}/current/src" + when 'file' + case node['kibana']['file']['type'] + when 'zip', 'tgz' + include_recipe 'ark::default' + ark 'kibana' do + url node['kibana']['file']['url'] + path node['kibana']['install_path'] + checksum node['kibana']['file']['checksum'] + owner kibana_user + action :put + end + node.set['kibana']['web_dir'] = node['kibana']['install_dir'] + end + end + + template "#{node['kibana']['web_dir']}/config.js" do + source node['kibana']['config_template'] + cookbook node['kibana']['config_cookbook'] + mode '0750' + user kibana_user + end + + link "#{node['kibana']['web_dir']}/app/dashboards/default.json" do + to 'logstash.json' + only_if { !File.symlink?("#{node['kibana']['web_dir']}/app/dashboards/default.json") } + end + + unless node['kibana']['webserver'].empty? + include_recipe "kibana::#{node['kibana']['webserver']}" + end +end diff --git a/test/unit/spec/default_spec.rb b/test/unit/spec/default_spec.rb index 85699b8..8cbfa75 100644 --- a/test/unit/spec/default_spec.rb +++ b/test/unit/spec/default_spec.rb @@ -4,7 +4,14 @@ describe 'kibana::default' do describe 'ubuntu' do - let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } + let(:runner) { ChefSpec::Runner.new(::UBUNTU_OPTS) } + let(:node) { runner.node } + let(:chef_run) do + # runner.node.set['logstash'] ... + runner.node.set['kibana']['legacy_mode'] = 'false' + runner.converge(described_recipe) + end + include_context 'stubs-common' it 'literally does nothing because its a lazy no good recipe.' do end