-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor defined type Splunk::Addon #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth checking that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class['splunk'] is now completely empty since the 7.2 refactor: https://github.com/voxpupuli/puppet-splunk/pull/215/files#diff-60ae41fd0a31977447947f59940ee9a4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't hurt. |
||
$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]') } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unreachable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct and the reason I didn't originally add the default statement. Only added it to get it to pass lint checks. Not a bad thing to have, I suppose...? If the manifest parses this far then something strange is happening an it'd be good to explicitly fail before damage is done. |
||
} | ||
} | ||
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? Iterating an empty hash is fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct. Just didn't realize. Tested just now and works fine without testing first |
||
$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.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t be necessary if it’s a requirement that one of
splunk
orsplunk:forwarder
has been included already?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that should be correct. Didn't dawn me at the time.