diff --git a/manifests/module/nginx.pp b/manifests/module/nginx.pp new file mode 100644 index 0000000..f8ce765 --- /dev/null +++ b/manifests/module/nginx.pp @@ -0,0 +1,65 @@ +# filebeat::module::nginx +# +# @summary +# This class manages the Filebeat module for Nginx. +# +# @example +# class { 'filebeat::module::nginx': +# access_enabled => true, +# access_paths => [ +# '/var/log/nginx/access.log*', +# ], +# error_enabled => true, +# error_paths => [ +# '/var/log/nginx/error.log*', +# ], +# ingress_enabled => true, +# ingress_paths => [ +# '/var/log/nginx/ingress.log*', +# ], +# } +# +# @param access_enabled +# Whether to enable the Nginx access module. +# @param access_paths +# The paths to the Nginx access logs. +# @param error_enabled +# Whether to enable the Nginx error module. +# @param error_paths +# The paths to the Nginx error logs. +# @param ingress_controller_enabled +# Whether to enable the Nginx ingress_controller module. +# @param ingress_controller_paths +# The paths to the Nginx ingress_controller logs. +# +class filebeat::module::nginx ( + Boolean $access_enabled = false, + Optional[Array[Stdlib::Absolutepath]] $access_paths = undef, + Boolean $error_enabled = false, + Optional[Array[Stdlib::Absolutepath]] $error_paths = undef, + Boolean $ingress_controller_enabled = false, + Optional[Array[Stdlib::Absolutepath]] $ingress_controller_paths = undef, +) { + filebeat::module { 'nginx': + config => { + 'access' => delete_undef_values( + { + 'enabled' => $access_enabled, + 'var.paths' => $access_paths, + } + ), + 'error' => delete_undef_values( + { + 'enabled' => $error_enabled, + 'var.paths' => $error_paths, + } + ), + 'ingress_controller' => delete_undef_values( + { + 'enabled' => $ingress_controller_enabled, + 'var.paths' => $ingress_controller_paths, + } + ), + }, + } +} diff --git a/spec/classes/module/nginx_spec.rb b/spec/classes/module/nginx_spec.rb new file mode 100644 index 0000000..4a2a611 --- /dev/null +++ b/spec/classes/module/nginx_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'filebeat::module::nginx' 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-nginx').with_content( + %r{- module: nginx\n\s{2}access:\n\s{4}enabled: false\n\s{2}error:\n\s{4}enabled: false\n\s{2}ingress_controller:\n\s{4}enabled: false\n\n}, + )} + end + + context 'on access, error and ingress_controller enabled with paths' do + let(:params) do + { + 'access_enabled' => true, + 'access_paths' => ['/var/log/nginx/access.log'], + 'error_enabled' => true, + 'error_paths' => ['/var/log/nginx/error.log'], + 'ingress_controller_enabled' => true, + 'ingress_controller_paths' => ['/var/log/nginx/ingress_controller.log'], + } + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('filebeat-module-nginx').with_content( + <<-EOS +### Filebeat configuration managed by Puppet ### +--- +- module: nginx + access: + enabled: true + var.paths: + - "/var/log/nginx/access.log" + error: + enabled: true + var.paths: + - "/var/log/nginx/error.log" + ingress_controller: + enabled: true + var.paths: + - "/var/log/nginx/ingress_controller.log" + +EOS + ) + } + end +end