Skip to content

Commit

Permalink
Add redis 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 0d126ec commit f13f09a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
50 changes: 50 additions & 0 deletions manifests/module/redis.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# filebeat::module::redis
#
# @summary
# This class manages the Filebeat Redis module.
#
# @example
# class { 'filebeat::module::redis':
# log_enabled => true,
# log_paths => ['/var/log/redis/redis-server.log'],
# slowlog_enabled => true,
# slowlog_hosts => ['localhost:6379'],
# slowlog_password => 'password',
# }
#
# @param log_enabled
# Whether to enable the Redis log input. Defaults to `false`.
# @param log_paths
# The paths to the Redis log files. Defaults to `undef`.
# @param slowlog_enabled
# Whether to enable the Redis slowlog input. Defaults to `false`.
# @param slowlog_hosts
# The Redis hosts to connect to. Defaults to `undef`.
# @param slowlog_password
# The password to use when connecting to Redis. Defaults to `undef`.
#
class filebeat::module::redis (
Boolean $log_enabled = false,
Optional[Array[Stdlib::Absolutepath]] $log_paths = undef,
Boolean $slowlog_enabled = false,
Optional[Array[String[1]]] $slowlog_hosts = undef,
Optional[String[1]] $slowlog_password = undef,
) {
filebeat::module { 'redis':
config => {
'log' => delete_undef_values(
{
'enabled' => $log_enabled,
'var.paths' => $log_paths,
}
),
'slowlog' => delete_undef_values(
{
'enabled' => $slowlog_enabled,
'var.hosts' => $slowlog_hosts,
'var.password' => $slowlog_password,
}
),
},
}
}
62 changes: 62 additions & 0 deletions spec/classes/module/redis_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'filebeat::module::redis' 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-redis').with_content(
%r{- module: redis\n\s{2}log:\n\s{4}enabled: false\n\s{2}slowlog:\n\s{4}enabled: false\n\n},
)}
end

context 'on log and slowlog enabled with paths' do
let(:params) do
{
'log_enabled' => true,
'log_paths' => ['/var/log/redis.log'],
'slowlog_enabled' => true,
'slowlog_hosts' => ['localhost:6379'],
'slowlog_password' => 'password',
}
end

it { is_expected.to compile.with_all_deps }

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

0 comments on commit f13f09a

Please sign in to comment.