Skip to content

Commit

Permalink
Merge pull request #350 from siegy22/master
Browse files Browse the repository at this point in the history
Ensure compatibility with Splunk 9.2.0.1 and 9.0.0
  • Loading branch information
bastelfreak authored Mar 22, 2024
2 parents 3dca215 + 3ddde7a commit 6fd47b8
Show file tree
Hide file tree
Showing 9 changed files with 536 additions and 363 deletions.
14 changes: 10 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,13 @@ Data type: `String[1]`

The user to run Splunk as.

Default value: `$splunk::params::splunk_user`
Default value:

```puppet
versioncmp($version, '9.1.0') ? {
-1 => $splunk::params::splunk_user,
default => 'splunkfwd'
```

##### <a name="-splunk--forwarder--forwarder_homedir"></a>`forwarder_homedir`

Expand Down Expand Up @@ -1495,7 +1501,7 @@ Data type: `String[1]`
The version of Splunk to install. This will be in the form x.y.z; e.g.
"4.3.2".

Default value: `'7.2.4.2'`
Default value: `'9.2.0.1'`

##### <a name="-splunk--params--build"></a>`build`

Expand All @@ -1507,7 +1513,7 @@ automatically but a build number must be supplied in order to correctly
construct the path to the packages. A build number will be six digits;
e.g. "123586".

Default value: `'fb30470262e3'`
Default value: `'d8ae995bf219'`

##### <a name="-splunk--params--splunkd_port"></a>`splunkd_port`

Expand Down Expand Up @@ -1545,7 +1551,7 @@ Default value:
```puppet
$facts['os']['family'] ? {
'windows' => 'Administrator',
default => 'root'
default => versioncmp($version, '8.0.0') ? { -1 => 'root', default => 'splunk'
```

##### <a name="-splunk--params--src_root"></a>`src_root`
Expand Down
9 changes: 7 additions & 2 deletions manifests/enterprise/install/nix.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
}
}

# Required for splunk 7.2.4.2
if $splunk::params::manage_net_tools and versioncmp($splunk::enterprise::version, '7.2.4.2') >= 0 {
# Required for splunk from 7.2.4.2 until 8.0.0
if (
$splunk::params::manage_net_tools and
$facts['kernel'] == 'Linux' and
versioncmp($splunk::enterprise::version, '7.2.4.2') >= 0 and
versioncmp($splunk::enterprise::version, '8.0.0') == -1
) {
stdlib::ensure_packages(['net-tools'], {
'ensure' => 'present',
})
Expand Down
5 changes: 4 additions & 1 deletion manifests/forwarder.pp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@
Boolean $manage_package_source = true,
Optional[String[1]] $package_source = undef,
Splunk::Fwdinstalloptions $install_options = $splunk::params::forwarder_install_options,
String[1] $splunk_user = $splunk::params::splunk_user,
String[1] $splunk_user = versioncmp($version, '9.1.0') ? {
-1 => $splunk::params::splunk_user,
default => 'splunkfwd',
},
Stdlib::Absolutepath $forwarder_homedir = $splunk::params::forwarder_homedir,
Stdlib::Absolutepath $forwarder_confdir = $splunk::params::forwarder_confdir,
String[1] $service_name = $splunk::params::forwarder_service,
Expand Down
9 changes: 7 additions & 2 deletions manifests/forwarder/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@
}
}

