Skip to content

Commit 2a76251

Browse files
authored
Merge pull request #49 from crayfishx/refactor
[REVIEW] [MODULES-3520] refactored types and providers and added purging
2 parents f585680 + 0fe96f7 commit 2a76251

39 files changed

+384
-584
lines changed

README.markdown

+47-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ This virtual resource will get collected by the `::splunk::forwarder` class if i
130130
### Types
131131

132132

133-
* `splunk_config`: This is a meta resource used to configur defaults for all the splunkforwarder and splunk types.
133+
* `splunk_config`: This is a meta resource used to configur defaults for all the splunkforwarder and splunk types. This type should not be declared directly as it is declared in `splunk::params` and used internally by the types and providers.
134134

135135
* `splunk_authentication`: Used to manage ini settings in [authentication.conf][authentication.conf-docs]
136136
* `splunk_authorize`: Used to manage ini settings in [authorize.conf][authorize.conf-docs]
@@ -150,6 +150,40 @@ This virtual resource will get collected by the `::splunk::forwarder` class if i
150150
* `splunkforwarder_transforms`: Used to manage ini settings in [transforms.conf][transforms.conf-docs]
151151
* `splunkforwarder_web`: Used to manage ini settings in [web.conf][web.conf-docs]
152152

153+
All of the above types use `puppetlabs/ini_file` as a parent and are declared in an identical way, and accept the following parameters:
154+
155+
* `section`: The name of the section in the configuration file
156+
* `setting`: The setting to be managed
157+
* `value`: The value of the setting
158+
159+
Both section and setting are namevars for the types. Specifying a single string as the title without a forward slash implies that the title is the section to be managed (if the section attribute is not defined). You can also specify the resource title as `section/setting` and ommit both `section` and `setting` params for a more shortform way of declaring the resource. Eg:
160+
161+
```puppet
162+
splunkforwarder_output { 'useless title':
163+
section => 'default',
164+
setting => 'defaultGroup',
165+
value => 'splunk_9777',
166+
}
167+
168+
splunkforwarder_output { 'default':
169+
setting => 'defaultGroup',
170+
value => 'splunk_9777',
171+
}
172+
173+
splunkforwarder_output { 'default/defaultGroup':
174+
value => 'splunk_9777',
175+
}
176+
```
177+
178+
The above resource declarations will all configure the following entry in `outputs.conf`
179+
180+
```
181+
[default]
182+
defaultGroup=splunk_9997
183+
```
184+
185+
Note: if the section contains forward slashes you should not use it as the resource title and should explicitly declare it with the `section` attribute.
186+
153187

154188
## Parameters
155189

@@ -288,6 +322,18 @@ no longer managed by the splunkforwarder_input type. Default to false.
288322
*Optional* If set to true, outputs.conf will be purged of configuration that is
289323
no longer managed by the splunk_output type. Default to false.
290324

325+
####`purge_props`
326+
*Optional* If set to true, props.conf will be purged of configuration that is
327+
no longer managed by the splunk_props type. Default to false.
328+
329+
####`purge_transforms`
330+
*Optional* If set to true, transforms.conf will be purged of configuration that is
331+
no longer managed by the splunk_transforms type. Default to false.
332+
333+
####`purge_web`
334+
*Optional* If set to true, web.conf will be purged of configuration that is
335+
no longer managed by the splunk_web type. Default to false.
336+
291337
####`pkg_provider`
292338
*Optional* This will override the default package provider for the package
293339
resource. Default to undef.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Puppet::Type.type(:ini_setting).provide(
2+
:splunk,
3+
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
4+
) do
5+
6+
confine :true => false # Never automatically select this provider
7+
8+
@file_path = nil
9+
10+
def self.file_path
11+
raise Puppet::Error, "file_path must be set with splunk_config type before provider can be used" if @file_path.nil?
12+
raise Puppet::Error, "Child provider class does not support a file_name method" unless self.respond_to?(:file_name)
13+
File.join(@file_path, file_name)
14+
end
15+
16+
def self.set_file_path(path)
17+
@file_path=path
18+
end
19+
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_authentication).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\authentication.conf'
11-
else
12-
'/opt/splunk/etc/system/local/authentication.conf'
13-
end
5+
def self.file_name
6+
'system/local/authentication.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_authorize).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\authorize.conf'
11-
else
12-
'/opt/splunk/etc/system/local/authorize.conf'
13-
end
5+
def self.file_name
6+
'system/local/authorize.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_distsearch).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\distsearch.conf'
11-
else
12-
'/opt/splunk/etc/system/local/distsearch.conf'
13-
end
5+
def self.file_name
6+
'system/local/distsearch.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_indexes).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\indexes.conf'
11-
else
12-
'/opt/splunk/etc/system/local/indexes.conf'
13-
end
5+
def self.file_name
6+
'system/local/indexes.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_input).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\inputs.conf'
11-
else
12-
'/opt/splunk/etc/system/local/inputs.conf'
13-
end
5+
def self.file_name
6+
'system/local/inputs.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_limits).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\limits.conf'
11-
else
12-
'/opt/splunk/etc/system/local/limits.conf'
13-
end
5+
def self.file_name
6+
'system/local/limits.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_output).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\outputs.conf'
11-
else
12-
'/opt/splunk/etc/system/local/outputs.conf'
13-
end
5+
def self.file_name
6+
'system/local/outputs.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_props).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\props.conf'
11-
else
12-
'/opt/splunk/etc/system/local/props.conf'
13-
end
5+
def self.file_name
6+
'system/local/props.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_server).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\server.conf'
11-
else
12-
'/opt/splunk/etc/system/local/server.conf'
13-
end
5+
def self.file_name
6+
'system/local/server.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_transforms).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\transforms.conf'
11-
else
12-
'/opt/splunk/etc/system/local/transforms.conf'
13-
end
5+
def self.file_name
6+
'system/local/transforms.conf'
147
end
158
end
+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
Puppet::Type.type(:splunk_web).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
6-
# hard code the file path (this allows purging)
7-
def self.file_path
8-
case Facter.value(:osfamily)
9-
when 'windows'
10-
'C:\Program Files\Splunk\etc\system\local\web.conf'
11-
else
12-
'/opt/splunk/etc/system/local/web.conf'
13-
end
5+
def self.file_name
6+
'system/local/web.conf'
147
end
158
end
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
Puppet::Type.type(:splunkforwarder_input).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
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-
14-
def self.file_path
15-
@file_path
5+
def self.file_name
6+
'system/local/inputs.conf'
167
end
178
end
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
Puppet::Type.type(:splunkforwarder_output).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
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-
14-
def self.file_path
15-
@file_path
5+
def self.file_name
6+
"system/local/outputs.conf"
167
end
178
end
9+
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
Puppet::Type.type(:splunkforwarder_props).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
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-
14-
def self.file_path
15-
@file_path
5+
def self.file_name
6+
'system/local/props.conf'
167
end
178
end
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
Puppet::Type.type(:splunkforwarder_transforms).provide(
22
:ini_setting,
3-
# set ini_setting as the parent provider
4-
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3+
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
54
) do
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-
14-
def self.file_path
15-
@file_path
5+
def self.file_name
6+
'system/local/transforms.conf'
167
end
178
end

0 commit comments

Comments
 (0)