Skip to content

Commit

Permalink
Add nginx 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 3107a22 commit 0f85723
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
65 changes: 65 additions & 0 deletions manifests/module/nginx.pp
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,
}
),
},
}
}
66 changes: 66 additions & 0 deletions spec/classes/module/nginx_spec.rb
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

0 comments on commit 0f85723

Please sign in to comment.