diff --git a/manifests/module/mysql.pp b/manifests/module/mysql.pp new file mode 100644 index 0000000..f909da2 --- /dev/null +++ b/manifests/module/mysql.pp @@ -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, + } + ), + }, + } +} diff --git a/spec/classes/module/mysql_spec.rb b/spec/classes/module/mysql_spec.rb new file mode 100644 index 0000000..25bc078 --- /dev/null +++ b/spec/classes/module/mysql_spec.rb @@ -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