Skip to content

Commit

Permalink
Merge pull request #225 from ody/pr_224_fixups
Browse files Browse the repository at this point in the history
Address post-merge comments on PR #224
  • Loading branch information
alexjfisher committed Apr 30, 2019
2 parents 36ff15d + 8bc72fd commit eaef302
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
50 changes: 24 additions & 26 deletions manifests/addon.pp
Expand Up @@ -43,18 +43,18 @@
Hash $inputs = {},
) {

include splunk::params

if defined(Class['splunk::forwarder']) {
$mode = 'forwarder'
} else {
} elsif defined(Class['splunk::enterprise']) {
$mode = 'enterprise'
} else {
fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]')
}


if $splunk_home {
$_splunk_home = $splunk_home
}
else {
} else {
case $mode {
'forwarder': { $_splunk_home = $splunk::params::forwarder_homedir }
'enterprise': { $_splunk_home = $splunk::params::enterprise_homedir }
Expand Down Expand Up @@ -84,30 +84,28 @@

file { "${_splunk_home}/etc/apps/${name}/local": ensure => directory }

unless $inputs.empty {
$inputs.each |$section, $attributes| {
$attributes.each |$setting, $value| {
case $mode {
'forwarder': {
splunkforwarder_input { "${name}_${section}_${setting}":
section => $section,
setting => $setting,
value => $value,
context => "apps/${name}/local",
require => File["${_splunk_home}/etc/apps/${name}/local"],
}
$inputs.each |$section, $attributes| {
$attributes.each |$setting, $value| {
case $mode {
'forwarder': {
splunkforwarder_input { "${name}_${section}_${setting}":
section => $section,
setting => $setting,
value => $value,
context => "apps/${name}/local",
require => File["${_splunk_home}/etc/apps/${name}/local"],
}
'enterprise': {
splunk_input { "${name}_${section}_${setting}":
section => $section,
setting => $setting,
value => $value,
context => "apps/${name}/local",
require => File["${_splunk_home}/etc/apps/${name}/local"],
}
}
'enterprise': {
splunk_input { "${name}_${section}_${setting}":
section => $section,
setting => $setting,
value => $value,
context => "apps/${name}/local",
require => File["${_splunk_home}/etc/apps/${name}/local"],
}
default: { fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]') }
}
default: { fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]') }
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions spec/defines/addon_spec.rb
@@ -1,7 +1,29 @@
require 'spec_helper'

describe 'splunk::addon' do
context 'fail if class prerequisit not declared' do
on_supported_os.each do |os, facts|
if os.start_with?('windows')
# Splunk Server not used supported on windows
else
context "on #{os}" do
let(:facts) do
facts
end
let(:title) { 'Splunk_TA' }
let(:params) { { 'splunkbase_source' => 'puppet:///modules/profiles/splunk-add-on.tgz' } }

it { is_expected.to raise_error(Puppet::Error) }
end
end
end
end

context 'supported operating systems' do
let(:pre_condition) do
'include splunk::forwarder'
end

on_supported_os.each do |os, facts|
if os.start_with?('windows')
# Splunk Server not used supported on windows
Expand Down

0 comments on commit eaef302

Please sign in to comment.