Skip to content

Commit 236715b

Browse files
TuningYourCodepcfens
authored andcommitted
Add system module
1 parent 2a18b0f commit 236715b

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

manifests/module/system.pp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# filebeat::module::system
2+
#
3+
# @summary
4+
# This class manages the Filebeat system module.
5+
#
6+
# @example
7+
# class { 'filebeat::module::system':
8+
# syslog_enabled => true,
9+
# syslog_paths => [
10+
# '/var/log/syslog',
11+
# ],
12+
# auth_enabled => true,
13+
# auth_paths => [
14+
# '/var/log/auth.log',
15+
# ],
16+
# }
17+
#
18+
# @param syslog_enabled
19+
# A boolean value to enable or disable the syslog module.
20+
# @param syslog_paths
21+
# An optional array of paths to the syslog logs.
22+
# @param auth_enabled
23+
# A boolean value to enable or disable the auth module.
24+
# @param auth_paths
25+
# An optional array of paths to the auth logs.
26+
#
27+
class filebeat::module::system (
28+
Boolean $syslog_enabled = false,
29+
Optional[Array[Stdlib::Unixpath]] $syslog_paths = undef,
30+
Boolean $auth_enabled = false,
31+
Optional[Array[Stdlib::Unixpath]] $auth_paths = undef,
32+
) {
33+
filebeat::module { 'system':
34+
config => {
35+
'syslog' => delete_undef_values(
36+
{
37+
'enabled' => $syslog_enabled,
38+
'var.paths' => $syslog_paths,
39+
}
40+
),
41+
'auth' => delete_undef_values(
42+
{
43+
'enabled' => $auth_enabled,
44+
'var.paths' => $auth_paths,
45+
}
46+
),
47+
},
48+
}
49+
}

spec/classes/module/system_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'filebeat::module::system' do
6+
let :pre_condition do
7+
'include ::filebeat'
8+
end
9+
10+
let(:facts) {
11+
{
12+
:kernel => 'Linux',
13+
:os => {
14+
:family => 'Debian',
15+
:name => 'Ubuntu',
16+
}
17+
}
18+
}
19+
20+
context 'on default values' do
21+
it { is_expected.to compile.with_all_deps }
22+
23+
it {
24+
is_expected.to contain_file('filebeat-module-system').with_content(
25+
%r{- module: system\n\s{2}syslog:\n\s{4}enabled: false\n\s{2}auth:\n\s{4}enabled: false\n\n},
26+
)}
27+
end
28+
29+
context 'on log and slowlog enabled with paths' do
30+
let(:params) do
31+
{
32+
'syslog_enabled' => true,
33+
'syslog_paths' => ['/var/log/syslog'],
34+
'auth_enabled' => true,
35+
'auth_paths' => ['/var/log/auth.log'],
36+
}
37+
end
38+
39+
it { is_expected.to compile.with_all_deps }
40+
41+
it {
42+
is_expected.to contain_file('filebeat-module-system').with_content(
43+
<<-EOS
44+
### Filebeat configuration managed by Puppet ###
45+
---
46+
- module: system
47+
syslog:
48+
enabled: true
49+
var.paths:
50+
- "/var/log/syslog"
51+
auth:
52+
enabled: true
53+
var.paths:
54+
- "/var/log/auth.log"
55+
56+
EOS
57+
)
58+
}
59+
end
60+
end

0 commit comments

Comments
 (0)