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

Multiple backends #66

Merged
merged 3 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source 'https://rubygems.org'

source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
Expand Down
23 changes: 13 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@
# [*sensu_api_endpoints*]
# Array of hashes
# Default: [{
# name => 'sensu',
# ssl => false,
# port => 4567,
# user => 'sensu',
# pass => 'sensu',
# path => '',
# timeout => 5,
# name => 'sensu',
# ssl => false,
# hostname => '127.0.0.1',
# port => 4567,
# user => 'sensu',
# pass => 'sensu',
# path => '',
# timeout => 5,
# }]
# An array of API endpoints to connect uchiwa to one or multiple sensu servers.
# An array of API endpoints to connect uchiwa to one or multiple sensu servers.
# The host field can be an array of hostnames or ip addresses for redundancy.
# You may also set the host field to be a single hostname or ip address string.
#
# [*users*]
# Array of hashes
# An array of user credentials to access the uchiwa dashboard. If set, it takes
# precendence over 'user' and 'pass'.
# Example:
# ```
# Example:
# ```
# [{
# 'username' => 'user1',
# 'password' => 'pass1',
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/uchiwa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@
}
end

context 'with sensu_api_endpoints multiple hosts' do
let(:params) {{ :sensu_api_endpoints => [ { 'name' => 'foo', 'host' => ['bar', 'baz' ] } ] }}
it {
should contain_file('/etc/sensu/uchiwa.json') \
.with_content(/"name": "foo"/) \
.with_content(/"host": "bar"/)
.with_content(/"host": "baz"/)
}
end

context 'with multiple users' do
let(:params) {{ :users => [ { 'username' => 'user1', 'password' => 'pass1', 'readonly' => true } ] }}
it {
Expand Down
37 changes: 23 additions & 14 deletions templates/etc/sensu/uchiwa.json.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
{
"sensu": [
<%- default_endpoint = scope['uchiwa::params::sensu_api_endpoints'][0] -%>
<%- @sensu_api_endpoints.each_with_index do |endpoint, i| -%>
{
"name": "<%= endpoint['name'] || default_endpoint['name'] %>",
"host": "<%= endpoint['host'] || default_endpoint['host'] %>",
"ssl": <%= endpoint['ssl'] || default_endpoint['ssl'] %>,
"insecure": <%= endpoint['insecure'] || default_endpoint['insecure']%>,
"port": <%= endpoint['port'] || default_endpoint['port'] %>,
"user": "<%= endpoint['user'] || default_endpoint['user'] %>",
"pass": "<%= endpoint['pass'] || default_endpoint['pass'] %>",
"path": "<%= endpoint['path'] || default_endpoint['path'] %>",
"timeout": <%= endpoint['timeout'] || default_endpoint['timeout'] %>
}<%= ',' if i < (@sensu_api_endpoints.size - 1) %>
<%- end -%>
<%-
default_endpoint = scope['uchiwa::params::sensu_api_endpoints'][0]
@sensu_api_endpoints.each_with_index do |endpoint, i|
if !endpoint['host'].kind_of?(Array)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docstring to explain how this works with an example of each? (array, non-array)

host = endpoint['host'] || default_endpoint['host']
endpoint['host'] = []
endpoint['host'] << host
end
endpoint['host'].each_with_index do |host,j| -%>
{
"name": "<%= endpoint['name'] || default_endpoint['name'] %>",
"host": "<%= host %>",
"ssl": <%= endpoint['ssl'] || default_endpoint['ssl'] %>,
"insecure": <%= endpoint['insecure'] || default_endpoint['insecure']%>,
"port": <%= endpoint['port'] || default_endpoint['port'] %>,
"user": "<%= endpoint['user'] || default_endpoint['user'] %>",
"pass": "<%= endpoint['pass'] || default_endpoint['pass'] %>",
"path": "<%= endpoint['path'] || default_endpoint['path'] %>",
"timeout": <%= endpoint['timeout'] || default_endpoint['timeout'] %>
}<%= ',' if j < (endpoint['host'].size - 1) %>
<%- end %>
<%= ',' if i < (@sensu_api_endpoints.size - 1) %>
<%- end -%>
],
"uchiwa": {
"host": "<%= @host %>",
Expand Down