diff --git a/README.md b/README.md index decc0c8..6ae8c5f 100644 --- a/README.md +++ b/README.md @@ -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 => { @@ -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: diff --git a/manifests/config.pp b/manifests/config.pp index 51c3f61..98db914 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,6 +3,7 @@ class mackerel_agent::config( $ensure = present, $apikey = undef, + $roles = undef, $metrics_plugins = {}, $check_plugins = {} ) { diff --git a/manifests/init.pp b/manifests/init.pp index f59cd5a..bb5ca3d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -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 => { @@ -63,6 +68,7 @@ class mackerel_agent( $ensure = present, $apikey = undef, + $roles = undef, $service_ensure = running, $service_enable = true, $use_metrics_plugins = undef, @@ -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 { @@ -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'] diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index a0c539b..e8e040a 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -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 diff --git a/templates/mackerel-agent.conf.erb b/templates/mackerel-agent.conf.erb index d4c76ca..1207601 100644 --- a/templates/mackerel-agent.conf.erb +++ b/templates/mackerel-agent.conf.erb @@ -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"