-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from ody/refactor_addon_management
Refactor defined type Splunk::Addon
- Loading branch information
Showing
4 changed files
with
86 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,115 @@ | ||
# @summary Defined type for deploying Splunk Add-ons and Apps from either OS packages or via splunkbase compatible archives | ||
# | ||
# Defined type: splunk::addon | ||
# | ||
# This define sets up a TA (Technology Addon) for Splunk. It (optionally) | ||
# installed a package, and configures input forwarders in | ||
# $SPLUNK_HOME/etc/apps/<app name>/local/inputs.conf | ||
# @example Basic usage | ||
# splunk::addon { 'Splunk_TA_nix': | ||
# splunkbase_source => 'puppet:///modules/splunk_qd/addons/splunk-add-on-for-unix-and-linux_602.tgz', | ||
# inputs => { | ||
# 'monitor:///var/log' => { | ||
# 'whitelist' => '(\.log|log$|messages|secure|auth|mesg$|cron$|acpid$|\.out)', | ||
# 'blacklist' => '(lastlog|anaconda\.syslog)', | ||
# 'disabled' => 'false' | ||
# }, | ||
# 'script://./bin/uptime.sh' => { | ||
# 'disabled' => 'false', | ||
# 'interval' => '86400', | ||
# 'source' => 'Unix:Uptime', | ||
# 'sourcetype' => 'Unix:Uptime' | ||
# } | ||
# } | ||
# } | ||
# | ||
# Examples | ||
# @see https://docs.splunk.com/Documentation/AddOns/released/Overview/AboutSplunkadd-ons | ||
# | ||
# splunk::addon { 'search': | ||
# package_manage => false, | ||
# } | ||
# @param splunk_home | ||
# Overrides the default Splunk installation target values from Class[splunk::params] | ||
# | ||
# splunk::addon::input { 'monitor:///var/log/messages': | ||
# attributes => { | ||
# 'index' => 'server_t', | ||
# }, | ||
# } | ||
# @param package_manage | ||
# If a package should be installed as part of declaring a new instance of Splunk::Addon | ||
# | ||
# Alternatively you can feed inputs directly into splunk::addon using the | ||
# inputs parameter (useful if you are configuring from Hiera) | ||
# @param splunkbase_source | ||
# When set the add-on will be installed from a splunkbase compatible archive instead of OS packages | ||
# | ||
# @param package_name | ||
# The OS package to install if you are not installing via splunk compatible archive | ||
# | ||
# splunk::addon { 'search': | ||
# package_manage => false, | ||
# inputs => { | ||
# 'monitor:///var/log/messages' => { | ||
# 'attributes' => { | ||
# 'index' => 'server_t', | ||
# } | ||
# } | ||
# } | ||
# } | ||
# @param inputs | ||
# 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 | ||
# | ||
define splunk::addon ( | ||
Optional[Stdlib::Absolutepath] $splunk_home = undef, | ||
Boolean $package_manage = true, | ||
Optional[String[1]] $splunkbase_source = undef, | ||
Optional[String[1]] $package_name = undef, | ||
Hash $inputs = {}, | ||
) { | ||
|
||
include 'splunk::params' | ||
include splunk::params | ||
|
||
if defined(Class['splunk::forwarder']) { | ||
$mode = 'forwarder' | ||
} else { | ||
$mode = 'enterprise' | ||
} | ||
|
||
if $splunk_home { | ||
$_splunk_home = $splunk_home | ||
} | ||
else { | ||
$_splunk_home = $splunk::params::forwarder_homedir | ||
case $mode { | ||
'forwarder': { $_splunk_home = $splunk::params::forwarder_homedir } | ||
'enterprise': { $_splunk_home = $splunk::params::enterprise_homedir } | ||
default: { fail('Instances of Splunk::Addon require the declaration of one of either Class[splunk::enterprise] or Class[splunk::forwarder]') } | ||
} | ||
} | ||
|
||
if $package_manage { | ||
package { $package_name: | ||
ensure => installed, | ||
before => File["${_splunk_home}/etc/apps/${name}/local"], | ||
if $splunkbase_source { | ||
$archive_name = $splunkbase_source.split('/')[-1] | ||
archive { $name: | ||
path => "${splunk::params::staging_dir}/${archive_name}", | ||
source => $splunkbase_source, | ||
extract => true, | ||
extract_path => "${_splunk_home}/etc/apps", | ||
creates => "${_splunk_home}/etc/apps/${name}", | ||
cleanup => true, | ||
before => File["${_splunk_home}/etc/apps/${name}/local"], | ||
} | ||
} else { | ||
package { $package_name: | ||
ensure => installed, | ||
before => File["${_splunk_home}/etc/apps/${name}/local"], | ||
} | ||
} | ||
} | ||
|
||
file { "${_splunk_home}/etc/apps/${name}/local": | ||
ensure => directory, | ||
} | ||
file { "${_splunk_home}/etc/apps/${name}/local": ensure => directory } | ||
|
||
if $inputs { | ||
concat { "splunk::addon::inputs_${name}": | ||
path => "${_splunk_home}/etc/apps/${name}/local/inputs.conf", | ||
require => File["${_splunk_home}/etc/apps/${name}/local"], | ||
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"], | ||
} | ||
} | ||
'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]') } | ||
} | ||
} | ||
} | ||
|
||
create_resources('splunk::addon::input', $inputs, {'addon' => $name }) | ||
} | ||
|
||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.