Skip to content

Commit daa0525

Browse files
committed
Merge pull request #14 from nanliu/windows
Expose splunk forwarder windows install options
2 parents 392953c + 53bda85 commit daa0525

File tree

8 files changed

+101
-45
lines changed

8 files changed

+101
-45
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*.sw?
2+
.bundle
3+
.pkg
4+
.ruby-version
5+
.vagrant
6+
Gemfile.lock
7+
modules/
8+
spec/fixtures

lib/puppet/provider/splunkforwarder_input/ini_setting.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# set ini_setting as the parent provider
44
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
55
) do
6-
# hard code the file path (this allows purging)
6+
7+
def self.prefetch(resources)
8+
catalog = resources[resources.keys.first].catalog
9+
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
10+
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
11+
@file_path = File.join(confdir, 'inputs.conf')
12+
end
13+
714
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\SplunkUniversalForwarder\etc\system\local\inputs.conf'
11-
else
12-
'/opt/splunkforwarder/etc/system/local/inputs.conf'
13-
end
15+
@file_path
1416
end
1517
end

lib/puppet/provider/splunkforwarder_output/ini_setting.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# set ini_setting as the parent provider
44
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
55
) do
6-
# hard code the file path (this allows purging)
6+
7+
def self.prefetch(resources)
8+
catalog = resources[resources.keys.first].catalog
9+
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
10+
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
11+
@file_path = File.join(confdir, 'outputs.conf')
12+
end
13+
714
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\SplunkUniversalForwarder\etc\system\local\outputs.conf'
11-
else
12-
'/opt/splunkforwarder/etc/system/local/outputs.conf'
13-
end
15+
@file_path
1416
end
1517
end

lib/puppet/provider/splunkforwarder_props/ini_setting.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# set ini_setting as the parent provider
44
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
55
) do
6-
# hard code the file path (this allows purging)
6+
7+
def self.prefetch(resources)
8+
catalog = resources[resources.keys.first].catalog
9+
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
10+
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
11+
@file_path = File.join(confdir, 'props.conf')
12+
end
13+
714
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\SplunkUniversalForwarder\etc\system\local\props.conf'
11-
else
12-
'/opt/splunkforwarder/etc/system/local/props.conf'
13-
end
15+
@file_path
1416
end
1517
end

lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# set ini_setting as the parent provider
44
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
55
) do
6-
# hard code the file path (this allows purging)
6+
7+
def self.prefetch(resources)
8+
catalog = resources[resources.keys.first].catalog
9+
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
10+
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
11+
@file_path = File.join(confdir, 'transforms.conf')
12+
end
13+
714
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\SplunkUniversalForwarder\etc\system\local\transforms.conf'
11-
else
12-
'/opt/splunkforwarder/etc/system/local/transforms.conf'
13-
end
15+
@file_path
1416
end
1517
end

lib/puppet/type/splunk_config.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Puppet::Type.newtype(:splunk_config) do
2+
newparam(:name, :namevar => true) do
3+
desc 'splunk config'
4+
end
5+
6+
newparam(:forwarder_installdir) do
7+
end
8+
9+
newparam(:forwarder_confdir) do
10+
end
11+
12+
newparam(:server_installdir) do
13+
end
14+
15+
newparam(:server_confdir) do
16+
end
17+
end

manifests/forwarder.pp

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# [*splunkd_port*]
2424
# The splunkd port. Used as a default for both splunk and splunk::forwarder.
2525
#
26+
# [*install_options*]
27+
# The splunkd forwarder installation options. Only applicable for Windows.
28+
#
2629
# [*splunkd_listen*]
2730
# The address on which splunkd should listen. Defaults to localhost only.
2831
#
@@ -47,6 +50,7 @@
4750
$package_ensure = $splunk::params::forwarder_pkg_ensure,
4851
$logging_port = $splunk::params::logging_port,
4952
$splunkd_port = $splunk::params::splunkd_port,
53+
$install_options = $splunk::params::forwarder_install_options,
5054
$splunkd_listen = '127.0.0.1',
5155
$purge_inputs = false,
5256
$purge_outputs = false,
@@ -80,7 +84,7 @@
8084
provider => $pkg_provider,
8185
source => $pkg_source,
8286
before => Service[$virtual_service],
83-
install_options => $splunk::params::forwarder_install_options,
87+
install_options => $install_options,
8488
tag => 'splunk_forwarder',
8589
}
8690
# Declare inputs and outputs specific to the forwarder profile

manifests/params.pp

