Skip to content

Commit

Permalink
FIxed sensu_client_subscription type
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Nov 21, 2017
1 parent a0ef8c4 commit f8b25fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/sensu_client_subscription/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def flush
end

def config_file
"#{resource[:base_path]}/subscription_#{resource[:name]}.json"
"#{resource[:base_path]}/#{resource[:file_name]}"
end

def pre_create
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_client_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def initialize(*args)
defaultto '/etc/sensu/conf.d/'
end

newparam(:file_name) do
desc "The name of the client config file"
defaultto { "subscription_" + resource.name + ".json" }
end

newproperty(:subscriptions, :array_matching => :all) do
desc "Subscriptions included, defaults to resource name"

Expand Down
6 changes: 4 additions & 2 deletions manifests/subscription.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

include ::sensu

$sanitized_name=regsubst($name, '[^0-9A-Za-z.\-]', '_', 'G')
$sanitized_name=regsubst($name, '[^0-9A-Za-z.-]', '_', 'G')

file { "${::sensu::conf_dir}/subscription_${sanitized_name}.json":
ensure => $ensure,
owner => $::sensu::user,
Expand All @@ -22,9 +23,10 @@
before => Sensu_client_subscription[$name],
}

sensu_client_subscription { $sanitized_name:
sensu_client_subscription { $name:
ensure => $ensure,
base_path => $::sensu::conf_dir,
file_name => "subscription_${sanitized_name}.json",
custom => $custom,
notify => $::sensu::client_service,
}
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/sensu_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class {'sensu':
context 'with char : in title' do
let(:title) { 'roundrobin:foo' }

it { should contain_sensu_client_subscription('roundrobin_foo').with(:ensure => 'present' ) }
it { should contain_sensu_client_subscription('roundrobin:foo').with(:ensure => 'present', :file_name => 'subscription_roundrobin_foo.json') }
it { should contain_file('/etc/sensu/conf.d/subscription_roundrobin_foo.json').with(:ensure => 'present' ) }
end

Expand All @@ -66,7 +66,7 @@ class {'sensu':
}
}

it { should contain_sensu_client_subscription('roundrobin_foo').with(:ensure => 'present' ) }
it { should contain_sensu_client_subscription('roundrobin:foo').with(:ensure => 'present' , :file_name => 'subscription_roundrobin_foo.json') }
it { should contain_file('C:/opt/sensu/conf.d/subscription_roundrobin_foo.json').with(:ensure => 'present' ) }
end
end

0 comments on commit f8b25fe

Please sign in to comment.