|
| 1 | +# @summary Defined type for deploying Splunk Add-ons and Apps from either OS packages or via splunkbase compatible archives |
1 | 2 | #
|
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 | +# } |
7 | 20 | #
|
8 |
| -# Examples |
| 21 | +# @see https://docs.splunk.com/Documentation/AddOns/released/Overview/AboutSplunkadd-ons |
9 | 22 | #
|
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] |
13 | 25 | #
|
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 |
19 | 28 | #
|
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 |
22 | 31 | #
|
| 32 | +# @param package_name |
| 33 | +# The OS package to install if you are not installing via splunk compatible archive |
23 | 34 | #
|
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 |
34 | 37 | #
|
35 | 38 | define splunk::addon (
|
36 | 39 | Optional[Stdlib::Absolutepath] $splunk_home = undef,
|
37 | 40 | Boolean $package_manage = true,
|
| 41 | + Optional[String[1]] $splunkbase_source = undef, |
38 | 42 | Optional[String[1]] $package_name = undef,
|
39 | 43 | Hash $inputs = {},
|
40 | 44 | ) {
|
41 | 45 |
|
42 |
| - include 'splunk::params' |
| 46 | + include splunk::params |
| 47 | + |
| 48 | + if defined(Class['splunk::forwarder']) { |
| 49 | + $mode = 'forwarder' |
| 50 | + } else { |
| 51 | + $mode = 'enterprise' |
| 52 | + } |
43 | 53 |
|
44 | 54 | if $splunk_home {
|
45 | 55 | $_splunk_home = $splunk_home
|
46 | 56 | }
|
47 | 57 | 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 | + } |
49 | 63 | }
|
50 | 64 |
|
51 | 65 | 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 | + } |
55 | 82 | }
|
56 | 83 | }
|
57 | 84 |
|
58 |
| - file { "${_splunk_home}/etc/apps/${name}/local": |
59 |
| - ensure => directory, |
60 |
| - } |
| 85 | + file { "${_splunk_home}/etc/apps/${name}/local": ensure => directory } |
61 | 86 |
|
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 | + } |
66 | 112 | }
|
67 |
| - |
68 |
| - create_resources('splunk::addon::input', $inputs, {'addon' => $name }) |
69 | 113 | }
|
70 |
| - |
71 | 114 | }
|
72 | 115 |
|
0 commit comments