diff --git a/manifests/init.pp b/manifests/init.pp index af9c008..23f1d7f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -15,8 +15,13 @@ # Class to install kibana frontend to logstash. # class kibana ( - $discover_nodes = ['localhost:9200'], - $version = 'ruby', + $discover_nodes = ['localhost:9200'], + $version = 'ruby', + $js_vhost_name = $::fqdn, + $js_vhost_aliases = [], + $js_vhost_template = 'kibana/dual-elasticsearch.vhost.erb', + $js_elasticsearch_prefix = '/', + $js_elasticsearch_url = 'http://localhost:9200', ) { group { 'kibana': @@ -46,6 +51,15 @@ class kibana ( 'ruby': { include ::kibana::ruby } + 'js': { + class { '::kibana::js': + vhost_name => $js_vhost_name, + vhost_aliases => $js_vhost_aliases, + vhost_template => $js_vhost_template, + elasticsearch_prefix => $js_elasticsearch_prefix, + elasticsearch_url => $js_elasticsearch_url, + } + } default: { fail("Unknown version: ${version}") } diff --git a/manifests/js.pp b/manifests/js.pp new file mode 100644 index 0000000..646db02 --- /dev/null +++ b/manifests/js.pp @@ -0,0 +1,54 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Class to install kibana frontend to logstash. +# +class kibana::js ( + $vhost_template = 'kibana/dual-elasticsearch.vhost.erb', + $vhost_aliases = [], + $vhost_name = $::fqdn, + $vhost_proxy_timeout = '120', + $vhost_proxy_connect_timeout = '15', + $elasticsearch_url = 'http://localhost:9200', + $elasticsearch_prefix = '/', # Must contain trailing / + $git_revision = 'v3.1.2', +) { + + $base_path = "/opt/kibana/${git_revision}" + + vcsrepo { $base_path: + ensure => latest, + provider => 'git', + source => 'https://github.com/elasticsearch/kibana.git', + revision => $git_revision, + owner => 'www-data', + } + + file { "${base_path}/src/config.js": + ensure => present, + content => template('kibana/config.js.erb'), + owner => 'www-data', + require => Vcsrepo[$base_path], + subscribe => Vcsrepo[$base_path], + } + + apache::vhost { 'kibana': + docroot => "${base_path}/src", + vhost_name => $vhost_name, + serveraliases => $vhost_aliases, + port => 80, + template => $vhost_template, + } + +} diff --git a/templates/config.js.erb b/templates/config.js.erb new file mode 100644 index 0000000..411ffa9 --- /dev/null +++ b/templates/config.js.erb @@ -0,0 +1,80 @@ +/** @scratch /configuration/config.js/1 + * + * == Configuration + * config.js is where you will find the core Kibana configuration. This file contains parameter that + * must be set before kibana is run for the first time. + */ +define(['settings'], +function (Settings) { + "use strict"; + + /** @scratch /configuration/config.js/2 + * + * === Parameters + */ + return new Settings({ + + /** @scratch /configuration/config.js/5 + * + * ==== elasticsearch + * + * The URL to your elasticsearch server. You almost certainly don't + * want +http://localhost:9200+ here. Even if Kibana and Elasticsearch are on + * the same host. By default this will attempt to reach ES at the same host you have + * kibana installed on. You probably want to set it to the FQDN of your + * elasticsearch host + * + * Note: this can also be an object if you want to pass options to the http client. For example: + * + * +elasticsearch: {server: "http://localhost:9200", withCredentials: true}+ + * + */ + elasticsearch: "http://"+window.location.hostname+":80"+"<%= @elasticsearch_prefix %>", + + /** @scratch /configuration/config.js/5 + * + * ==== default_route + * + * This is the default landing page when you don't specify a dashboard to load. You can specify + * files, scripts or saved dashboards here. For example, if you had saved a dashboard called + * `WebLogs' to elasticsearch you might use: + * + * default_route: '/dashboard/elasticsearch/WebLogs', + */ + default_route : '/dashboard/file/logstash.json', + + /** @scratch /configuration/config.js/5 + * + * ==== kibana-int + * + * The default ES index to use for storing Kibana specific object + * such as stored dashboards + */ + kibana_index: "kibana-int", + + /** @scratch /configuration/config.js/5 + * + * ==== panel_name + * + * An array of panel modules available. Panels will only be loaded when they are defined in the + * dashboard, but this list is used in the "add panel" interface. + */ + panel_names: [ + 'histogram', + 'map', + 'goal', + 'table', + 'filtering', + 'timepicker', + 'text', + 'hits', + 'column', + 'trends', + 'bettermap', + 'query', + 'terms', + 'stats', + 'sparklines' + ] + }); +}); diff --git a/templates/dual-elasticsearch.vhost.erb b/templates/dual-elasticsearch.vhost.erb new file mode 100644 index 0000000..78b3394 --- /dev/null +++ b/templates/dual-elasticsearch.vhost.erb @@ -0,0 +1,41 @@ + + ServerName <%= @vhost_name %> + ServerAdmin <%= @serveradmin %> +<% if @serveraliases.is_a? Array %> +<% serveraliases.each do |name| %><%= " ServerAlias #{name}\n" %><% end %> +<% elsif @serveraliases != '' %> +<%= " ServerAlias #{serveraliases}" %> +<% end %> + + ErrorLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-error.log + + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-access.log combined + + + # Proxy GETs for elasticsearch .*/_aliases, .*/_status, .*/_search, + # .*/_mapping, .*/_mapping/field/.*, _cluster/health, _cluster/state/.*, + # _nodes. and _nodes/stats + # These GETs allow read-only access for kibana3, elasticsearch-head, and bigdesk, + # as well as arbitrary searches using the elasticsearch search api. + RewriteEngine on + RewriteCond %{REQUEST_METHOD} GET + RewriteRule ^<%= @elasticsearch_prefix %>((.*/)?_aliases|(.*/)?_status|(.*/)?_search|(.*/)?_mapping(/field(/.*)?)?|_cluster/(health|state(/.*)?)|_nodes(/stats)?)$ <%= @elasticsearch_url %>/$1 [P] + RewriteCond %{REQUEST_METHOD} POST + RewriteRule ^<%= @elasticsearch_prefix %>(_aliases|(.*/)?_search)$ <%= @elasticsearch_url %>/$1 [P] + RewriteCond %{REQUEST_METHOD} OPTIONS + RewriteRule ^<%= @elasticsearch_prefix %>((.*/)?_search)$ <%= @elasticsearch_url %>/$1 [P] + /> + ProxySet connectiontimeout=<%= @vhost_proxy_connect_timeout %> timeout=<%= @vhost_proxy_timeout %> + + ProxyPassReverse <%= @elasticsearch_prefix %> <%= @elasticsearch_url %>/ + + + DocumentRoot <%= docroot %> + > + Options -Multiviews + + + +