Skip to content

Commit

Permalink
Added sensu client support for ec2(sensu#772), chef (sensu#773) and p…
Browse files Browse the repository at this point in the history
…uppet (sensu#774)
  • Loading branch information
alvagante committed Sep 1, 2017
1 parent 0ebe548 commit f6412aa
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 2 deletions.
70 changes: 70 additions & 0 deletions lib/puppet/type/sensu_client_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,77 @@ def insync?(is)
defaultto {}
end

newproperty(:ec2) do
desc "Configure ec2 integration on Sensu client."
include PuppetX::Sensu::ToType

munge do |value|
value.each { |k, v| value[k] = to_type(v) }
end

def insync?(is)
if defined? @should[0]
if is == @should[0].each { |k, v| value[k] = to_type(v) }
true
else
false
end
else
true
end
end

defaultto {}
end

newproperty(:chef) do
desc "Configure Chef integration on Sensu client."
include PuppetX::Sensu::ToType

munge do |value|
value.each { |k, v| value[k] = to_type(v) }
end

def insync?(is)
if defined? @should[0]
if is == @should[0].each { |k, v| value[k] = to_type(v) }
true
else
false
end
else
true
end
end

defaultto {}
end

newproperty(:puppet) do
desc "Configure Puppet integration on Sensu client."
include PuppetX::Sensu::ToType

munge do |value|
value.each { |k, v| value[k] = to_type(v) }
end

def insync?(is)
if defined? @should[0]
if is == @should[0].each { |k, v| value[k] = to_type(v) }
true
else
false
end
else
true
end
end

defaultto {}
end

autorequire(:package) do
['sensu']
end

end
3 changes: 3 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
deregistration => $::sensu::client_deregistration,
http_socket => $::sensu::client_http_socket,
servicenow => $::sensu::client_servicenow,
ec2 => $::sensu::client_ec2,
chef => $::sensu::client_chef,
puppet => $::sensu::client_puppet,
}
}
15 changes: 15 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@
# parameters, as described in:
# https://sensuapp.org/docs/latest/reference/clients.html#servicenow-attributes
#
# @param client_ec2 Client ec2 configuration. Supported only on Sensu
# Enterprise. It expects an Hash with valid paramters as described in:
# https://sensuapp.org/docs/latest/reference/clients.html#ec2-attributes
#
# @param client_chef Client chef configuration. Supported only on Sensu
# Enterprise. It expects an Hash with valid paramters as described in:
# https://sensuapp.org/docs/latest/reference/clients.html#chef-attributes
#
# @param client_puppet Client puppet configuration. Supported only on Sensu
# Enterprise. It expects an Hash with valid paramters as described in:
# https://sensuapp.org/docs/latest/reference/clients.html#puppet-attributes
#
# @param safe_mode Force safe mode for checks
#
# @param plugins Plugins to install on the node
Expand Down Expand Up @@ -354,6 +366,9 @@
Hash $client_keepalive = {},
Hash $client_http_socket = {},
Hash $client_servicenow = {},
Hash $client_ec2 = {},
Hash $client_chef = {},
Hash $client_puppet = {},
Boolean $safe_mode = false,
Variant[String,Array,Hash] $plugins = [],
Hash $plugins_defaults = {},
Expand Down
58 changes: 56 additions & 2 deletions spec/classes/sensu_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
:custom => {},
:http_socket => {},
:servicenow => {},
:ec2 => {},
:chef => {},
:puppet => {},
) }

it { should contain_sensu_client_config(title).without_redact }
Expand Down Expand Up @@ -49,7 +52,10 @@
:safe_mode => true,
:client_custom => { 'bool' => true, 'foo' => 'bar' },
:client_http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 },
:client_servicenow => { 'configuration_item' => { 'name' => 'Sample', 'os_version' => '6' } }
:client_servicenow => { 'configuration_item' => { 'name' => 'Sample', 'os_version' => '6' } },
:client_ec2 => { 'instance_id' => 'i-2131221' },
:client_chef => { 'nodename' => 'test' },
:client_puppet => { 'nodename' => 'test' },
} }

