Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions manifests/logging/channel.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
# @param syslog_facility
# The syslog facility to use when logging to a syslog log_type
define dns::logging::channel (
Optional[Stdlib::Absolutepath] $file_path = undef,
Optional[String] $file_size = undef,
Optional[Integer] $file_versions = undef,
Enum['file', 'null', 'stderr', 'syslog'] $log_type = undef,
Integer[51, 59] $order = 51,
Optional[Enum['no', 'yes']] $print_category = undef,
Optional[Enum['no', 'yes']] $print_severity = undef,
Optional[Enum['no', 'yes']] $print_time = undef,
Optional[String] $severity = undef,
Optional[String] $syslog_facility = undef,
Optional[Stdlib::Absolutepath] $file_path = undef,
Optional[String] $file_size = undef,
Optional[Variant[Enum['unlimited'],Integer]] $file_versions = undef,
Enum['file', 'null', 'stderr', 'syslog'] $log_type = undef,
Integer[51, 59] $order = 51,
Optional[Enum['no', 'yes']] $print_category = undef,
Optional[Enum['no', 'yes']] $print_severity = undef,
Optional[Enum['no', 'yes']] $print_time = undef,
Optional[String] $severity = undef,
Optional[String] $syslog_facility = undef,
) {
include dns::logging

Expand All @@ -55,11 +55,8 @@
if empty($file_path) {
fail('dns::logging::channel: "file_path" needs to be set with log type file')
}
if empty($file_size) {
fail('dns::logging::channel: "file_size" needs to be set with log type file')
}
if !$file_versions {
fail('dns::logging::channel: "file_versions" needs to be set with log type file')
if $file_versions and empty($file_size) {
fail('dns::logging::channel: "file_size" needs to be set if "file_version" is set')
}
}

Expand Down
15 changes: 14 additions & 1 deletion spec/defines/dns_logging_channel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@
it { is_expected.not_to compile }
end

describe 'with log_type = file and file_size and file_version not set' do
let(:params) do
{
'log_type' => 'file',
'file_path' => '/path/to/file.log',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_concat__fragment("named.conf-logging-channel-#{title}.dns").with_content(%r{file "/path/to/file.log";})}
end

describe 'with log_type = file and file_versions not set' do
let(:params) do
{
Expand All @@ -163,7 +175,8 @@
}
end

it { is_expected.not_to compile }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_concat__fragment("named.conf-logging-channel-#{title}.dns").with_content(%r{file "/path/to/file.log" size 5m;})}
end

describe 'with log_type = syslog and all options set' do
Expand Down
6 changes: 6 additions & 0 deletions templates/log.channel.conf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
channel <%= @channel_name %> {
<%- if @log_type == 'file' -%>
<%- if @file_versions && @file_size -%>
file "<%= @file_path -%>" versions <%= @file_versions -%> size <%= @file_size -%>;
<%- elsif @file_size -%>
file "<%= @file_path -%>" size <%= @file_size -%>;
<%- else -%>
file "<%= @file_path -%>";
<%- end -%>
<%- elsif @log_type == 'null' -%>
null;
<%- elsif @log_type == 'stderr' -%>
Expand Down
Loading