Skip to content

Commit

Permalink
Add logstash 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 ed6217e commit b6e4773
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
45 changes: 45 additions & 0 deletions manifests/module/logstash.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# filebeat::module::logstash
#
# @summary
# This class manages the Filebeat Logstash module.
#
# @example
# class { 'filebeat::module::logstash':
# log_enabled => true,
# log_paths => ['/var/log/logstash/logstash-plain.log'],
# slowlog_enabled => true,
# slowlog_paths => ['/var/log/logstash/logstash-slowlog.log'],
# }
#
# @param log_enabled
# Whether to enable the Logstash module.
# @param log_paths
# An array of paths to the Logstash logs.
# @param slowlog_enabled
# Whether to enable the Logstash slowlog module.
# @param slowlog_paths
# An array of paths to the Logstash slowlogs.
#
class filebeat::module::logstash (
Boolean $log_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $log_paths = undef,
Boolean $slowlog_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $slowlog_paths = undef,
) {
filebeat::module { 'logstash':
config => {
'log' => delete_undef_values(
{
'enabled' => $log_enabled,
'var.paths' => $log_paths,
}
),
'slowlog' => delete_undef_values(
{
'enabled' => $slowlog_enabled,
'var.paths' => $slowlog_paths,
}
),
},
}
}
60 changes: 60 additions & 0 deletions spec/classes/module/logstash_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::logstash' 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-logstash').with_content(
%r{- module: logstash\n\s{2}log:\n\s{4}enabled: false\n\s{2}slowlog:\n\s{4}enabled: false\n\n},
)}
end

context 'on log and slowlog enabled with paths' do
let(:params) do
{
'log_enabled' => true,
'log_paths' => ['/var/log/logstash.log'],
'slowlog_enabled' => true,
'slowlog_paths' => ['/var/log/logstash-slowlog.log'],
}
end

it { is_expected.to compile.with_all_deps }

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

0 comments on commit b6e4773

Please sign in to comment.