# Required for splunk 7.2.4.2
if $splunk::params::manage_net_tools and $facts['kernel'] == 'Linux' and (versioncmp($splunk::forwarder::version, '7.2.4.2') >= 0) {
# Required for splunk from 7.2.4.2 until 8.0.0
if (
$splunk::params::manage_net_tools and
$facts['kernel'] == 'Linux' and
versioncmp($splunk::forwarder::version, '7.2.4.2') >= 0 and
versioncmp($splunk::forwarder::version, '8.0.0') == -1
) {
stdlib::ensure_packages(['net-tools'], {
'ensure' => 'present',
})
Expand Down
19 changes: 13 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
# Disable certificate verification when connecting to SSL hosts to download packages.
#
class splunk::params (
String[1] $version = '7.2.4.2',
String[1] $build = 'fb30470262e3',
String[1] $version = '9.2.0.1',
String[1] $build = 'd8ae995bf219',
String[1] $src_root = 'https://download.splunk.com',
Stdlib::Port $splunkd_port = 8089,
Stdlib::Port $logging_port = 9997,
Expand All @@ -112,7 +112,7 @@
Boolean $boot_start = true,
String[1] $splunk_user = $facts['os']['family'] ? {
'windows' => 'Administrator',
default => 'root'
default => versioncmp($version, '8.0.0') ? { -1 => 'root', default => 'splunk' },
},
String[1] $default_host = $facts['clientcert'],
Boolean $manage_net_tools = true,
Expand Down Expand Up @@ -302,6 +302,13 @@
default: { $package_provider = undef } # Don't define a $package_provider
}

# Download URLs changed starting from 8.2.11 and 9.0.5 for RPMs.
# Splunk no longer includes "-linux-2.6-".
$linux_prefix = (versioncmp($version, '9.0.5') >= 0 or (versioncmp($version, '8.2.11') >= 0 and versioncmp($version, '9.0.0') == -1)) ? {
true => '.',
false => '-linux-2.6-',
}

# Settings specific to an architecture as well as an OS family
case "${facts['os']['family']} ${facts['os']['architecture']}" {
'RedHat i386': {
Expand All @@ -310,12 +317,12 @@
$enterprise_package_name = 'splunk'
}
'RedHat x86_64': {
$package_suffix = "${version}-${build}-linux-2.6-x86_64.rpm"
$package_suffix = "${version}-${build}${linux_prefix}x86_64.rpm"
$forwarder_package_name = 'splunkforwarder'
$enterprise_package_name = 'splunk'
}
'RedHat ppc64le': {
$package_suffix = "${version}-${build}-linux-2.6-ppc64le.rpm"
$package_suffix = "${version}-${build}${linux_prefix}ppc64le.rpm"
$forwarder_package_name = 'splunkforwarder'
$enterprise_package_name = 'splunk'
}
Expand Down Expand Up @@ -350,7 +357,7 @@
$enterprise_package_name = 'splunk'
}
'Suse x86_64': {
$package_suffix = "${version}-${build}-linux-2.6-x86_64.rpm"
$package_suffix = "${version}-${build}${linux_prefix}x86_64.rpm"
$forwarder_package_name = 'splunkforwarder'
$enterprise_package_name = 'splunk'
}
Expand Down
52 changes: 49 additions & 3 deletions spec/acceptance/splunk_enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,51 @@
'splunk'
end

OLD_SPLUNK_VERSIONS.each do |version, build|
context "Splunk version #{version}" do
after(:all) do
pp = <<-EOS
service { '#{service_name}': ensure => stopped }
package { 'splunk': ensure => purged }
file { '/opt/splunk': ensure => absent, force => true, require => Package['splunk'] }
file { '/etc/init.d/splunk': ensure => absent, require => Package['splunk'] }
file { '/etc/systemd/system/Splunkd.service': ensure => absent, require => Package['splunk'] }
EOS
apply_manifest(pp, catch_failures: true)
end

it 'works idempotently with no errors' do
pp = <<-EOS
class { 'splunk::params': version => '#{version}', build => '#{build}' }
class { 'splunk::enterprise': }
# See https://community.splunk.com/t5/Installation/Why-am-I-getting-an-error-to-start-a-fresh-Splunk-instance-in-my/m-p/336938
file_line { 'file_locking':
path => '/opt/splunk/etc/splunk-launch.conf',
line => 'OPTIMISTIC_ABOUT_FILE_LOCKING=1',
before => Exec['enable_splunk'],
require => Package['splunk'],
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# give splunk some time to start
sleep(10)
end

describe package('splunk') do
it { is_expected.to be_installed }
end

describe service(service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
end
end

context 'default parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
Expand All @@ -20,7 +65,8 @@ class { 'splunk::enterprise': }
file_line { 'file_locking':
path => '/opt/splunk/etc/splunk-launch.conf',
line => 'OPTIMISTIC_ABOUT_FILE_LOCKING=1',
require => Class['splunk::enterprise'],
before => Exec['enable_splunk'],
require => Package['splunk'],
}
EOS

Expand All @@ -46,8 +92,8 @@ class { 'splunk::enterprise': }
describe file(conf_file_path) do
it { is_expected.to be_file }
it { is_expected.to be_mode 600 }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_owned_by 'splunk' }
it { is_expected.to be_grouped_into 'splunk' }
end
end

Expand Down
51 changes: 44 additions & 7 deletions spec/acceptance/splunk_forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,50 @@
require 'spec_helper_acceptance'

describe 'splunk::forwarder class' do
init = shell('/bin/readlink /sbin/init', acceptable_exit_codes: [0, 1]).stdout
service_name = if init.include? 'systemd'
'SplunkForwarder'
else
'splunk'
end

OLD_SPLUNK_VERSIONS.each do |version, build|
context "Splunk forwarder version #{version}" do
after(:all) do
pp = <<-EOS
service { '#{service_name}': ensure => stopped }
package { 'splunkforwarder': ensure => purged }
file { '/opt/splunkforwarder': ensure => absent, force => true, require => Package['splunkforwarder'] }
file { '/opt/splunk': ensure => absent, force => true, require => Package['splunkforwarder'] }
file { '/etc/systemd/system/SplunkForwarder.service': ensure => absent, require => Package['splunkforwarder'] }
EOS
apply_manifest(pp, catch_failures: true)
end

it 'works idempotently with no errors' do
pp = <<-EOS
class { 'splunk::params': version => '#{version}', build => '#{build}' }
class { 'splunk::forwarder':
splunkd_port => 8090,
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package('splunkforwarder') do
it { is_expected.to be_installed }
end

describe service(service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
end
end

context 'default parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
Expand Down Expand Up @@ -32,13 +76,6 @@ class { 'splunk::forwarder':
it { is_expected.to be_installed }
end

init = shell('/bin/readlink /sbin/init', acceptable_exit_codes: [0, 1]).stdout
service_name = if init.include? 'systemd'
'SplunkForwarder'
else
'splunk'
end

describe service(service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
Expand Down
Loading

0 comments on commit 6fd47b8

Please sign in to comment.