Skip to content

Commit

Permalink
Add postgresql 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 0f85723 commit d311ade
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions manifests/module/postgresql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# filebeat::module::postgresql
#
# @summary
# This class manages the Filebeat module for PostgreSQL.
#
# @example
# class { 'filebeat::module::postgresql':
# log_enabled => true,
# log_paths => [
# '/var/log/postgresql/*.log',
# ],
# }
#
# @param log_enabled
# Whether to enable the PostgreSQL module.
# @param log_paths
# An array of absolute paths to the PostgreSQL log files.
#
class filebeat::module::postgresql (
Boolean $log_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $log_paths = undef,
) {
filebeat::module { 'postgresql':
config => {
'log' => delete_undef_values(
{
'enabled' => $log_enabled,
'var.paths' => $log_paths,
}
),
},
}
}
54 changes: 54 additions & 0 deletions spec/classes/module/postgresql_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'filebeat::module::postgresql' 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-postgresql').with_content(
%r{- module: postgresql\n\s{2}log:\n\s{4}enabled: false\n\n},
)}
end

context 'on log enabled with paths' do
let(:params) do
{
'log_enabled' => true,
'log_paths' => ['/var/log/postgresql.log'],
}
end

it { is_expected.to compile.with_all_deps }

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

0 comments on commit d311ade

Please sign in to comment.