it { should contain_sensu_client_config(title).with( {
Expand All @@ -62,7 +68,10 @@
:safe_mode => true,
:custom => { 'bool' => true, 'foo' => 'bar' },
:http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 },
:servicenow => { 'configuration_item' => { 'name' => 'Sample', 'os_version' => '6' } }
:servicenow => { 'configuration_item' => { 'name' => 'Sample', 'os_version' => '6' } },
:ec2 => { 'instance_id' => 'i-2131221' },
:chef => { 'nodename' => 'test' },
:puppet => { 'nodename' => 'test' },
} ) }
end

Expand Down Expand Up @@ -126,6 +135,51 @@
it { is_expected.to contain_sensu_client_config(title).with(servicenow: servicenow) }
end
end

describe 'ec2' do
ec2 = {
'instance-id' => 'i-424242',
'allowed_instance_states' => [ 'pending','running','rebooting'],
'region' => 'us-west-1',
'access_key_id' => 'AlygD0X6Z4Xr2m3gl70J',
'secret_access_key' => 'y9Jt5OqNOqdy5NCFjhcUsHMb6YqSbReLAJsy4d6obSZIWySv',
'timeout' => '30',
}
context "=> {'ec2' => 'custom hash'}" do
let(:params_override) { {client_ec2: ec2} }
it { is_expected.to contain_sensu_client_config(title).with(ec2: ec2) }
end
end

describe 'chef' do
chef = {
'nodename' => 'test',
'endpoint' => 'https://api.chef.io/organizations/example',
'flavor' => 'enterprise',
'client' => 'sensu-server',
'key' => '/etc/chef/i-424242.pem',
'ssl_verify' => 'false',
'proxy_address' => 'proxy.example.com',
'proxy_port' => '8080',
'proxy_username' => 'chef',
'proxy_password' => 'secret',
'timeout' => '30',
}
context "=> {'chef' => 'custom hash'}" do
let(:params_override) { {client_chef: chef} }
it { is_expected.to contain_sensu_client_config(title).with(chef: chef) }
end
end

describe 'puppet' do
puppet = {
'nodename' => 'test',
}
context "=> {'puppet' => 'custom hash'}" do
let(:params_override) { {client_puppet: puppet} }
it { is_expected.to contain_sensu_client_config(title).with(puppet: puppet) }
end
end
end

context 'purge config' do
Expand Down
57 changes: 57 additions & 0 deletions spec/unit/sensu_client_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,61 @@
end
end

describe 'ec2' do
subject { described_class.new(resource_hash)[:ec2] }
context 'in the default case' do
it { is_expected.to be_nil }
end
ec2 = {
'instance-id' => 'i-424242',
'allowed_instance_states' => [ 'pending','running','rebooting'],
'region' => 'us-west-1',
'access_key_id' => 'AlygD0X6Z4Xr2m3gl70J',
'secret_access_key' => 'y9Jt5OqNOqdy5NCFjhcUsHMb6YqSbReLAJsy4d6obSZIWySv',
'timeout' => '30',
}
context '=> custom values' do
let(:resource_hash_override) { {ec2: ec2} }
it { is_expected.to eq(ec2) }
end
end

describe 'chef' do
subject { described_class.new(resource_hash)[:chef] }
context 'in the default case' do
it { is_expected.to be_nil }
end
chef = {
'nodename' => 'test',
'endpoint' => 'https://api.chef.io/organizations/example',
'flavor' => 'enterprise',
'client' => 'sensu-server',
'key' => '/etc/chef/i-424242.pem',
'ssl_verify' => 'false',
'proxy_address' => 'proxy.example.com',
'proxy_port' => '8080',
'proxy_username' => 'chef',
'proxy_password' => 'secret',
'timeout' => '30',
}
context '=> custom values' do
let(:resource_hash_override) { {chef: chef} }
it { is_expected.to eq(chef) }
end
end

describe 'puppet' do
subject { described_class.new(resource_hash)[:puppet] }
context 'in the default case' do
it { is_expected.to be_nil }
end
puppet = {
'nodename' => 'test',
}
context '=> custom values' do
let(:resource_hash_override) { {puppet: puppet} }
it { is_expected.to eq(puppet) }
end
end

end

0 comments on commit f6412aa

Please sign in to comment.