Skip to content

Commit 820a15b

Browse files
authored
Merge pull request voxpupuli#224 from ody/refactor_addon_management
Refactor defined type Splunk::Addon
2 parents 1f0954d + 3964ea7 commit 820a15b

File tree

4 files changed

+86
-66
lines changed

4 files changed

+86
-66
lines changed

manifests/addon.pp

+84-41
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,115 @@
1+
# @summary Defined type for deploying Splunk Add-ons and Apps from either OS packages or via splunkbase compatible archives
12
#
2-
# Defined type: splunk::addon
3-
#
4-
# This define sets up a TA (Technology Addon) for Splunk. It (optionally)
5-
# installed a package, and configures input forwarders in
6-
# $SPLUNK_HOME/etc/apps/<app name>/local/inputs.conf
3+
# @example Basic usage
4+
# splunk::addon { 'Splunk_TA_nix':
5+
# splunkbase_source => 'puppet:///modules/splunk_qd/addons/splunk-add-on-for-unix-and-linux_602.tgz',
6+
# inputs => {
7+
# 'monitor:///var/log' => {
8+
# 'whitelist' => '(\.log|log$|messages|secure|auth|mesg$|cron$|acpid$|\.out)',
9+
# 'blacklist' => '(lastlog|anaconda\.syslog)',
10+
# 'disabled' => 'false'
11+
# },
12+
# 'script://./bin/uptime.sh' => {
13+
# 'disabled' => 'false',
14+
# 'interval' => '86400',
15+
# 'source' => 'Unix:Uptime',
16+
# 'sourcetype' => 'Unix:Uptime'
17+
# }
18+
# }
19+
# }
720
#
8-
# Examples
21+
# @see https://docs.splunk.com/Documentation/AddOns/released/Overview/AboutSplunkadd-ons
922
#
10-
# splunk::addon { 'search':
11-
# package_manage => false,
12-
# }
23+
# @param splunk_home
24+
# Overrides the default Splunk installation target values from Class[splunk::params]
1325
#
14-
# splunk::addon::input { 'monitor:///var/log/messages':
15-
# attributes => {
16-
# 'index' => 'server_t',
17-
# },
18-
# }
26+
# @param package_manage
27+
# If a package should be installed as part of declaring a new instance of Splunk::Addon
1928
#
20-
# Alternatively you can feed inputs directly into splunk::addon using the
21-
# inputs parameter (useful if you are configuring from Hiera)
29+
# @param splunkbase_source
30+
# When set the add-on will be installed from a splunkbase compatible archive instead of OS packages
2231
#
32+
# @param package_name
33+
# The OS package to install if you are not installing via splunk compatible archive
2334
#
24-
# splunk::addon { 'search':
25-
# package_manage => false,
26-
# inputs => {
27-
# 'monitor:///var/log/messages' => {
28-
# 'attributes' => {
29-
# 'index' => 'server_t',
30-
# }
31-
# }
32-
# }
33-
# }
35+
# @param inputs
36+
# A hash of inputs to be configured as part of add-on installation, alterntively you can also define splunk_input or splunkforwarder_input resouces seperately
3437
#
3538
define splunk::addon (
3639
Optional[Stdlib::Absolutepath] $splunk_home = undef,
3740
Boolean $package_manage = true,
41+
Optional[String[1]] $splunkbase_source = undef,
3842
Optional[String[1]] $package_name = undef,
3943
Hash $inputs = {},
4044
) {
4145

42-
include 'splunk::params'
46+
include splunk::params
47+
48+
if defined(Class['splunk::forwarder']) {
49+
$mode = 'forwarder'
50+
} else {
51+
$mode = 'enterprise'
52+
}
4353

4454
if $splunk_home {
4555
$_splunk_home = $splunk_home
4656
}
4757
else {
48-
$_splunk_home = $splunk::params::forwarder_homedir
58+
case $mode {
59+
'forwarder': { $_splunk_home = $splunk::params::forwarder_homedir }
60+
'enterprise': { $_splunk_home = $splunk::params::enterprise_homedir }
61+
default: { fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]') }
62+
}
4963
}
5064

5165
if $package_manage {
52-
package { $package_name:
53-
ensure => installed,
54-
before => File["${_splunk_home}/etc/apps/${name}/local"],
66+
if $splunkbase_source {
67+
$archive_name = $splunkbase_source.split('/')[-1]
68+
archive { $name:
69+
path => "${splunk::params::staging_dir}/${archive_name}",
70+
source => $splunkbase_source,
71+
extract => true,
72+
extract_path => "${_splunk_home}/etc/apps",
73+
creates => "${_splunk_home}/etc/apps/${name}",
74+
cleanup => true,
75+
before => File["${_splunk_home}/etc/apps/${name}/local"],
76+
}
77+
} else {
78+
package { $package_name:
79+
ensure => installed,
80+
before => File["${_splunk_home}/etc/apps/${name}/local"],
81+
}
5582
}
5683
}
5784

58-
file { "${_splunk_home}/etc/apps/${name}/local":
59-
ensure => directory,
60-
}
85+
file { "${_splunk_home}/etc/apps/${name}/local": ensure => directory }
6186

62-
if $inputs {
63-
concat { "splunk::addon::inputs_${name}":
64-
path => "${_splunk_home}/etc/apps/${name}/local/inputs.conf",
65-
require => File["${_splunk_home}/etc/apps/${name}/local"],
87+
unless $inputs.empty {
88+
$inputs.each |$section, $attributes| {
89+
$attributes.each |$setting, $value| {
90+
case $mode {
91+
'forwarder': {
92+
splunkforwarder_input { "${name}_${section}_${setting}":
93+
section => $section,
94+
setting => $setting,
95+
value => $value,
96+
context => "apps/${name}/local",
97+
require => File["${_splunk_home}/etc/apps/${name}/local"],
98+
}
99+
}
100+
'enterprise': {
101+
splunk_input { "${name}_${section}_${setting}":
102+
section => $section,
103+
setting => $setting,
104+
value => $value,
105+
context => "apps/${name}/local",
106+
require => File["${_splunk_home}/etc/apps/${name}/local"],
107+
}
108+
}
109+
default: { fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]') }
110+
}
111+
}
66112
}
67-
68-
create_resources('splunk::addon::input', $inputs, {'addon' => $name })
69113
}
70-
71114
}
72115

manifests/addon/input.pp

-17
This file was deleted.

spec/defines/addon_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
let(:facts) do
1111
facts
1212
end
13-
let(:title) { 'someaddon' }
14-
let(:params) { { 'package_name' => 'foo' } }
13+
let(:title) { 'Splunk_TA' }
14+
let(:params) { { 'splunkbase_source' => 'puppet:///modules/profiles/splunk-add-on.tgz' } }
1515

1616
it { is_expected.to compile.with_all_deps }
1717
end

templates/addon/_input.erb

-6
This file was deleted.

0 commit comments

Comments
 (0)