Skip to content

Commit

Permalink
Merge pull request Yelp#21 from queeno/uchiwa_api_default_params
Browse files Browse the repository at this point in the history
Remove uchiwa::api and pass API data via class params
  • Loading branch information
solarkennedy committed Dec 1, 2014
2 parents 3c14820 + f8e8e27 commit 9398086
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 132 deletions.
5 changes: 2 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fixtures:
repositories:
apt: git://github.com/puppetlabs/puppetlabs-apt.git
datacat: git://github.com/richardc/puppet-datacat.git
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
apt: 'git://github.com/puppetlabs/puppetlabs-apt.git'
stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
symlinks:
uchiwa: "#{source_dir}"
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GEM
remote: https://rubygems.org/
remote: https://rubygems.org/
specs:
CFPropertyList (2.2.8)
Expand Down
1 change: 0 additions & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ project_page 'https://github.com/yelp/puppet-uchiwa'

dependency 'puppetlabs/apt'
dependency 'puppetlabs/stdlib'
dependency 'richardc/datacat'
38 changes: 19 additions & 19 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tested with Travis CI

## Upgrade Note

Versions greater than 0.2.0 are incompatible with previous versions of the Yelp-Uchiwa module.
Versions greater than 0.2.6 are incompatible with previous versions of the Yelp-Uchiwa module.

## Installation

Expand All @@ -18,7 +18,6 @@ Versions greater than 0.2.0 are incompatible with previous versions of the Yelp-
### Dependencies
- puppetlabs/apt
- puppetlabs/stdlib
- richardc/datacat

See `Modulefile` for details.

Expand All @@ -27,16 +26,15 @@ See `Modulefile` for details.
### Sensu server

node 'uchiwa-server.foo.com' {
class { 'uchiwa':
}
include ::uchiwa
}

## Advanced example using multiple APIs

API definitions will default to the following values:

name => Definition Name
host => ''
name => 'sensu'
host => '127.0.0.1'
ssl => false
insecure => false
port => 4567
Expand All @@ -48,21 +46,23 @@ API definitions will default to the following values:
This is an example of a 2 API setup:

