Skip to content

Commit

Permalink
fix voxpupuli#242 enable_ha for notification feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz authored and n00by committed Apr 26, 2018
1 parent bb937c8 commit 320065f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,9 @@ Enables or disables the `notification` feature.
##### `ensure`
Either `present` or `absent`. Defines if the feature `notification` should be enabled. Defaults to `present`.

##### `enable_ha`
Notifications are load-balanced amongst all nodes in a zone. By default this functionality is enabled. If your nodes should send out notifications independently from any other nodes (this will cause duplicated notifications if not properly handled!), you can set enable_ha to false.

#### Class: `icinga2::feature::command`
Enables or disables the `command` feature.

Expand Down
19 changes: 17 additions & 2 deletions manifests/feature/notification.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@
# [*ensure*]
# Set to present enables the feature notification, absent disabled it. Defaults to present.
#
# [*enable_ha*]
# Notifications are load-balanced amongst all nodes in a zone. By default this
# functionality is enabled. If your nodes should send out notifications independently
# from any other nodes (this will cause duplicated notifications if not properly
# handled!), you can set enable_ha to false.
#
#
class icinga2::feature::notification(
$ensure = present,
$ensure = present,
$enable_ha = undef,
) {

$conf_dir = $::icinga2::params::conf_dir

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
if $enable_ha {
validate_bool($enable_ha)
}

# compose attributes
$attrs = {
enable_ha => $enable_ha,
}

# create object
icinga2::object { 'icinga2::object::NotificationComponent::notification':
object_name => 'notification',
object_type => 'NotificationComponent',
attrs => {},
attrs => delete_undef_values($attrs),
target => "${conf_dir}/features-available/notification.conf",
order => '10',
notify => $ensure ? {
Expand Down
50 changes: 50 additions & 0 deletions spec/classes/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@
it { is_expected.to contain_icinga2__object('icinga2::object::NotificationComponent::notification')
.with({ 'target' => '/etc/icinga2/features-available/notification.conf' }) }
end


context "#{os} with enable_ha = true" do
let(:params) { {:enable_ha => true} }

it { is_expected.to contain_concat__fragment('icinga2::object::NotificationComponent::notification')
.with({ 'target' => '/etc/icinga2/features-available/notification.conf' })
.with_content(/enable_ha = true\n/) }
end


context "#{os} with enable_ha = false" do
let(:params) { {:enable_ha => false} }

it { is_expected.to contain_concat__fragment('icinga2::object::NotificationComponent::notification')
.with({ 'target' => '/etc/icinga2/features-available/notification.conf' })
.with_content(/enable_ha = false\n/) }
end


context "#{os} with enable_ha = foo (not a valid boolean)" do
let(:params) { {:enable_ha => 'foo'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }
end
end
end

Expand Down Expand Up @@ -75,4 +100,29 @@
# it { is_expected.to contain_icinga2__object('icinga2::object::NotificationComponent::notification')
# .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/notification.conf' }) }
end


context "Windows 2012 R2 with enable_ha = true" do
let(:params) { {:enable_ha => true} }

it { is_expected.to contain_concat__fragment('icinga2::object::NotificationComponent::notification')
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/notification.conf' })
.with_content(/enable_ha = true\r\n/) }
end


context "Windows 2012 R2 with enable_ha = false" do
let(:params) { {:enable_ha => false} }

it { is_expected.to contain_concat__fragment('icinga2::object::NotificationComponent::notification')
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/notification.conf' })
.with_content(/enable_ha = false\r\n/) }
end


context "Windows 2012 R2 with enable_ha = foo (not a valid boolean)" do
let(:params) { {:enable_ha => 'foo'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }
end
end

0 comments on commit 320065f

Please sign in to comment.