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

(#495) Notify Service[sensu-enterprise] from Sensu::Check resources #720

Merged
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
8 changes: 7 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
server.vm.network :forwarded_port, guest: 3000, host: 3000, auto_correct: true
server.vm.network :forwarded_port, guest: 15672, host: 15672, auto_correct: true
server.vm.provision :shell, :path => "tests/provision_basic_el.sh"
server.vm.provision :shell, :path => "tests/provision_enterprise_server.sh"
server.vm.provision :shell,
:path => "tests/provision_enterprise_server.sh",
:env => {
'FACTER_SE_USER' => ENV['FACTER_SE_USER'].to_s,
'FACTER_SE_PASS' => ENV['FACTER_SE_PASS'].to_s,
}

server.vm.provision :shell, :path => "tests/rabbitmq.sh"
end

Expand Down
11 changes: 7 additions & 4 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ def should
def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-client]",
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
"Service[sensu-client]",
"Service[sensu-server]",
"Service[sensu-enterprise]",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Service[sensu-enterprise] is not in the catalog, because we aren't using enterprise, does this cause a problem?

Copy link
Collaborator Author

@jeffmccune jeffmccune Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect no problem becauseArray#select filters out the resource ref when absent from the catalog.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you verified with vagrant up ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, will do so now.

Copy link
Collaborator Author

@jeffmccune jeffmccune Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghoneycutt I modified the provisioning manifest for sensu-server-enterprise to manage Service[sensu-enterprise] instead of Service[sensu-server]. Take a look at this change in 1d694e4, I assumed tests/sensu-server-enterprise.pp is intended to setup sensu-enterprise.

With vagrant up sensu-server, the notification doesn't cause a problem as we expect. With vagrant up sensu-server-enterprise, the notification does properly notify Service[sensu-enterprise] when a managed sensu::check resource changes state.

].select { |ref| c.resource(ref) }
end
end

ensurable do
Expand Down
11 changes: 7 additions & 4 deletions lib/puppet/type/sensu_check_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-client]",
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-client]',
'Service[sensu-server]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

ensurable do
Expand Down
11 changes: 7 additions & 4 deletions lib/puppet/type/sensu_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-api]",
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-api]',
'Service[sensu-server]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

ensurable do
Expand Down
12 changes: 9 additions & 3 deletions lib/puppet/type/sensu_handler.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..',
'puppet_x', 'sensu', 'boolean_property.rb'))

Puppet::Type.newtype(:sensu_handler) do
@doc = ""

def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-server]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

ensurable do
Expand Down
9 changes: 6 additions & 3 deletions lib/puppet/type/sensu_mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-server]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

ensurable do
Expand Down
14 changes: 8 additions & 6 deletions lib/puppet/type/sensu_rabbitmq_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
def initialize(*args)
super(*args)

self[:notify] = [
'Service[sensu-server]',
'Service[sensu-client]',
'Service[sensu-api]',
'Service[sensu-enterprise]'
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-server]',
'Service[sensu-client]',
'Service[sensu-api]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

def has_cluster?
Expand Down
11 changes: 7 additions & 4 deletions lib/puppet/type/sensu_redis_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
def initialize(*args)
super *args

self[:notify] = [
"Service[sensu-api]",
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
if c = catalog
self[:notify] = [
'Service[sensu-api]',
'Service[sensu-server]',
'Service[sensu-enterprise]',
].select { |ref| c.resource(ref) }
end
end

def has_sentinels?
Expand Down
32 changes: 32 additions & 0 deletions spec/unit/sensu_check_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Puppet::Type.type(:sensu_check_config) do
let(:resource_hash) do
{
:title => 'foo.example.com',
:catalog => Puppet::Resource::Catalog.new
}
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'foo.example.com',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
22 changes: 22 additions & 0 deletions spec/unit/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,26 @@
# ).to eq nil
# end
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'foo.example.com',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
32 changes: 32 additions & 0 deletions spec/unit/sensu_extension_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Puppet::Type.type(:sensu_extension) do
let(:resource_hash) do
{
:title => 'Emanon',
:catalog => Puppet::Resource::Catalog.new
}
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'Emanon',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
32 changes: 32 additions & 0 deletions spec/unit/sensu_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Puppet::Type.type(:sensu_handler) do
let(:resource_hash) do
{
:title => 'myhandler',
:catalog => Puppet::Resource::Catalog.new
}
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'myhandler',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
32 changes: 32 additions & 0 deletions spec/unit/sensu_mutator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Puppet::Type.type(:sensu_mutator) do
let(:resource_hash) do
{
:title => 'mymutator',
:catalog => Puppet::Resource::Catalog.new
}
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'mymutator',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
22 changes: 22 additions & 0 deletions spec/unit/sensu_rabbitmq_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,26 @@ def create_type_instance(resource_hash)
end
end
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'foo.example.com',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
21 changes: 21 additions & 0 deletions spec/unit/sensu_redis_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,25 @@ def create_type_instance(resource_hash)
end
end

describe 'notifications' do
context 'when managing sensu-enterprise (#495)' do
let(:service_resource) do
Puppet::Type.type(:service).new(name: 'sensu-enterprise')
end
let(:resource_hash) do
c = Puppet::Resource::Catalog.new
c.add_resource(service_resource)
{
:title => 'foo.example.com',
:catalog => c
}
end

it 'notifies Service[sensu-enterprise]' do
notify_list = described_class.new(resource_hash)[:notify]
# compare the resource reference strings, the object identities differ.
expect(notify_list.map(&:ref)).to eq [service_resource.ref]
end
end
end
end
7 changes: 7 additions & 0 deletions tests/provision_enterprise_server.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

if [ -z "${FACTER_SE_USER:-}" ]; then
echo "ERROR: You must export FACTER_SE_USER and FACTER_SE_PASS" >&2
echo "ERROR: In the shell that executes vagrant up" >&2
exit 1
fi
echo "FACTER_SE_USER=$FACTER_SE_USER"

# setup module dependencies
puppet module install puppetlabs/rabbitmq

Expand Down
11 changes: 6 additions & 5 deletions tests/sensu-server-enterprise.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
mode => '0600',
}

# NOTE: When testing sensu enterprise, provide the SE_USER and SE_PASS to use
# with the online repository using the FACTER_SE_USER and FACTER_SE_PASS
# environment variables. An effective way to manage this is with `direnv`
class { '::sensu':
install_repo => true,
server => true,
enterprise => true,
enterprise_user => $facts['se_user'],
enterprise_pass => $facts['se_pass'],
manage_services => true,
manage_user => true,
rabbitmq_password => 'correct-horse-battery-staple',
rabbitmq_vhost => '/sensu',
api => true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the API portion removed?

api_user => 'admin',
api_password => 'secret',
client_address => $::ipaddress_eth1,
# enterprise options
api_ssl_port => '4568',
api_ssl_keystore_file => '/etc/sensu/api.keystore',
api_ssl_keystore_password => 'sensutest',
Expand Down