-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3107a22
commit 0f85723
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |