Skip to content

Commit

Permalink
Added sensu client params sensu#772 sensu#773 sensu#774 sensu#775
Browse files Browse the repository at this point in the history
Added servicenow support to client config (sensu#775)
Added ec2 support to client config (sensu#772)
Added chef  support to client config (sensu#773)
Added puppet support to client config (sensu#774)
  • Loading branch information
alvagante committed Sep 1, 2017
1 parent 8ddd9e6 commit b3585f3
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 10 deletions.
93 changes: 93 additions & 0 deletions lib/puppet/type/sensu_client_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,100 @@ def insync?(is)
defaultto {}
end

newproperty(:servicenow) do
desc "Configure Service Now 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(: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
4 changes: 4 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@
deregister => $::sensu::client_deregister,
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,
}
}
27 changes: 25 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,28 @@
# status, and issued timestamp. The following attributes are provided as
# recommendations for controlling client deregistration behavior.
#
# @param client_keepalive Client keepalive config
# @param client_keepalive Client keepalive configuration
#
# @param client_http_socket Client http_socket config
# @param client_http_socket Client http_socket configuration. Must be an Hash of
# parameters as described in:
# https://sensuapp.org/docs/latest/reference/clients.html#http-socket-attributes
#
# @param client_servicenow Client servicenow configuration. Supported only
# on Sensu Enterprise. It expects an Hash with a single key named
# 'configuration_item' containing an Hash of 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
#
Expand Down Expand Up @@ -346,6 +365,10 @@
Variant[Undef,Hash] $client_deregistration = undef,
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
85 changes: 77 additions & 8 deletions spec/classes/sensu_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
context 'config' do
context 'defaults' do
let(:params) { { :client => true } }
it { should contain_sensu_client_config('host.domain.com').with(
it { should contain_sensu_client_config(title).with(
:ensure => 'present',
:client_name => 'host.domain.com',
:address => '2.3.4.5',
:socket => { 'bind' => '127.0.0.1', 'port' => 3030 },
:subscriptions => [],
:custom => {},
:http_socket => {},
:servicenow => {},
:ec2 => {},
:chef => {},
:puppet => {},
) }

it { should contain_sensu_client_config('host.domain.com').without_redact }
it { should contain_sensu_client_config('host.domain.com').without_deregister }
it { should contain_sensu_client_config('host.domain.com').without_deregistration }
it { should contain_sensu_client_config(title).without_redact }
it { should contain_sensu_client_config(title).without_deregister }
it { should contain_sensu_client_config(title).without_deregistration }
end # defaults

context 'setting config params' do
Expand All @@ -47,10 +51,14 @@
:client_name => 'myclient',
:safe_mode => true,
:client_custom => { 'bool' => true, 'foo' => 'bar' },
:client_http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 }
:client_http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 },
: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('host.domain.com').with( {
it { should contain_sensu_client_config(title).with( {
:ensure => 'present',
:client_name => 'myclient',
:address => '1.2.3.4',
Expand All @@ -59,7 +67,11 @@
:redact => ['password'],
:safe_mode => true,
:custom => { 'bool' => true, 'foo' => 'bar' },
:http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 }
:http_socket => { 'bind' => '127.0.0.1', 'port' => 3031 },
:servicenow => { 'configuration_item' => { 'name' => 'Sample', 'os_version' => '6' } },
:ec2 => { 'instance_id' => 'i-2131221' },
:chef => { 'nodename' => 'test' },
:puppet => { 'nodename' => 'test' },
} ) }
end

Expand Down Expand Up @@ -109,8 +121,65 @@
let(:params_override) { {client_http_socket: http_socket} }
it { is_expected.to contain_sensu_client_config(title).with(http_socket: http_socket) }
end
end

describe 'servicenow' do
servicenow = {
'configuration_item' => {
'name' => 'ServiceNow test',
'os_version' => '16.04'
}
}
context "=> {'servicenow' => 'custom hash'}" do
let(:params_override) { {client_servicenow: servicenow} }
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

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
74 changes: 74 additions & 0 deletions spec/unit/sensu_client_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
end
end
end

describe 'http_socket' do
subject { described_class.new(resource_hash)[:http_socket] }
context 'in the default case' do
Expand All @@ -77,7 +78,80 @@
let(:resource_hash_override) { {http_socket: http_socket} }
it { is_expected.to eq(http_socket) }
end
end

describe 'servicenow' do
subject { described_class.new(resource_hash)[:servicenow] }
context 'in the default case' do
it { is_expected.to be_nil }
end
servicenow = {
'configuration_item' => {
'name' => 'test server',
'os_version' => '7',
}
}
context '=> custom values' do
let(:resource_hash_override) { {servicenow: servicenow} }
it { is_expected.to eq(servicenow) }
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
19 changes: 19 additions & 0 deletions tests/sensu-client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,31 @@
$ip = $facts['networking']['ip']
}

$client_ec2 = {
'instance-id' => 'i-2102113',
}
$client_puppet = {
'nodename' => $::fqdn,
}
$client_chef = {
'nodename' => $::fqdn,
}
$client_servicenow = {
'configuration_item' => {
'name' => 'ServiceNow test',
'os_version' => '16.04',
},
}
class { '::sensu':
rabbitmq_password => 'correct-horse-battery-staple',
rabbitmq_host => '192.168.56.10',
rabbitmq_vhost => '/sensu',
subscriptions => 'all',
client_address => $ip,
client_ec2 => $client_ec2,
client_chef => $client_chef,
client_puppet => $client_puppet,
client_servicenow => $client_servicenow,
filters => $filters,
filter_defaults => $filter_defaults,
}
Expand Down

0 comments on commit b3585f3

Please sign in to comment.