Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to configure host status #17

Merged
merged 1 commit into from
Jun 8, 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$ensure = present,
$apikey = undef,
$roles = undef,
$host_status = undef,
$metrics_plugins = {},
$check_plugins = {}
) {
Expand Down
18 changes: 16 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand All @@ -69,6 +77,7 @@
$ensure = present,
$apikey = undef,
$roles = undef,
$host_status = undef,
$service_ensure = running,
$service_enable = true,
$use_metrics_plugins = undef,
Expand All @@ -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 {
Expand All @@ -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']
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 @@ -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
6 changes: 6 additions & 0 deletions templates/mackerel-agent.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down