node 'uchiwa-server.foo.com' {
class { 'uchiwa': }

uchiwa::api { ' API 1':
host => '10.56.5.8',
}
$uchiwa_api_config = [{
host => '10.56.5.8',
},
{
host => '10.16.1.25',
ssl => true,
insecure => true,
port => 7654,
user => 'sensu',
pass => 'saBEnX8PQoyz2LG',
path => '/sensu',
timeout => 5000
}]

uchiwa::api { 'API 2':
host => '10.16.1.25',
ssl => true,
insecure => true,
port => 7654,
user => 'sensu',
pass => 'saBEnX8PQoyz2LG',
path => '/sensu',
timeout => 5000
class { 'uchiwa':
sensu_api_endpoints => $uchiwa_api_config,
}
}

Expand Down
59 changes: 0 additions & 59 deletions manifests/api.pp

This file was deleted.

4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
class uchiwa::config {

datacat { '/etc/sensu/uchiwa.json':
template => 'uchiwa/etc/sensu/uchiwa.json.erb',
file { '/etc/sensu/uchiwa.json':
content => template('uchiwa/etc/sensu/uchiwa.json.erb'),
}
}
47 changes: 31 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# [*sample_parameter*]
# Explanation of what this parameter affects and what it defaults to.

#
# [*package_name*]
# String
# Default: uchiwa
Expand Down Expand Up @@ -82,23 +82,37 @@
# Default: 5
# Determines the interval to pull the Sensu API, in seconds
#
# [*sensu_api_endpoints*]
# Array of hashes
# Default: [{
# name => 'sensu',
# ssl => false,
# port => 4567,
# user => 'sensu',
# pass => 'sensu',
# path => '',
# timeout => 5,
# }]
# An array of API endpoints to connect uchiwa to one or multiple sensu servers.
#
class uchiwa (
$package_name = $uchiwa::params::package_name,
$service_name = $uchiwa::params::service_name,
$version = $uchiwa::params::version,
$install_repo = $uchiwa::params::install_repo,
$repo = $uchiwa::params::repo,
$repo_source = $uchiwa::params::repo_source,
$repo_key_id = $uchiwa::params::repo_key_id,
$repo_key_source = $uchiwa::params::repo_key_source,
$manage_services = $uchiwa::params::manage_services,
$manage_user = $uchiwa::params::manage_user,
$host = $uchiwa::params::host,
$port = $uchiwa::params::port,
$user = $uchiwa::params::user,
$pass = $uchiwa::params::pass,
$refresh = $uchiwa::params::refresh
$package_name = $uchiwa::params::package_name,
$service_name = $uchiwa::params::service_name,
$version = $uchiwa::params::version,
$install_repo = $uchiwa::params::install_repo,
$repo = $uchiwa::params::repo,
$repo_source = $uchiwa::params::repo_source,
$repo_key_id = $uchiwa::params::repo_key_id,
$repo_key_source = $uchiwa::params::repo_key_source,
$manage_services = $uchiwa::params::manage_services,
$manage_user = $uchiwa::params::manage_user,
$host = $uchiwa::params::host,
$port = $uchiwa::params::port,
$user = $uchiwa::params::user,
$pass = $uchiwa::params::pass,
$stats = $uchiwa::params::stats,
$refresh = $uchiwa::params::refresh,
$sensu_api_endpoints = $uchiwa::params::sensu_api_endpoints,
) inherits uchiwa::params {

# validate parameters here
Expand All @@ -117,6 +131,7 @@
validate_string($user)
validate_string($pass)
validate_string($refresh)
validate_array($sensu_api_endpoints)

anchor { 'uchiwa::begin': } ->
class { 'uchiwa::install': } ->
Expand Down
10 changes: 10 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
$manage_services = true
$manage_user = true

$sensu_api_endpoints = [{
name => 'sensu',
ssl => false,
port => 4567,
user => 'sensu',
pass => 'sensu',
path => '',
timeout => 5,
}]

$host = '0.0.0.0'
$port = 3000
$user = ''
Expand Down
1 change: 0 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@
"dependencies": [
{"name":"puppetlabs/apt"},
{"name":"puppetlabs/stdlib"},
{"name":"richardc/datacat"}
]
}
59 changes: 43 additions & 16 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ class { 'sensu':
}
class { 'uchiwa':
install_repo => false,
require => Class['sensu'],
install_repo => false,
sensu_api_endpoints => [{
name => 'Main Server',
host => '127.0.0.1',
ssl => false,
insecure => false,
port => 4567,
user => 'sensu',
pass => 'secret',
path => '',
timeout => 5000
}],
require => Class['sensu'],
}
uchiwa::api { 'Main Server':
host => '192.168.50.4',
ssl => false,
insecure => false,
port => 4567,
user => 'sensu',
pass => 'secret',
path => '',
timeout => 5000
}
EOS


# Run it twice and test for idempotency
expect(apply_manifest(pp, :catch_failures => true).exit_code)
expect(apply_manifest(pp, :catch_failures => true).exit_code)
Expand All @@ -54,6 +54,33 @@ class { 'uchiwa':
expect(curl.stdout).to include '<html lang="en" ng-app="uchiwa" ng-controller="init">'
end
end
end
it 'should produce consistent uchiwa.json file' do

uchiwa_json = "{\n\"sensu\": [\n {\n \"name\": \"Main Server\",\n \"host\": \"127.0.0.1\",\n \"ssl\": false,\n \"insecure\": false,\n \"port\": 4567,\n \"user\": \"sensu\",\n \"pass\": \"secret\",\n \"path\": \"\",\n \"timeout\": 5000\n }\n ],\n \"uchiwa\": {\n \"host\": \"0.0.0.0\",\n \"port\": 3000,\n \"user\": \"\",\n \"pass\": \"\",\n \"stats\": 10,\n \"refresh\": 10000\n }\n}\n"

shell('cat /etc/sensu/uchiwa.json') do |cat|
expect(cat.stdout).to eq (uchiwa_json)
end
end

it 'rerun puppet with default params' do

pp = <<-EOS
include ::uchiwa
EOS
expect(apply_manifest(pp, :catch_failures => true).exit_code)
end

it 'should produce a uchiwa.json file from defaults' do

uchiwa_json = "{\n\"sensu\": [\n {\n \"name\": \"sensu\",\n \"host\": \"127.0.0.1\",\n \"ssl\": false,\n \"insecure\": false,\n \"port\": 4567,\n \"user\": \"sensu\",\n \"pass\": \"sensu\",\n \"path\": \"\",\n \"timeout\": 5000\n }\n ],\n \"uchiwa\": {\n \"host\": \"0.0.0.0\",\n \"port\": 3000,\n \"user\": \"\",\n \"pass\": \"\",\n \"stats\": 10,\n \"refresh\": 10000\n }\n}\n"

shell('cat /etc/sensu/uchiwa.json') do |cat|
expect(cat.stdout).to eq (uchiwa_json)
end
end
end
end
end
end
1 change: 0 additions & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
shell('puppet module install puppetlabs-rabbitmq --version 4.1.0', { :acceptable_exit_codes => [0] })
shell('puppet module install fsalum-redis --version 1.0.0', { :acceptable_exit_codes => [0] })
shell('puppet module install sensu-sensu', { :acceptable_exit_codes => [0] })
shell('puppet module install richardc/datacat', { :acceptable_exit_codes => [0] })
end
end
end
35 changes: 22 additions & 13 deletions templates/etc/sensu/uchiwa.json.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"sensu": [
<%-
apis = Array.new
@data['api'].each do |a|
apis << a
end %>
<%= apis.join(",\n") %>
],
"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 -%>
],
"uchiwa": {
"host": "<%= @data['host'] %>",
"port": <%= @data['port'] %>,
"user": "<%= @data['user'] %>",
"pass": "<%= @data['pass'] %>",
"refresh": <%= @data['refresh'] %>
"host": "<%= @host %>",
"port": <%= @port %>,
"user": "<%= @user %>",
"pass": "<%= @pass %>",
"stats": <%= @stats %>,
"refresh": <%= @refresh %>
}
}

0 comments on commit 9398086

Please sign in to comment.