Skip to content

Commit fe76980

Browse files
author
Lennart Betz
committed
rewrite feature syslog to use objects
1 parent f32cde9 commit fe76980

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

manifests/feature/syslog.pp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# == Class: icinga2::feature::syslog
2+
#
3+
# This module configures the Icinga2 feature syslog.
4+
#
5+
# === Parameters
6+
#
7+
# [*ensure*]
8+
# Set to present enables the feature syslog, absent disables it. Defaults to present.
9+
#
10+
# [*severity*]
11+
# You can choose the log severity between information, notice, warning or debug.
12+
# Defaults to warning.
13+
#
14+
# === Authors
15+
#
16+
# Icinga Development Team <[email protected]>
17+
#
18+
class icinga2::feature::syslog(
19+
$ensure = present,
20+
$severity = 'warning',
21+
) {
22+
23+
include ::icinga2::params
24+
25+
$conf_dir = $::icinga2::params::conf_dir
26+
27+
# validation
28+
validate_re($ensure, [ '^present$', '^absent$' ],
29+
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
30+
validate_re($severity, ['^information$','^notice$','^warning$','^debug$'])
31+
32+
# compose attributes
33+
$attrs = {
34+
severity => $severity,
35+
}
36+
37+
# create object
38+
icinga2::object { "icinga2::object::SyslogLogger::syslog":
39+
object_name => 'syslog',
40+
object_type => 'SyslogLogger',
41+
attrs => $attrs,
42+
target => "${conf_dir}/features-available/syslog.conf",
43+
order => '10',
44+
notify => $ensure ? {
45+
'present' => Class['::icinga2::service'],
46+
default => undef,
47+
},
48+
}
49+
50+
# manage feature
51+
icinga2::feature { 'syslog':
52+
ensure => $ensure,
53+
}
54+
}
55+

spec/classes/syslog_spec.rb

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
require 'spec_helper'
2+
3+
describe('icinga2::feature::syslog', :type => :class) do
4+
let(:pre_condition) { [
5+
"class { 'icinga2': features => [], }"
6+
] }
7+
8+
on_supported_os.each do |os, facts|
9+
let :facts do
10+
facts
11+
end
12+
13+
14+
context "#{os} with ensure => present" do
15+
let(:params) { {:ensure => 'present'} }
16+
17+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) }
18+
19+
it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog')
20+
.with({ 'target' => '/etc/icinga2/features-available/syslog.conf' })
21+
.that_notifies('Class[icinga2::service]') }
22+
end
23+
24+
25+
context "#{os} with ensure => absent" do
26+
let(:params) { {:ensure => 'absent'} }
27+
28+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'absent'}) }
29+
30+
it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog')
31+
.with({ 'target' => '/etc/icinga2/features-available/syslog.conf' }) }
32+
end
33+
34+
35+
context "#{os} with all defaults" do
36+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) }
37+
38+
it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog')
39+
.with({ 'target' => '/etc/icinga2/features-available/syslog.conf' })
40+
.with_content(/severity = "warning"/) }
41+
end
42+
43+
44+
context "#{os} with severity => notice" do
45+
let(:params) { {:severity => 'notice'} }
46+
47+
it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog')
48+
.with({ 'target' => '/etc/icinga2/features-available/syslog.conf' })
49+
.with_content(/severity = "notice"/) }
50+
end
51+
52+
53+
context "#{os} with severity => foo (not a valid value)" do
54+
let(:params) { {:severity => 'foo'} }
55+
56+
it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) }
57+
end
58+
end
59+
60+
61+
context 'Windows 2012 R2 with ensure => present' do
62+
let(:facts) { {
63+
:kernel => 'Windows',
64+
:architecture => 'x86_64',
65+
:osfamily => 'Windows',
66+
:operatingsystem => 'Windows',
67+
:operatingsystemmajrelease => '2012 R2'
68+
} }
69+
let(:params) { {:ensure => 'present'} }
70+
71+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) }
72+
73+
it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog')
74+
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' })
75+
.that_notifies('Class[icinga2::service]') }
76+
end
77+
78+
79+
context 'Windows 2012 R2 with ensure => absent' do
80+
let(:facts) { {
81+
:kernel => 'Windows',
82+
:architecture => 'x86_64',
83+
:osfamily => 'Windows',
84+
:operatingsystem => 'Windows',
85+
:operatingsystemmajrelease => '2012 R2'
86+
} }
87+
let(:params) { {:ensure => 'absent'} }
88+
89+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'absent'}) }
90+
91+
it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog')
92+
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' }) }
93+
end
94+
95+
96+
context "Windows 2012 R2 with all defaults" do
97+
let(:facts) { {
98+
:kernel => 'Windows',
99+
:architecture => 'x86_64',
100+
:osfamily => 'Windows',
101+
:operatingsystem => 'Windows',
102+
:operatingsystemmajrelease => '2012 R2'
103+
} }
104+
it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) }
105+
106+
it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog')
107+
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' })
108+
.with_content(/severity = "warning"/) }
109+
end
110+
111+
112+
context 'Windows 2012 R2 with severity => notice' do
113+
let(:facts) { {
114+
:kernel => 'Windows',
115+
:architecture => 'x86_64',
116+
:osfamily => 'Windows',
117+
:operatingsystem => 'Windows',
118+
:operatingsystemmajrelease => '2012 R2'
119+
} }
120+
let(:params) { {:severity => 'notice'} }
121+
122+
it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog')
123+
.with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' })
124+
.with_content(/severity = "notice"/) }
125+
end
126+
127+
128+
context 'Windows 2012 R2 with severity => foo (not a valid value)' do
129+
let(:facts) { {
130+
:kernel => 'Windows',
131+
:architecture => 'x86_64',
132+
:osfamily => 'Windows',
133+
:operatingsystem => 'Windows',
134+
:operatingsystemmajrelease => '2012 R2'
135+
} }
136+
let(:params) { {:severity => 'foo'} }
137+
138+
it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) }
139+
end
140+
end

0 commit comments

Comments
 (0)