Skip to content

Commit

Permalink
Add mysql 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 b6e4773 commit 3107a22
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
49 changes: 49 additions & 0 deletions manifests/module/mysql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# filebeat::module::mysql
#
# @summary
# This class manages the Filebeat module for MySQL.
#
# @example
# class { 'filebeat::module::mysql':
# error_enabled => true,
# error_paths => [
# '/var/log/mysql/error.log',
# ],
# slowlog_enabled => true,
# slowlog_paths => [
# '/var/log/mysql/slow.log',
# ],
# }
#
# @param error_enabled
# Whether to enable the MySQL error log module. Defaults to false.
# @param error_paths
# An array of absolute paths to the MySQL error log files. Defaults to undef.
# @param slowlog_enabled
# Whether to enable the MySQL slow log module. Defaults to false.
# @param slowlog_paths
# An array of absolute paths to the MySQL slow log files. Defaults to undef.
#
class filebeat::module::mysql (
Boolean $error_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $error_paths = undef,
Boolean $slowlog_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $slowlog_paths = undef,
) {
filebeat::module { 'mysql':
config => {
'error' => delete_undef_values(
{
'enabled' => $error_enabled,
'var.paths' => $error_paths,
}
),
'slowlog' => delete_undef_values(
{
'enabled' => $slowlog_enabled,
'var.paths' => $slowlog_paths,
}
),
},
}
}
60 changes: 60 additions & 0 deletions spec/classes/module/mysql_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::mysql' 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-mysql').with_content(
%r{- module: mysql\n\s{2}error:\n\s{4}enabled: false\n\s{2}slowlog:\n\s{4}enabled: false\n\n},
)}
end

context 'on error and slowlog enabled with paths' do
let(:params) do
{
'error_enabled' => true,
'error_paths' => ['/var/log/mysql/error.log'],
'slowlog_enabled' => true,
'slowlog_paths' => ['/var/log/mysql/slowlog.log'],
}
end

it { is_expected.to compile.with_all_deps }

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

0 comments on commit 3107a22

Please sign in to comment.