Skip to content

Commit

Permalink
fix #684 Add new feature windowseventlog
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Sep 10, 2021
1 parent 807df10 commit 7d63aa7
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
50 changes: 50 additions & 0 deletions manifests/feature/windowseventlog.pp
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,
}
}

44 changes: 44 additions & 0 deletions spec/classes/windowseventlog_spec.rb
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

0 comments on commit 7d63aa7

Please sign in to comment.