diff --git a/README.md b/README.md index 54ff77c..02a3ae3 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,11 @@ Usage ```puppet class { 'mackerel_agent': apikey => 'Your API Key', - roles => ['service:web', 'service:database'] + roles => ['service:web', 'service:database'], + host_status => { + on_start => 'working', + on_stop => 'poweroff' + }, use_metrics_plugins => true, use_check_plugins => true, metrics_plugins => { @@ -59,6 +63,9 @@ mackerel_agent::apikey: 'Your API Key' mackerel_agent::roles: - 'service:web' - 'service:database' +mackerel_agent::host_status: + on_start: working + on_stop: poweroff 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 98db914..7f7d280 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,6 +4,7 @@ $ensure = present, $apikey = undef, $roles = undef, + $host_status = undef, $metrics_plugins = {}, $check_plugins = {} ) { diff --git a/manifests/init.pp b/manifests/init.pp index bb5ca3d..562a9fc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,6 +16,10 @@ # Name of roles to which the server is assigned # Defaults to undefined # +# [*host_status*] +# Set the host's status +# Defaults to undefined +# # [*service_ensure*] # Whether you want to mackerel-agent daemon to start up # Defaults to running @@ -43,8 +47,12 @@ # === Examples # # class { 'mackerel_agent': -# apikey => 'Your API Key' -# roles => ['service:web', 'service:database'] +# apikey => 'Your API Key', +# roles => ['service:web', 'service:database'], +# host_status => { +# on_start => 'working', +# on_stop => 'poweroff' +# }, # use_metrics_plugins => true, # use_check_plugins => true, # metrics_plugins => { @@ -69,6 +77,7 @@ $ensure = present, $apikey = undef, $roles = undef, + $host_status = undef, $service_ensure = running, $service_enable = true, $use_metrics_plugins = undef, @@ -86,6 +95,10 @@ validate_array($roles) } + if $host_status != undef { + validate_hash($host_status) + } + if $apikey == undef { crit('apikey must be specified in the class paramerter.') } else { @@ -98,6 +111,7 @@ class { 'mackerel_agent::config': apikey => $apikey, roles => $roles, + host_status => $host_status, 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 e8e040a..8f72f4e 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -21,4 +21,12 @@ it { should contain_file('mackerel-agent.conf').with_ensure('present').with_content(%r{^roles = \["service:web", "service:database"\]$}) } end + + context 'with host_status' do + let(:params) do + { :host_status => {'on_start' => 'working', 'on_stop' => 'poweroff'} } + end + + it { should contain_file('mackerel-agent.conf').with_ensure('present').with_content(%r{^\[host_status\]\non_start = "working"\non_stop = "poweroff"$}) } + end end diff --git a/templates/mackerel-agent.conf.erb b/templates/mackerel-agent.conf.erb index 1207601..1cbe13e 100644 --- a/templates/mackerel-agent.conf.erb +++ b/templates/mackerel-agent.conf.erb @@ -13,6 +13,12 @@ roles = [<%= @roles.map {|r| %{"#{r}"} }.join(', ') %>] # Include other config files include = "/etc/mackerel-agent/conf.d/*.conf" +<% if @host_status -%> +[host_status] +on_start = "<%= @host_status['on_start'] %>" +on_stop = "<%= @host_status['on_stop'] %>" +<% end %> + # Configuration for connection # [connection] # post_metrics_dequeue_delay_seconds = 30 # delay for dequeuing from buffer queue (max value: 59)