Skip to content

Commit

Permalink
Merge pull request #49 from crayfishx/refactor
Browse files Browse the repository at this point in the history
[REVIEW] [MODULES-3520] refactored types and providers and added purging
  • Loading branch information
bastelfreak authored Sep 21, 2016
2 parents f585680 + 0fe96f7 commit 2a76251
Show file tree
Hide file tree
Showing 39 changed files with 384 additions and 584 deletions.
48 changes: 47 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This virtual resource will get collected by the `::splunk::forwarder` class if i
### Types


* `splunk_config`: This is a meta resource used to configur defaults for all the splunkforwarder and splunk types.
* `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.

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

All of the above types use `puppetlabs/ini_file` as a parent and are declared in an identical way, and accept the following parameters:

* `section`: The name of the section in the configuration file
* `setting`: The setting to be managed
* `value`: The value of the setting

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:

```puppet
splunkforwarder_output { 'useless title':
section => 'default',
setting => 'defaultGroup',
value => 'splunk_9777',
}
splunkforwarder_output { 'default':
setting => 'defaultGroup',
value => 'splunk_9777',
}
splunkforwarder_output { 'default/defaultGroup':
value => 'splunk_9777',
}
```

The above resource declarations will all configure the following entry in `outputs.conf`

```
[default]
defaultGroup=splunk_9997
```

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.


## Parameters

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

####`purge_props`
*Optional* If set to true, props.conf will be purged of configuration that is
no longer managed by the splunk_props type. Default to false.

####`purge_transforms`
*Optional* If set to true, transforms.conf will be purged of configuration that is
no longer managed by the splunk_transforms type. Default to false.

####`purge_web`
*Optional* If set to true, web.conf will be purged of configuration that is
no longer managed by the splunk_web type. Default to false.

####`pkg_provider`
*Optional* This will override the default package provider for the package
resource. Default to undef.
Expand Down
19 changes: 19 additions & 0 deletions lib/puppet/provider/ini_setting/splunk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Puppet::Type.type(:ini_setting).provide(
:splunk,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do

confine :true => false # Never automatically select this provider

@file_path = nil

def self.file_path
raise Puppet::Error, "file_path must be set with splunk_config type before provider can be used" if @file_path.nil?
raise Puppet::Error, "Child provider class does not support a file_name method" unless self.respond_to?(:file_name)
File.join(@file_path, file_name)
end

def self.set_file_path(path)
@file_path=path
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_authentication/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_authentication).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\authentication.conf'
else
'/opt/splunk/etc/system/local/authentication.conf'
end
def self.file_name
'system/local/authentication.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_authorize/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_authorize).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\authorize.conf'
else
'/opt/splunk/etc/system/local/authorize.conf'
end
def self.file_name
'system/local/authorize.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_distsearch/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_distsearch).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\distsearch.conf'
else
'/opt/splunk/etc/system/local/distsearch.conf'
end
def self.file_name
'system/local/distsearch.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_indexes/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_indexes).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\indexes.conf'
else
'/opt/splunk/etc/system/local/indexes.conf'
end
def self.file_name
'system/local/indexes.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_input/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_input).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\inputs.conf'
else
'/opt/splunk/etc/system/local/inputs.conf'
end
def self.file_name
'system/local/inputs.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_limits/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_limits).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\limits.conf'
else
'/opt/splunk/etc/system/local/limits.conf'
end
def self.file_name
'system/local/limits.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_output/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_output).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\outputs.conf'
else
'/opt/splunk/etc/system/local/outputs.conf'
end
def self.file_name
'system/local/outputs.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_props/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_props).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\props.conf'
else
'/opt/splunk/etc/system/local/props.conf'
end
def self.file_name
'system/local/props.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_server/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_server).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\server.conf'
else
'/opt/splunk/etc/system/local/server.conf'
end
def self.file_name
'system/local/server.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_transforms/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_transforms).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\transforms.conf'
else
'/opt/splunk/etc/system/local/transforms.conf'
end
def self.file_name
'system/local/transforms.conf'
end
end
13 changes: 3 additions & 10 deletions lib/puppet/provider/splunk_web/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Puppet::Type.type(:splunk_web).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do
# hard code the file path (this allows purging)
def self.file_path
case Facter.value(:osfamily)
when 'windows'
'C:\Program Files\Splunk\etc\system\local\web.conf'
else
'/opt/splunk/etc/system/local/web.conf'
end
def self.file_name
'system/local/web.conf'
end
end
15 changes: 3 additions & 12 deletions lib/puppet/provider/splunkforwarder_input/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
Puppet::Type.type(:splunkforwarder_input).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do

def self.prefetch(resources)
catalog = resources[resources.keys.first].catalog
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
@file_path = File.join(confdir, 'inputs.conf')
end

def self.file_path
@file_path
def self.file_name
'system/local/inputs.conf'
end
end
16 changes: 4 additions & 12 deletions lib/puppet/provider/splunkforwarder_output/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
Puppet::Type.type(:splunkforwarder_output).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do

def self.prefetch(resources)
catalog = resources[resources.keys.first].catalog
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
@file_path = File.join(confdir, 'outputs.conf')
end

def self.file_path
@file_path
def self.file_name
"system/local/outputs.conf"
end
end

15 changes: 3 additions & 12 deletions lib/puppet/provider/splunkforwarder_props/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
Puppet::Type.type(:splunkforwarder_props).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do

def self.prefetch(resources)
catalog = resources[resources.keys.first].catalog
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
@file_path = File.join(confdir, 'props.conf')
end

def self.file_path
@file_path
def self.file_name
'system/local/props.conf'
end
end
15 changes: 3 additions & 12 deletions lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
Puppet::Type.type(:splunkforwarder_transforms).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:ini_setting).provider(:splunk)
) do

def self.prefetch(resources)
catalog = resources[resources.keys.first].catalog
splunk_config = catalog.resources.find{|s| s.type == :splunk_config}
confdir = splunk_config['forwarder_confdir'] || raise(Puppet::Error, 'Unknown splunk forwarder confdir')
@file_path = File.join(confdir, 'transforms.conf')
end

def self.file_path
@file_path
def self.file_name
'system/local/transforms.conf'
end
end
Loading

0 comments on commit 2a76251

Please sign in to comment.