Skip to content

Commit

Permalink
syslog: Add option notify_level
Browse files Browse the repository at this point in the history
This change:
* adds option notify_level
* converts the template to epp
* set all parameters type
* Add rspec testing
  • Loading branch information
sileht committed Jun 12, 2018
1 parent e69dd24 commit ad25d97
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
9 changes: 5 additions & 4 deletions manifests/plugin/syslog.pp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# https://collectd.org/wiki/index.php/Plugin:SysLog
class collectd::plugin::syslog (
$ensure = 'present',
$interval = undef,
$log_level = 'info'
Enum['present', 'absent'] $ensure = 'present',
Optional[Float] $interval = undef,
Enum['debug', 'info', 'notice', 'warning', 'err'] $log_level = 'info',
Optional[Enum['OKAY', 'WARNING', 'FAILURE']] $notify_level = undef
) {

include ::collectd

collectd::plugin { 'syslog':
ensure => $ensure,
content => template('collectd/plugin/syslog.conf.erb'),
content => epp('collectd/plugin/syslog.conf.epp'),
interval => $interval,
# Load logging plugin first
# https://github.com/puppet-community/puppet-collectd/pull/166#issuecomment-50591413
Expand Down
69 changes: 69 additions & 0 deletions spec/classes/collectd_plugin_syslog_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'spec_helper'

describe 'collectd::plugin::syslog', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end
let :pre_condition do
'include collectd'
end

options = os_specific_options(facts)

context 'all options set' do
let :params do
{
log_level: 'debug',
notify_level: 'FAILURE'
}
end

content = <<EOS
# Generated by Puppet
<LoadPlugin syslog>
Globals false
</LoadPlugin>
<Plugin syslog>
LogLevel debug
NotifyLevel FAILURE
</Plugin>
EOS

it "Will create #{options[:plugin_conf_dir]}/05-syslog.conf" do
is_expected.to contain_file('syslog.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/05-syslog.conf",
content: content
)
end
end

context ':ensure => absent' do
let :params do
{ ensure: 'absent' }
end

it "Will not create #{options[:plugin_conf_dir]}/05-syslog.conf" do
is_expected.to contain_file('syslog.load').with(
ensure: 'absent',
path: "#{options[:plugin_conf_dir]}/05-syslog.conf"
)
end
end

context 'notify_level invalid' do
let :params do
{ notify_level: 'notexist' }
end

it 'Will raise an error about :notify_level being Enum' do
is_expected.to compile.and_raise_error(%r{Enum})
end
end
end
end
end
6 changes: 6 additions & 0 deletions templates/plugin/syslog.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Plugin syslog>
LogLevel <%= $collectd::plugin::syslog::log_level %>
<% if $collectd::plugin::syslog::notify_level { -%>
NotifyLevel <%= $collectd::plugin::syslog::notify_level %>
<% } -%>
</Plugin>
3 changes: 0 additions & 3 deletions templates/plugin/syslog.conf.erb

This file was deleted.

0 comments on commit ad25d97

Please sign in to comment.