Skip to content

Commit

Permalink
[WIP] Refactor defined type splunk::addon
Browse files Browse the repository at this point in the history
	Transitions the defined type splunk::addon to using the
	splunk*_input types instead of concat, supports installation
	from splunkbase provided archive, and valid for use on more
	than just forwarder nodes.
  • Loading branch information
ody committed Apr 10, 2019
1 parent fa08184 commit fbffdcc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
68 changes: 53 additions & 15 deletions manifests/addon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,76 @@
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('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 }
}
}

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"],
}
}
}
}
}

create_resources('splunk::addon::input', $inputs, {'addon' => $name })
}

}

17 changes: 0 additions & 17 deletions manifests/addon/input.pp

This file was deleted.

6 changes: 0 additions & 6 deletions templates/addon/_input.erb

This file was deleted.

0 comments on commit fbffdcc

Please sign in to comment.