+35-16
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@
6767
# Requires: nothing
6868
#
6969
class splunk::params (
70-
$version = '5.0.5',
71-
$build = '179365',
72-
$src_root = 'puppet:///modules/splunk',
73-
$splunkd_port = '8089',
74-
$logging_port = '9997',
75-
$server = 'splunk'
70+
$version = '5.0.5',
71+
$build = '179365',
72+
$src_root = 'puppet:///modules/splunk',
73+
$splunkd_port = '8089',
74+
$logging_port = '9997',
75+
$server = 'splunk'
76+
$forwarder_installdir = undef,
77+
$server_installdir = undef,
7678
) {
7779

7880
# Based on the small number of inputs above, we can construct sane defaults
@@ -85,40 +87,48 @@
8587
$password_content = ':admin:$6$pIE/xAyP9mvBaewv$4GYFxC0SqonT6/x8qGcZXVCRLUVKODj9drDjdu/JJQ/Iw0Gg.aTkFzCjNAbaK4zcCHbphFz1g1HK18Z2bI92M0::Administrator:admin:changeme@example.com::'
8688

8789

90+
if $::osfamily == 'Windows' {
91+
$forwarder_dir = pick($forwarder_installdir, 'C:/Program Files/SplunkUniversalForwarder')
92+
$server_dir = pick($server_installdir, 'C:/Program Files/Splunk')
93+
} else {
94+
$forwarder_dir = pick($forwarder_installdir, '/opt/splunkforwarder')
95+
$server_dir = pick($server_installdir, '/opt/splunk')
96+
}
97+
8898
# Settings common to a kernel
8999
case $::kernel {
90100
'Linux': {
91101
$path_delimiter = '/'
92102
$forwarder_src_subdir = 'universalforwarder/linux'
93103
$forwarder_service = [ 'splunk' ]
94-
$password_config_file = '/opt/splunkforwarder/etc/passwd'
95-
$forwarder_confdir = '/opt/splunkforwarder/etc/system/local'
96-
$secret_file = '/opt/splunkforwarder/etc/splunk.secret'
104+
$password_config_file = "${forwarder_dir}/etc/passwd"
105+
$secret_file = "${forwarder_dir}/etc/splunk.secret"
106+
$forwarder_confdir = "${forwarder_dir}/etc/system/local"
97107
$server_src_subdir = 'splunk/linux'
98108
$server_service = [ 'splunk', 'splunkd', 'splunkweb' ]
99-
$server_confdir = '/opt/splunk/etc/system/local'
109+
$server_confdir = "${server_dir}/etc/system/local"
100110
}
101111
'SunOS': {
102112
$path_delimiter = '/'
103113
$forwarder_src_subdir = 'universalforwarder/solaris'
104114
$forwarder_service = [ 'splunk' ]
105-
$password_config_file = '/opt/splunkforwarder/etc/passwd'
106-
$forwarder_confdir = '/opt/splunkforwarder/etc/system/local'
107-
$secret_file = '/opt/splunkforwarder/etc/splunk.secret'
115+
$password_config_file = "${forwarder_dir}/etc/passwd"
116+
$secret_file = "${forwarder_dir}/etc/splunk.secret"
117+
$forwarder_confdir = "${forwarder_dir}/etc/system/local"
108118
$server_src_subdir = 'splunk/solaris'
109119
$server_service = [ 'splunk', 'splunkd', 'splunkweb' ]
110-
$server_confdir = '/opt/splunk/etc/system/local'
120+
$server_confdir = "${server_dir}/etc/system/local"
111121
}
112122
'Windows': {
113123
$path_delimiter = '\\'
114124
$forwarder_src_subdir = 'universalforwarder/windows'
115125
$password_config_file = 'C:/Program Files/SplunkUniversalForwarder/etc/passwd'
116126
$secret_file = 'C:/Program Files/SplunkUniversalForwarder/etc/splunk.secret'
117127
$forwarder_service = [ 'SplunkForwarder' ] # UNKNOWN
118-
$forwarder_confdir = 'C:/Program Files/SplunkUniversalForwarder/etc/system/local'
128+
$forwarder_confdir = "${forwarder_dir}/etc/system/local"
119129
$server_src_subdir = 'splunk/windows'
120130
$server_service = [ 'Splunkd', 'Splunkweb' ] # UNKNOWN
121-
$server_confdir = 'C:/Program Files/Splunk/etc/system/local' # UNKNOWN
131+
$server_confdir = "${server_dir}/etc/system/local"
122132
$forwarder_install_options = [
123133
'AGREETOLICENSE=Yes',
124134
'LAUNCHSPLUNK=0',
@@ -129,6 +139,7 @@
129139
'WINEVENTLOG_FWD_ENABLE=1',
130140
'WINEVENTLOG_SET_ENABLE=1',
131141
'ENABLEADMON=1',
142+
"INSTALLDIR=\"${forwarder_dir}\"",
132143
]
133144
$server_install_options = [
134145
'LAUNCHSPLUNK=1',
@@ -227,4 +238,12 @@
227238
$create_password = true
228239

229240
$forwarder_pkg_ensure = 'installed'
241+
242+
# A meta resource so providers know where splunk is installed:
243+
splunk_config { 'splunk':
244+
forwarder_installdir => $forwarder_dir,
245+
forwarder_confdir => $forwarder_confdir,
246+
server_installdir => $server_dir,
247+
server_confdir => $server_confdir,
248+
}
230249
}

0 commit comments

Comments
 (0)