Add kibana3 support

Add support for the javascript version of kibana.

By default, this is done by serving both the kibana and also an
elasticsearch proxy from the same location. Allowed GETs and POSTs
for read-only access to elasticsearch are passed to a proxy and all
other requests are served from the kibana source directory.

An optional prefix, such as 'elasticsearch/', can be specified in which
case the reverse proxy to elasticsearch will be served from this
sub-path.

Change-Id: I13f9dff0bbd6498a36dc75b026c9042a9bb05e8f
This commit is contained in:
K Jonathan Harker 2015-06-02 16:24:30 -07:00
parent 3e95d92cfc
commit 8c66da99df
4 changed files with 191 additions and 2 deletions

View File

@ -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}")
}

54
manifests/js.pp Normal file
View File

@ -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,
}
}

80
templates/config.js.erb Normal file
View File

@ -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'
]
});
});

View File

@ -0,0 +1,41 @@
<VirtualHost *:80>
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
<IfModule mod_proxy.c>
# 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]
<Proxy <%= @elasticsearch_url %>/>
ProxySet connectiontimeout=<%= @vhost_proxy_connect_timeout %> timeout=<%= @vhost_proxy_timeout %>
</Proxy>
ProxyPassReverse <%= @elasticsearch_prefix %> <%= @elasticsearch_url %>/
</IfModule>
DocumentRoot <%= docroot %>
<Directory <%= docroot %>>
Options -Multiviews
</Directory>
</VirtualHost>