Skip to content

Commit

Permalink
Add option to configure server role
Browse files Browse the repository at this point in the history
  • Loading branch information
hanazuki committed May 13, 2016
1 parent cbe35ba commit e29c018
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Usage
```puppet
class { 'mackerel_agent':
apikey => 'Your API Key',
roles => ['service:web', 'service:database']
use_metrics_plugins => true,
use_check_plugins => true,
metrics_plugins => {
Expand All @@ -54,6 +55,9 @@ class { 'mackerel_agent':

```yaml
mackerel_agent::apikey: 'Your API Key'
mackerel_agent::roles:
- 'service:web'
- 'service:database'
mackerel_agent::use_metrics_plugins: true
mackerel_agent::use_check_plugins: true
mackerel_agent::metrics_plugins:
Expand Down
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class mackerel_agent::config(
$ensure = present,
$apikey = undef,
$roles = undef,
$metrics_plugins = {},
$check_plugins = {}
) {
Expand Down
11 changes: 11 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# Your mackerel API key
# Defaults to undefined
#
# [*roles*]
# Name of roles to which the server is assigned
# Defaults to undefined
#
# [*service_ensure*]
# Whether you want to mackerel-agent daemon to start up
# Defaults to running
Expand Down Expand Up @@ -40,6 +44,7 @@
#
# class { 'mackerel_agent':
# apikey => 'Your API Key'
# roles => ['service:web', 'service:database']
# use_metrics_plugins => true,
# use_check_plugins => true,
# metrics_plugins => {
Expand All @@ -63,6 +68,7 @@
class mackerel_agent(
$ensure = present,
$apikey = undef,
$roles = undef,
$service_ensure = running,
$service_enable = true,
$use_metrics_plugins = undef,
Expand All @@ -76,6 +82,10 @@
validate_hash($metrics_plugins)
validate_hash($check_plugins)

if $roles != undef {
validate_array($roles)
}

if $apikey == undef {
crit('apikey must be specified in the class paramerter.')
} else {
Expand All @@ -87,6 +97,7 @@

class { 'mackerel_agent::config':
apikey => $apikey,
roles => $roles,
metrics_plugins => $metrics_plugins,
check_plugins => $check_plugins,
require => Class['mackerel_agent::install']
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@

it { should contain_file('mackerel-agent.conf').with_ensure('absent') }
end

context 'with roles' do
let(:params) do
{ :roles => %w[service:web service:database] }
end

it { should contain_file('mackerel-agent.conf').with_ensure('present').with_content(%r{^roles = \["service:web", "service:database"\]$}) }
end
end
4 changes: 4 additions & 0 deletions templates/mackerel-agent.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pidfile = "./pid"
root = "."
verbose = false

<% if @roles %>
roles = [<%= @roles.map {|r| %{"#{r}"} }.join(', ') %>]
<% end %>

# Include other config files
include = "/etc/mackerel-agent/conf.d/*.conf"

Expand Down

0 comments on commit e29c018

Please sign in to comment.