All Files (100.0% covered at 7.99 hits/line)
17 files in total.
552 relevant lines.
552 lines covered and
0 lines missed
#
# Cookbook:: syslog_ng
# Library:: common
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
module SyslogNg
- 1
SYSLOG_NG_BOOLEAN_OPERATORS ||= %w(and or and_not or_not container).freeze # I've added the __container__ 'operator' and __operator__ 'filter' here to allow nested boolean operation, syslog-ng doesn't know anything about it.
- 1
SYSLOG_NG_FILTER_FUNCTIONS ||= %w(facility filter host inlist level priority match message netmask netmask6 program source tags operator).freeze
- 1
SYSLOG_NG_REWRITE_OPERATORS ||= %w(subst set unset groupset groupunset set-tag clear-tag credit-card-mask credit-card-hash).freeze
- 1
SYSLOG_NG_REWRITE_PARAMETERS_UNNAMED ||= %w(match replacement field tags additional_options).freeze
- 1
module CommonHelpers
- 1
def format_string_value(string)
- 57
raise ArgumentError, "format_string_value: Expected a configuration String to format, got a #{string.class}." unless string.is_a?(String)
- 57
param_string = string.dup
- 57
unless %w(yes YES no NO).include?(param_string) || ip_address?(param_string)
- 50
param_string.prepend('"')
- 50
param_string.concat('"')
end
- 57
Chef::Log.debug("format_string_value: Formatted parameter string to: #{param_string}.")
- 57
param_string
end
- 1
def build_parameter_string(parameters:, unnamed_parameters: [])
- 43
raise ArgumentError, "build_parameter_string: Expected configuration parameters to be passed as a Hash, Array or String. Got a #{parameters.class}." unless parameters.is_a?(Hash) || parameters.is_a?(Array) || parameters.is_a?(String)
- 43
param_string = ''
- 43
return param_string if parameters.empty?
- 43
if parameters.is_a?(Hash)
- 29
parameters.each do |parameter, value|
- 63
if value.nil?
- 4
next
- 59
elsif value.is_a?(Hash) || value.is_a?(Array)
- 15
next if value.empty?
- 13
param_string.concat(format_parameter_pair(parameter: parameter, value: build_parameter_string(parameters: value), named: !unnamed_parameters.include?(parameter)))
else
- 44
param_string.concat(format_parameter_pair(parameter: parameter, value: value, named: !unnamed_parameters.include?(parameter)))
end
end
- 14
elsif parameters.is_a?(Array)
- 12
if parameters.count > 1
- 7
param_string.concat(parameter_pair_array(parameters))
else
- 5
return parameters.first
end
- 2
elsif parameters.is_a?(String)
- 2
param_string.concat(parameters + ' ')
end
- 38
param_string.rstrip!
- 38
Chef::Log.debug("build_parameter_string: Generated parameter string is: #{param_string}.")
- 38
param_string
end
- 1
def array_join(array)
- 20
raise unless array.is_a?(Array)
- 20
config_string = ''
- 20
array.each do |element|
- 57
config_string.concat(element + ' ')
end
- 20
config_string.gsub(/(\( )|( \))/, '( ' => '(', ' )' => ')').strip
end
- 1
def parameter_builder(driver: nil, path: nil, parameters: nil, configuration: nil)
- 9
if parameter_defined?(configuration) && configuration.is_a?(Array)
- 1
configuration
- 8
elsif parameter_defined?(driver) && driver.is_a?(Array)
- 4
source_config = []
- 4
if !path.nil? && !parameters.nil?
- 1
driver.zip(path, parameters).each do |drv, pth, param|
- 2
hash = {}
- 2
hash[drv] = {}
- 2
hash[drv]['path'] = pth unless pth.nil?
- 2
hash[drv]['parameters'] = param unless param.nil?
- 2
source_config.push(hash)
end
- 3
elsif path.nil? && !parameters.nil?
- 1
driver.zip(parameters).each do |drv, param|
- 2
hash = {}
- 2
hash[drv] = {}
- 2
hash[drv]['parameters'] = param unless param.nil?
- 2
source_config.push(hash)
end
- 2
elsif !path.nil? && parameters.nil?
- 1
driver.zip(path).each do |drv, pth|
- 2
hash = {}
- 2
hash[drv] = {}
- 2
hash[drv]['path'] = pth unless pth.nil?
- 2
source_config.push(hash)
end
else
- 1
driver.zip(driver).each do |drv|
- 2
hash = {}
- 2
hash[drv] = {}
- 2
source_config.push(hash)
end
end
- 4
source_config
- 4
elsif parameter_defined?(driver) && driver.is_a?(String)
- 3
[
driver => {
'path' => path,
'parameters' => parameters,
},
]
else
- 1
raise ArgumentError, "parameter_builder: Invalid argument set given. driver: #{driver.class} | path: #{path.class} | parameters: #{parameters.class} | configuration: #{configuration.class}"
end
end
- 1
private
- 1
def parameter_defined?(parameter)
- 21
if parameter.nil? || parameter.empty?
- 10
false
else
- 11
true
end
end
- 1
def format_parameter_pair(parameter:, value:, named: true)
- 57
raise ArgumentError, "format_parameter_pair: Type error, got #{parameter.class} and #{value.class}. Expected String and String/Integer." unless parameter.is_a?(String) && (value.is_a?(String) || value.is_a?(Integer))
- 57
parameter_value = value.is_a?(String) && !value.match?('"') ? format_string_value(value) : value.to_s # TODO: Don't like this matching for already quoted strings
- 57
parameter_string = ''
- 57
parameter_string.concat(parameter) if named
- 57
if named
- 43
parameter_string.concat('(' + parameter_value + ') ')
else
- 14
parameter_string.concat(parameter_value + ', ')
end
- 57
Chef::Log.debug("format_parameter_pair: Generated parameter: #{parameter_string}.")
- 57
parameter_string
end
- 1
def parameter_pair_array(array)
#
# Formats an array of either strings of already correctly formatted parameters or constructs a set of correctly formatted parameters from
# an array of multiple common parameters.
#
- 7
raise ArgumentError, "parameter_pair_array: Excepted configuration parameters to be passed as an Array, got #{array.class}." unless array.is_a?(Array)
- 7
parameter_string = ''
- 7
join_comma = false
- 7
parameters_formatted = array.map do |parameter|
- 14
if parameter.is_a?(String)
- 12
if parameter.match?('\(|\)')
# Pre-formatted
- 2
parameter
else
# Needed to be formatted
- 10
join_comma = true
- 10
format_string_value(parameter)
end
else
- 2
parameter.to_s
end
end
- 7
join_comma ? parameter_string.concat(parameters_formatted.join(', ')) : parameter_string.concat(parameters_formatted.join(' '))
- 7
Chef::Log.debug("format_parameter_pair: Generated parameter: #{parameter_string}.")
- 7
parameter_string
end
- 1
def contained_group(hash)
- 14
raise ArgumentError, "contained_group: Expected configuration parameters to be passed as a Hash, got a #{hash.class}." unless hash.is_a?(Hash)
- 14
local_hash = hash.dup
- 14
config_string = ''
- 14
config_string = '(' unless local_hash.empty?
- 14
if local_hash.key?('operator')
- 5
boolean_operator = local_hash.delete('operator')
- 5
raise ArgumentError, "contained_group: Invalid combining operator '#{boolean_operator}' specified." unless SYSLOG_NG_BOOLEAN_OPERATORS.include?(boolean_operator)
- 5
Chef::Log.debug("contained_group: Contained group operator is '#{boolean_operator}'.")
else
- 9
boolean_operator = 'and'
end
- 14
local_hash.each do |filter, value|
- 16
case value
when String
- 6
config_string.concat(contained_group_append(config_string, boolean_operator, filter, value))
when Array
- 4
value.each do |val|
- 12
config_string.concat(contained_group_append(config_string, boolean_operator, filter, val))
end
when Hash
- 5
if config_string.include?(')')
- 2
config_string.concat(boolean_operator.tr('_', ' ') + ' ' + contained_group(value))
else
- 3
config_string.concat(contained_group(value) + ' ')
end
else
- 1
raise "Invalid value class found, support String, Array and Hash. Got a #{value.class}."
end
end
- 12
config_string.rstrip!
- 12
config_string.concat(')') unless local_hash.empty?
- 12
config_string
end
- 1
def contained_group_append(config_string, operator, filter, value)
- 18
append_string = if config_string.include?(')')
- 8
operator.tr('_', ' ') + ' ' + filter + '(' + value + ') '
else
- 10
filter + '(' + value + ') '
end
- 18
append_string
end
- 1
def ip_address?(string)
- 56
require 'ipaddr'
- 56
IPAddr.new(string).ipv4? || IPAddr.new(string).ipv6?
rescue IPAddr::InvalidAddressError
- 50
false
end
end
end
#
# Cookbook:: syslog_ng
# Library:: config
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require_relative 'source'
- 1
module SyslogNg
- 1
module DestinationHelpers
- 1
include SyslogNg::SourceHelpers
end
end
#
# Cookbook:: syslog_ng
# Library:: filter
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require_relative '_common'
- 1
module SyslogNg
- 1
module FilterHelpers
- 1
include SyslogNg::CommonHelpers
- 1
def filter_builder(parameters)
- 20
raise ArgumentError, "filter_builder: Expected syslog-ng filter definition to be passed as a Hash, Array or String. Got a #{parameters.class}." unless parameters.is_a?(Hash) || parameters.is_a?(Array) || parameters.is_a?(String)
- 20
config_string = ''
- 20
if parameters.is_a?(Hash)
- 16
parameters.each do |filter, parameter|
- 18
if (SYSLOG_NG_BOOLEAN_OPERATORS.include?(filter) || filter.match?('container')) && parameter.is_a?(Hash)
- 11
if filter.match?('container')
- 9
config_string.concat(contained_group(parameter))
else
- 2
config_string.concat(filter.tr('_', ' ') + ' ' + filter_builder(parameter) + ' ')
end
- 7
elsif SYSLOG_NG_FILTER_FUNCTIONS.include?(filter) && (parameter.is_a?(String) || parameter.is_a?(Array))
- 6
if parameter.is_a?(String)
- 4
config_string.concat(filter + '(' + parameter + ') ')
- 2
elsif parameter.is_a?(Array)
- 2
parameter.each do |param|
- 6
config_string.concat(filter + '(' + param + ') ')
end
- 2
config_string.rstrip!
end
else
- 1
raise ArgumentError, "filter_builder: Invalid operator '#{filter}' specified in filter configuration. Object type #{parameter.class}."
end
end
- 14
config_string.rstrip!
- 4
elsif parameters.is_a?(Array)
- 2
parameters.each do |parameter|
- 6
config_string.concat(parameter + ' ')
end
- 2
elsif parameters.is_a?(String)
- 2
config_string.concat(parameters)
end
- 18
config_string.rstrip!
- 18
config_string
end
end
end
#
# Cookbook:: syslog_ng
# Library:: install
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
module SyslogNg
- 1
module InstallHelpers
- 1
def installed_version_get
- 2
require 'mixlib/shellout'
- 2
syslog_ng_version_cmd = Mixlib::ShellOut.new("syslog-ng --version | grep 'Installer-Version' | grep -Po '([0-9]\.?)+'")
- 2
syslog_ng_version_cmd.run_command
- 2
syslog_ng_version_cmd.error!
- 2
/[0-9]+.[0-9]+/.match(syslog_ng_version_cmd.stdout).to_s
end
- 1
def repo_get_packages(platform:, latest: false, copr_version: '0.0')
- 13
raise ArgumentException, "Expected platform to be a String, got a #{platform.class}." unless platform.is_a?(String)
- 13
require 'mixlib/shellout'
- 13
version = copr_version.delete('.')
- 13
case platform
when 'rhel', 'amazon'
- 4
command = if latest
- 2
"yum -q --disablerepo=* --enablerepo=syslog-ng#{version} search syslog-ng | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-zA-Z0-9]+)?)+' | sort -u"
else
- 2
"yum -q search syslog-ng | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-zA-Z0-9]+)?)+' | sort -u"
end
- 4
Chef::Log.debug("RHEL selected, command will be '#{command}'")
when 'fedora'
- 4
command = if latest
- 2
"dnf -q --disablerepo=* --enablerepo=syslog-ng#{version} search syslog-ng | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-zA-Z0-9]+)?)+' | sort -u"
else
- 2
"dnf -q search syslog-ng | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-zA-Z0-9]+)?)+' | sort -u"
end
- 4
Chef::Log.debug("Fedora selected, command will be '#{command}'")
when 'debian'
- 4
command = if latest
- 2
'apt-cache search syslog-ng | grep -i "syslog-ng" | awk "{print $1}" | grep -Po "(syslog-ng)" | sort -u'
else
- 2
"apt-cache search syslog-ng | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-zA-Z0-9]+)?)+' | sort -u"
end
- 4
Chef::Log.debug("Debian selected, command will be '#{command}'")
else
- 1
raise "repo_get_packages: Unknown platform. Given platform: #{platform}."
end
- 12
package_search = Mixlib::ShellOut.new(command)
- 12
package_search.run_command
- 12
package_search.error!
- 12
packages = package_search.stdout.split(/\n+/)
- 12
packages
end
- 1
def installed_get_packages(platform:)
- 7
raise ArgumentException, "Expected platform to be a String, got a #{platform.class}." unless platform.is_a?(String)
- 7
require 'mixlib/shellout'
- 7
case platform
when 'rhel', 'fedora', 'amazon'
- 4
command = "rpm -qa | grep -i 'syslog-ng' | awk '{print $1}' | grep -Po '(syslog-ng)((-[a-z]+)?)+' | sort -u"
- 4
Chef::Log.debug("RHEL selected, command will be '#{command}'")
when 'debian'
- 2
command = "dpkg -l | grep -i 'syslog-ng' | awk '{print $2}' | grep -Po '(syslog-ng)((-[a-z]+)?)+' | sort -u"
- 2
Chef::Log.debug("Debian selected, command will be '#{command}'")
else
- 1
raise "installed_get_packages: Unknown platform. Given platform: #{platform}."
end
- 6
package_search = Mixlib::ShellOut.new(command)
- 6
package_search.run_command
- 6
package_search.error!
- 6
packages = package_search.stdout.split(/\n+/)
- 6
packages
end
end
end
#
# Cookbook:: syslog_ng
# Library:: rewrite
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require_relative '_common'
- 1
module SyslogNg
- 1
module RewriteHelpers
- 1
include SyslogNg::CommonHelpers
- 1
def rewrite_builder(parameters)
- 18
raise ArgumentError, "config_rewrite_map: Expected syslog-ng rewrite configuration attribute block to be a Hash, got a #{parameters.class}." unless parameters.is_a?(Hash)
- 18
raise ArgumentError, "config_rewrite_map: Invalid rewrite operator specified, got #{parameters['function']} which is not a valid syslog-ng rewrite operation." unless SYSLOG_NG_REWRITE_OPERATORS.include?(parameters['function'])
- 18
int_parameters = parameters.dup
- 18
config_string = ''
- 18
config_string.concat(int_parameters.delete('function') + '(')
- 18
config_string.concat(build_parameter_string(parameters: int_parameters, unnamed_parameters: SYSLOG_NG_REWRITE_PARAMETERS_UNNAMED))
- 18
config_string.rstrip!
- 18
config_string = config_string.slice(0, (config_string.length - 1)) if config_string[(config_string.length - 1)].eql?(',')
- 18
config_string.concat(')')
- 18
config_string
end
end
end
#
# Cookbook:: syslog_ng
# Library:: config
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require_relative '_common'
- 1
module SyslogNg
- 1
module SourceHelpers
- 1
include SyslogNg::CommonHelpers
- 1
def source_builder(driver:, parameters:, multiline: false)
- 22
raise ArgumentError, "source_builder: Expected syslog-ng destination driver name to be a String, got a #{driver.class}." unless driver.is_a?(String)
- 22
raise ArgumentError, "source_builder: Expected syslog-ng destination driver configuration attribute block to be a Hash, got a #{parameters.class}." unless parameters.is_a?(Hash)
- 22
config = []
- 22
config.push(driver.dup.concat('('))
- 22
config.push(format_string_value(parameters['path'])) if parameters.key?('path') # Certain drivers have an unnamed 'path' parameter (eg File)
- 22
if parameters.key?('parameters')
- 12
if multiline
- 3
build_parameter_string(parameters: parameters['parameters']).split.each { |string| config.push(string.prepend(' ')) }
else
- 11
config.push(build_parameter_string(parameters: parameters['parameters']))
end
end
- 22
config.push(');')
- 22
if multiline
- 2
config
else
- 20
array_join(config)
end
end
- 1
alias_method :destination_builder, :source_builder
end
end
#
# Cookbook:: syslog_ng
# Spec:: destination_helpers_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'SyslogNg::SourceHelpers' do
- 7
let(:dummy_class) { Class.new { include SyslogNg::SourceHelpers } }
- 1
describe '.destination_builder destinations' do
- 1
context('given driver with no parameters and a path') do
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: { 'path' => '/dev/console' })).to be_a(String)
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: { 'path' => '/dev/console' })).to eql('file("/dev/console");')
end
end
- 1
context('given driver with parameters and a path') do
- 1
param = {
'path' => '/var/log/maillog',
'parameters' => {
'flush_lines' => 10,
},
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: param)).to be_a(String)
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: param)).to eql('file("/var/log/maillog" flush_lines(10));')
end
end
- 1
context('given string') do
- 1
param = {
'path' => '/var/log/maillog',
'parameters' => 'flush_lines(10)',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: param)).to be_a(String)
- 1
expect(dummy_class.new.destination_builder(driver: 'file', parameters: param)).to eql('file("/var/log/maillog" flush_lines(10));')
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: filter_helpers_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'SyslogNg::FilterHelpers' do
- 21
let(:dummy_class) { Class.new { include SyslogNg::FilterHelpers } }
- 1
describe '.filter_builder' do
- 1
context('given basic filter') do
- 1
param = {
'facility' => 'kern',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('facility(kern)')
end
end
- 1
context('given complex filter') do
- 1
param = {
'level' => 'info..emerg',
'and_not' => {
'container' => {
'operator' => 'or',
'facility' => %w(mail authpriv cron),
},
},
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('level(info..emerg) and not (facility(mail) or facility(authpriv) or facility(cron))')
end
end
- 1
context('given inplicit _and_ filter') do
- 1
param = {
'container' => {
'facility' => %w(mail authpriv cron),
},
}
- 1
it 'returns valid config string with _and_ present' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('(facility(mail) and facility(authpriv) and facility(cron))')
end
end
- 1
context('given contained string') do
- 1
param = {
'container' => {
'facility' => 'mail',
},
}
- 1
it 'returns valid config string with _and_ present' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('(facility(mail))')
end
end
- 1
context('given multiple contained strings') do
- 1
param = {
'container_outside' => {
'operator' => 'and',
'container_1' => {
'facility' => 'mail',
},
'container_2' => {
'facility' => 'cron',
},
},
}
- 1
it 'returns valid config string with _and_ present' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('((facility(mail)) and (facility(cron)))')
end
end
- 1
context('given contained integer') do
- 1
param = {
'container_outside' => {
'operator' => 'and',
'container_1' => {
'port' => 514,
},
},
}
- 1
it 'raises RuntimeError' do
- 2
expect { dummy_class.new.filter_builder(param) }.to raise_exception(RuntimeError)
end
end
- 1
context('given hash array key') do
- 1
param = {
'facility' => %w(mail authpriv cron),
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('facility(mail) facility(authpriv) facility(cron)')
end
end
- 1
context('given array') do
- 1
param = [
'facility(mail)',
'facility(authpriv)',
'facility(cron)',
]
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('facility(mail) facility(authpriv) facility(cron)')
end
end
- 1
context('given string') do
- 1
param = 'level(emerg)'
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.filter_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.filter_builder(param)).to eql('level(emerg)')
end
end
- 1
context('invalid filter') do
- 1
param = {
'invalidfilter': 'bollocks',
}
- 1
it 'raises ArgumentError' do
- 2
expect { dummy_class.new.filter_builder(param) }.to raise_exception(ArgumentError)
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: install_helpers_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'SyslogNg::InstallHelpers' do
- 21
let(:dummy_class) { Class.new { include SyslogNg::InstallHelpers } }
- 1
describe '.installed_version_get' do
- 1
context('when called') do
- 1
let(:shellout) do
- 1
double(run_command: nil, error!: nil, stdout: '', stderr: '', exitstatus: 0, live_stream: '')
end
- 1
it 'return syslog-ng version as a float' do
- 1
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout)
- 1
allow(shellout).to receive(:error!).and_return(nil)
- 1
allow(shellout).to receive(:stdout).and_return('3.18\n1')
- 1
expect(dummy_class.new.installed_version_get).to be_a(String)
- 1
expect(dummy_class.new.installed_version_get).to eq('3.18')
end
end
end
- 1
describe '.repo_get_packages' do
- 1
platforms = {
'rhel' => "syslog-ng-debuginfo\nsyslog-ng-devel\nsyslog-ng-geoip\nsyslog-ng-http\nsyslog-ng-java\nsyslog-ng-java-deps\nsyslog-ng-json\nsyslog-ng-libdbi\nsyslog-ng-mongodb\nsyslog-ng-python\nsyslog-ng-redis\nsyslog-ng-riemann\nsyslog-ng-smtp\nsyslog-ng\n",
'fedora' => "syslog-ng\nsyslog-ng-http\nsyslog-ng-smtp\nsyslog-ng-http\nsyslog-ng-smtp\nsyslog-ng-amqp\nsyslog-ng-geoip\nsyslog-ng-redis\nsyslog-ng-geoip\nsyslog-ng-redis\nsyslog-ng-libdbi\nsyslog-ng-devel\nsyslog-ng-riemann\nsyslog-ng-devel\nsyslog-ng-riemann\nsyslog-ng-devel\nsyslog-ng-mongodb\nsyslog-ng-java\nsyslog-ng-python\nsyslog-ng-debugsource\nsyslog-ng-python\nsyslog-ng-java-deps\nsyslog-ng-debuginfo\nsyslog-ng-http-debuginfo\nsyslog-ng-java-debuginfo\nsyslog-ng-smtp-debuginfo\nsyslog-ng-geoip-debuginfo\nsyslog-ng-redis-debuginfo\nsyslog-ng-libdbi-debuginfo\nsyslog-ng-python-debuginfo\nsyslog-ng-riemann-debuginfo\n",
'debian' => "syslog-ng\nsyslog-ng-core\nsyslog-ng-dbg\nsyslog-ng-dev\nsyslog-ng-mod-add-contextual-data\nsyslog-ng-mod-amqp\nsyslog-ng-mod-geoip\nsyslog-ng-mod-graphite\nsyslog-ng-mod-journal\nsyslog-ng-mod-json\nsyslog-ng-mod-mongodb\nsyslog-ng-mod-python\nsyslog-ng-mod-redis\nsyslog-ng-mod-riemann\nsyslog-ng-mod-smtp\nsyslog-ng-mod-sql\nsyslog-ng-mod-stomp\nsyslog-ng-mod-basicfuncs-plus\nsyslog-ng-mod-date\nsyslog-ng-mod-grok\nsyslog-ng-mod-kafka\nsyslog-ng-mod-lua\nsyslog-ng-mod-perl\nsyslog-ng-mod-rss\nsyslog-ng-mod-trigger\nsyslog-ng-mod-zmq\n",
}
- 1
platforms.each do |platform, packages|
- 3
context("when called with #{platform} platform") do
- 3
let(:shellout) do
- 3
double(run_command: nil, error!: nil, stdout: '', stderr: '', exitstatus: 0, live_stream: '')
end
- 3
it "return syslog-ng packages for #{platform}" do
- 3
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout)
- 3
allow(shellout).to receive(:error!).and_return(nil)
- 3
allow(shellout).to receive(:stdout).and_return(packages)
- 3
expect(dummy_class.new.repo_get_packages(platform: platform)).to be_a(Array)
- 3
expect(dummy_class.new.repo_get_packages(platform: platform)).to eq(packages.split(/\n+/))
end
end
end
- 1
platforms.each do |platform, packages|
- 3
context("when called with #{platform} platform for COPR") do
- 3
let(:shellout) do
- 3
double(run_command: nil, error!: nil, stdout: '', stderr: '', exitstatus: 0, live_stream: '')
end
- 3
it "return syslog-ng packages for #{platform}" do
- 3
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout)
- 3
allow(shellout).to receive(:error!).and_return(nil)
- 3
allow(shellout).to receive(:stdout).and_return(packages)
- 3
expect(dummy_class.new.repo_get_packages(platform: platform, latest: true)).to be_a(Array)
- 3
expect(dummy_class.new.repo_get_packages(platform: platform, latest: true)).to eq(packages.split(/\n+/))
end
end
end
- 1
context('when given unknown platform') do
- 3
let(:dummy_class) { Class.new { include SyslogNg::InstallHelpers } }
- 1
it 'raises RuntimeError' do
- 2
expect { dummy_class.new.repo_get_packages(platform: 'unknown') }.to raise_exception(RuntimeError)
end
end
end
- 1
describe '.installed_get_packages' do
- 1
platforms = {
'rhel' => "syslog-ng-debuginfo\nsyslog-ng-devel\nsyslog-ng-geoip\nsyslog-ng-http\nsyslog-ng-java\nsyslog-ng-java-deps\nsyslog-ng-json\nsyslog-ng-libdbi\nsyslog-ng-mongodb\nsyslog-ng-python\nsyslog-ng-redis\nsyslog-ng-riemann\nsyslog-ng-smtp\nsyslog-ng\n",
'fedora' => "syslog-ng\nsyslog-ng-http\nsyslog-ng-smtp\nsyslog-ng-http\nsyslog-ng-smtp\nsyslog-ng-amqp\nsyslog-ng-geoip\nsyslog-ng-redis\nsyslog-ng-geoip\nsyslog-ng-redis\nsyslog-ng-libdbi\nsyslog-ng-devel\nsyslog-ng-riemann\nsyslog-ng-devel\nsyslog-ng-riemann\nsyslog-ng-devel\nsyslog-ng-mongodb\nsyslog-ng-java\nsyslog-ng-python\nsyslog-ng-debugsource\nsyslog-ng-python\nsyslog-ng-java-deps\nsyslog-ng-debuginfo\nsyslog-ng-http-debuginfo\nsyslog-ng-java-debuginfo\nsyslog-ng-smtp-debuginfo\nsyslog-ng-geoip-debuginfo\nsyslog-ng-redis-debuginfo\nsyslog-ng-libdbi-debuginfo\nsyslog-ng-python-debuginfo\nsyslog-ng-riemann-debuginfo\n",
'debian' => "syslog-ng\nsyslog-ng-core\nsyslog-ng-dbg\nsyslog-ng-dev\nsyslog-ng-mod-add-contextual-data\nsyslog-ng-mod-amqp\nsyslog-ng-mod-geoip\nsyslog-ng-mod-graphite\nsyslog-ng-mod-journal\nsyslog-ng-mod-json\nsyslog-ng-mod-mongodb\nsyslog-ng-mod-python\nsyslog-ng-mod-redis\nsyslog-ng-mod-riemann\nsyslog-ng-mod-smtp\nsyslog-ng-mod-sql\nsyslog-ng-mod-stomp\nsyslog-ng-mod-basicfuncs-plus\nsyslog-ng-mod-date\nsyslog-ng-mod-grok\nsyslog-ng-mod-kafka\nsyslog-ng-mod-lua\nsyslog-ng-mod-perl\nsyslog-ng-mod-rss\nsyslog-ng-mod-trigger\nsyslog-ng-mod-zmq\n",
}
- 1
platforms.each do |platform, packages|
- 3
context("when called with #{platform} platform") do
- 3
let(:shellout) do
- 3
double(run_command: nil, error!: nil, stdout: '', stderr: '', exitstatus: 0, live_stream: '')
end
- 3
it "return syslog-ng packages for #{platform}" do
- 3
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout)
- 3
allow(shellout).to receive(:error!).and_return(nil)
- 3
allow(shellout).to receive(:stdout).and_return(packages)
- 3
expect(dummy_class.new.installed_get_packages(platform: platform)).to be_a(Array)
- 3
expect(dummy_class.new.installed_get_packages(platform: platform)).to eq(packages.split(/\n+/))
end
end
end
- 1
context('when given unknown platform') do
- 3
let(:dummy_class) { Class.new { include SyslogNg::InstallHelpers } }
- 1
it 'raises RuntimeError' do
- 2
expect { dummy_class.new.installed_get_packages(platform: 'unknown') }.to raise_exception(RuntimeError)
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: rewrite_helpers_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'SyslogNg::RewriteHelpers' do
- 19
let(:dummy_class) { Class.new { include SyslogNg::RewriteHelpers } }
- 1
describe '.rewrite_builder' do
- 1
context('given subst rewrite') do
- 1
param = {
'function' => 'subst',
'match' => 'IP',
'replacement' => 'IP-Address',
'value' => 'MESSAGE',
'flags' => nil,
'condition' => nil,
'additional_options' => {},
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('subst("IP", "IP-Address", value("MESSAGE"))')
end
end
- 1
context('given set rewrite') do
- 1
param = {
'function' => 'set',
'match' => 'myhost',
'value' => 'HOST',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('set("myhost", value("HOST"))')
end
end
- 1
context('given set rewrite with condition') do
- 1
param = {
'function' => 'set',
'match' => 'myhost',
'value' => 'HOST',
'condition' => 'program("myapplication")',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('set("myhost", value("HOST") condition(program("myapplication")))')
end
end
- 1
context('given unset rewrite') do
- 1
param = {
'function' => 'unset',
'value' => 'HOST',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('unset(value("HOST"))')
end
end
- 1
context('given groupunset rewrite') do
- 1
param = {
'function' => 'groupunset',
'values' => '.SDATA.*',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('groupunset(values(".SDATA.*"))')
end
end
- 1
context('given groupset rewrite') do
- 1
param = {
'function' => 'groupset',
'match' => 'myhost',
'values' => %w(HOST FULLHOST),
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('groupset("myhost", values("HOST", "FULLHOST"))')
end
end
- 1
context('given set-tag rewrite') do
- 1
param = {
'function' => 'set-tag',
'tags' => [
'test-tag-01',
'test-tag-02',
],
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('set-tag("test-tag-01", "test-tag-02")')
end
end
- 1
context('given clear-tag rewrite') do
- 1
param = {
'function' => 'clear-tag',
'tags' => [
'test-tag-01',
],
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('clear-tag("test-tag-01")')
end
end
- 1
context('given credit-card-mask rewrite') do
- 1
param = {
'function' => 'credit-card-mask',
'value' => 'cc_field',
}
- 1
it 'returns valid config string' do
- 1
expect(dummy_class.new.rewrite_builder(param)).to be_a(String)
- 1
expect(dummy_class.new.rewrite_builder(param)).to eql('credit-card-mask(value("cc_field"))')
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: source_helpers_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'SyslogNg::SourceHelpers' do
- 17
let(:dummy_class) { Class.new { include SyslogNg::SourceHelpers } }
- 1
describe '.source_builder sources' do
- 1
context('given driver with no parameters') do
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'system', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'system', parameters: {})).to eql('system();')
end
end
- 1
context('given driver with parameters') do
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'system', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'udp', parameters: { 'parameters' => { 'ip' => '0.0.0.0', 'port' => 514 } })).to eql('udp(ip(0.0.0.0) port(514));')
end
end
- 1
context('given driver with parameters as an array as string') do
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: { 'parameters' => ['ip("127.0.0.1")', 'port(5514)'] })).to eql('network(ip("127.0.0.1") port(5514));')
end
end
- 1
context('given driver with parameters as an array with non-string') do
- 1
param = {
'parameters' => {
'ip' => [
'127.0.0.1',
],
'port' => [
5614,
],
},
}
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: param)).to eql('network(ip(127.0.0.1) port(5614));')
end
end
- 1
context('given driver with parameter as an array with multiple non-string') do # There is no valid config I can see that would use this but it validates a code path.
- 1
param = {
'parameters' => {
'ip' => [
'127.0.0.1',
],
'port' => [
5614,
5714,
],
},
}
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: param)).to eql('network(ip(127.0.0.1) port("5614 5714"));')
end
end
- 1
context('given driver with parameters as a hash containing an array') do
- 1
param = {
'parameters' => {
'program-override' => 'testing',
'use_fqdn' => 'yes',
'tags' => %w(test_tag_01 test_tag_02),
},
}
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'internal', parameters: {})).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'internal', parameters: param)).to eql('internal(program-override("testing") use_fqdn(yes) tags("test_tag_01", "test_tag_02"));')
end
end
- 1
context('given nested source driver config') do
- 1
param = {
'parameters' => {
'transport' => 'tls',
'ip' => '127.0.0.1',
'port' => 9999,
'tls' => {
'peer-verify' => 'required-trusted',
'key-file' => '/etc/syslog-ng/tls/syslog-ng.key',
'cert-file' => '/etc/syslog-ng/tls/syslog-ng.crt',
},
},
}
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: param)).to be_a(String)
- 1
expect(dummy_class.new.source_builder(driver: 'network', parameters: param)).to eql('network(transport("tls") ip(127.0.0.1) port(9999) tls(peer-verify("required-trusted") key-file("/etc/syslog-ng/tls/syslog-ng.key") cert-file("/etc/syslog-ng/tls/syslog-ng.crt")));')
end
end
- 1
context('given driver with parameters and multiline set') do
- 1
it 'returns config string' do
- 1
expect(dummy_class.new.source_builder(driver: 'system', parameters: {}, multiline: true)).to be_a(Array)
- 1
expect(dummy_class.new.source_builder(driver: 'udp', parameters: { 'parameters' => { 'ip' => '0.0.0.0', 'port' => 514 } }, multiline: true)).to eql(['udp(', ' ip(0.0.0.0)', ' port(514)', ');'])
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: destination_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::config_global' do
- 1
platforms = {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
}
- 1
platforms.each do |platform, version|
- 5
context "With test recipe, on #{platform} #{version}" do
- 5
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 10
runner = ChefSpec::SoloRunner.new(platform: platform.dup.downcase!, version: version)
- 10
runner.converge(described_recipe)
end
- 5
it 'converges successfully' do
- 10
expect { chef_run }.to_not raise_error
end
- 5
it 'creates global config file' do
- 5
expect(chef_run).to create_syslog_ng_config_global('/etc/syslog-ng/syslog-ng.conf')
- 5
config_test = chef_run.execute('syslog-ng-config-test')
- 5
expect(config_test).to do_nothing
- 5
expect(chef_run).to start_service('syslog-ng')
- 5
expect(chef_run).to enable_service('syslog-ng')
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: destination_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::destination' do
- 1
platforms = {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
}
- 1
platforms.each do |platform, version|
- 5
context "With test recipe, on #{platform} #{version}" do
- 5
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 35
runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.6.1804')
- 35
runner.converge(described_recipe)
end
- 5
it 'converges successfully' do
- 10
expect { chef_run }.to_not raise_error
end
- 5
%w(d_test_file d_test_file_params d_test_mongo_params d_test_multi_file d_test_multi_file_multiline d_test_multi_file_alternative).each do |testdestination|
- 30
it "creates destination #{testdestination}" do
- 30
expect(chef_run).to create_syslog_ng_destination(testdestination)
- 30
dest = chef_run.syslog_ng_destination(testdestination)
- 30
expect(dest).to notify('execute[syslog-ng-config-test]').to(:run).delayed
- 30
expect(dest).to notify('service[syslog-ng]').to(:reload).delayed
end
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: filter_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::filter' do
- 1
platforms = {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
}
- 1
platforms.each do |platform, version|
- 5
context "With test recipe, on #{platform} #{version}" do
- 5
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 35
runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.6.1804')
- 35
runner.converge(described_recipe)
end
- 5
it 'converges successfully' do
- 10
expect { chef_run }.to_not raise_error
end
- 5
%w(f_test f_test_contained f_test_array_and f_test_array_or f_test_raw_string f_test_raw_string_array).each do |testfilter|
- 30
it "creates test filter #{testfilter}" do
- 30
expect(chef_run).to create_syslog_ng_filter(testfilter)
- 30
filter = chef_run.syslog_ng_filter(testfilter)
- 30
expect(filter).to notify('execute[syslog-ng-config-test]').to(:run).delayed
- 30
expect(filter).to notify('service[syslog-ng]').to(:reload).delayed
end
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: destination_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::install' do
- 1
tests = {
'syslog_ng_test::package_distro' => {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
},
'syslog_ng_test::package_latest' => {
'CentOS' => '7.6.1804',
'Fedora' => '29',
},
}
- 1
tests.each do |resource, platforms|
- 2
platforms.each do |platform, version|
- 7
context "With test recipe, on #{platform} #{version}" do
- 7
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 14
runner = ChefSpec::SoloRunner.new(platform: platform.dup.downcase!, version: version)
- 14
runner.converge(resource)
end
- 7
it 'converges successfully' do
- 14
expect { chef_run }.to_not raise_error
end
- 7
it 'installs syslog-ng' do
- 7
expect(chef_run).to install_syslog_ng_install('')
end
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: filter_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::log' do
- 1
platforms = {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
}
- 1
platforms.each do |platform, version|
- 5
context "With test recipe, on #{platform} #{version}" do
- 5
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 15
runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.6.1804')
- 15
runner.converge(described_recipe)
end
- 5
it 'converges successfully' do
- 10
expect { chef_run }.to_not raise_error
end
- 5
%w(l_test l_test_embedded).each do |testlog|
- 10
it 'creates log' do
- 10
expect(chef_run).to create_syslog_ng_log(testlog)
- 10
log = chef_run.syslog_ng_log(testlog)
- 10
expect(log).to notify('execute[syslog-ng-config-test]').to(:run).delayed
- 10
expect(log).to notify('service[syslog-ng]').to(:reload).delayed
end
end
end
end
end
#
# Cookbook:: syslog_ng
# Spec:: filter_spec
#
# Copyright:: 2018, Ben Hughes <bmhughes@bmhughes.co.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 1
require 'spec_helper'
- 1
describe 'syslog_ng_test::source' do
- 1
platforms = {
'CentOS' => '7.6.1804',
'Fedora' => '29',
'Amazon' => '2',
'Debian' => '9.6',
'Ubuntu' => '18.04',
}
- 1
platforms.each do |platform, version|
- 5
context "With test recipe, on #{platform} #{version}" do
- 5
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
- 30
runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.6.1804')
- 30
runner.converge(described_recipe)
end
- 5
it 'converges successfully' do
- 10
expect { chef_run }.to_not raise_error
end
- 5
%w(s_test_tcp s_test_pipe s_test_tcpudp s_test_network_multiline s_test_network_multiple).each do |testsource|
- 25
it "creates source #{testsource}" do
- 25
expect(chef_run).to create_syslog_ng_source(testsource)
- 25
source = chef_run.syslog_ng_source(testsource)
- 25
expect(source).to notify('execute[syslog-ng-config-test]').to(:run).delayed
- 25
expect(source).to notify('service[syslog-ng]').to(:reload).delayed
end
end
end
end
end