-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #684 Add new feature windowseventlog
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# @summary | ||
# Configures the Icinga 2 feature windowseventlog. | ||
# | ||
# @param [Enum['absent', 'present']] ensure | ||
# Set to present enables the feature windowseventlog, absent disables it. | ||
# | ||
# @param [Icinga2::LogSeverity] severity | ||
# You can choose the log severity between information, notice, warning or debug. | ||
# | ||
class icinga2::feature::windowseventlog( | ||
Enum['absent', 'present'] $ensure = present, | ||
Icinga2::LogSeverity $severity = 'warning', | ||
) { | ||
|
||
if ! defined(Class['::icinga2']) { | ||
fail('You must include the icinga2 base class before using any icinga2 feature class!') | ||
} | ||
|
||
if $facts['os']['family'] != 'windows' and $ensure != 'absent' { | ||
fail('The feature windowseventlogs is only supported on Windows platforms!') | ||
} | ||
|
||
$conf_dir = $::icinga2::globals::conf_dir | ||
$_notify = $ensure ? { | ||
'present' => Class['::icinga2::service'], | ||
default => undef, | ||
} | ||
|
||
# compose attributes | ||
$attrs = { | ||
severity => $severity, | ||
} | ||
|
||
# create object | ||
icinga2::object { 'icinga2::object::WindowsEventLogLogger::windowseventlog': | ||
object_name => 'windowseventlog', | ||
object_type => 'WindowsEventLogLogger', | ||
attrs => delete_undef_values($attrs), | ||
attrs_list => keys($attrs), | ||
target => "${conf_dir}/features-available/windowseventlog.conf", | ||
order => 10, | ||
notify => $_notify, | ||
} | ||
|
||
# manage feature | ||
icinga2::feature { 'windowseventlog': | ||
ensure => $ensure, | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe('icinga2::feature::windowseventlog', type: :class) do | ||
let(:pre_condition) do | ||
[ | ||
"class { 'icinga2': features => [] }", | ||
] | ||
end | ||
|
||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
let(:facts) do | ||
facts | ||
end | ||
|
||
case facts[:kernel] | ||
when 'windows' | ||
let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } | ||
|
||
context 'with defaults' do | ||
it { is_expected.to contain_icinga2__feature('windowseventlog').with({ 'ensure' => 'present' }) } | ||
|
||
it { | ||
is_expected.to contain_icinga2__object('icinga2::object::WindowsEventLogLogger::windowseventlog').with( | ||
{ 'target' => "#{icinga2_conf_dir}/features-available/windowseventlog.conf" }, | ||
).that_notifies('Class[icinga2::service]') | ||
} | ||
end | ||
else | ||
it { is_expected.to raise_error(Puppet::Error, %r{only supported on Windows platforms}) } | ||
end | ||
|
||
context 'with ensure => absent' do | ||
let(:params) do | ||
{ | ||
ensure: 'absent', | ||
} | ||
end | ||
|
||
it { is_expected.to contain_icinga2__feature('windowseventlog').with({ 'ensure' => 'absent' }) } | ||
end | ||
end | ||
end | ||
end |