Skip to content

Commit

Permalink
Add system module
Browse files Browse the repository at this point in the history
  • Loading branch information
TuningYourCode authored and pcfens committed Feb 18, 2024
1 parent 2a18b0f commit 236715b
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
49 changes: 49 additions & 0 deletions manifests/module/system.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# filebeat::module::system
#
# @summary
# This class manages the Filebeat system module.
#
# @example
# class { 'filebeat::module::system':
# syslog_enabled => true,
# syslog_paths => [
# '/var/log/syslog',
# ],
# auth_enabled => true,
# auth_paths => [
# '/var/log/auth.log',
# ],
# }
#
# @param syslog_enabled
# A boolean value to enable or disable the syslog module.
# @param syslog_paths
# An optional array of paths to the syslog logs.
# @param auth_enabled
# A boolean value to enable or disable the auth module.
# @param auth_paths
# An optional array of paths to the auth logs.
#
class filebeat::module::system (
Boolean $syslog_enabled = false,
Optional[Array[Stdlib::Unixpath]] $syslog_paths = undef,
Boolean $auth_enabled = false,
Optional[Array[Stdlib::Unixpath]] $auth_paths = undef,
) {
filebeat::module { 'system':
config => {
'syslog' => delete_undef_values(
{
'enabled' => $syslog_enabled,
'var.paths' => $syslog_paths,
}
),
'auth' => delete_undef_values(
{
'enabled' => $auth_enabled,
'var.paths' => $auth_paths,
}
),
},
}
}
60 changes: 60 additions & 0 deletions spec/classes/module/system_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'filebeat::module::system' do
let :pre_condition do
'include ::filebeat'
end

let(:facts) {
{
:kernel => 'Linux',
:os => {
:family => 'Debian',
:name => 'Ubuntu',
}
}
}

context 'on default values' do
it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_file('filebeat-module-system').with_content(
%r{- module: system\n\s{2}syslog:\n\s{4}enabled: false\n\s{2}auth:\n\s{4}enabled: false\n\n},
)}
end

context 'on log and slowlog enabled with paths' do
let(:params) do
{
'syslog_enabled' => true,
'syslog_paths' => ['/var/log/syslog'],
'auth_enabled' => true,
'auth_paths' => ['/var/log/auth.log'],
}
end

it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_file('filebeat-module-system').with_content(
<<-EOS
### Filebeat configuration managed by Puppet ###
---
- module: system
syslog:
enabled: true
var.paths:
- "/var/log/syslog"
auth:
enabled: true
var.paths:
- "/var/log/auth.log"
EOS
)
}
end
end

0 comments on commit 236715b

Please sign in to comment.