diff --git a/README.markdown b/README.markdown index a37f2aba..e9960512 100644 --- a/README.markdown +++ b/README.markdown @@ -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] @@ -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 @@ -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. diff --git a/lib/puppet/provider/ini_setting/splunk.rb b/lib/puppet/provider/ini_setting/splunk.rb new file mode 100644 index 00000000..72f9d3d9 --- /dev/null +++ b/lib/puppet/provider/ini_setting/splunk.rb @@ -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 diff --git a/lib/puppet/provider/splunk_authentication/ini_setting.rb b/lib/puppet/provider/splunk_authentication/ini_setting.rb index 157c6fb3..c87f3ff3 100644 --- a/lib/puppet/provider/splunk_authentication/ini_setting.rb +++ b/lib/puppet/provider/splunk_authentication/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_authorize/ini_setting.rb b/lib/puppet/provider/splunk_authorize/ini_setting.rb index 7b07e2fb..66a5a486 100644 --- a/lib/puppet/provider/splunk_authorize/ini_setting.rb +++ b/lib/puppet/provider/splunk_authorize/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_distsearch/ini_setting.rb b/lib/puppet/provider/splunk_distsearch/ini_setting.rb index f313b67c..7ed0f875 100644 --- a/lib/puppet/provider/splunk_distsearch/ini_setting.rb +++ b/lib/puppet/provider/splunk_distsearch/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_indexes/ini_setting.rb b/lib/puppet/provider/splunk_indexes/ini_setting.rb index e11dad6d..0a3dde7c 100644 --- a/lib/puppet/provider/splunk_indexes/ini_setting.rb +++ b/lib/puppet/provider/splunk_indexes/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_input/ini_setting.rb b/lib/puppet/provider/splunk_input/ini_setting.rb index 4845b59d..7c773413 100644 --- a/lib/puppet/provider/splunk_input/ini_setting.rb +++ b/lib/puppet/provider/splunk_input/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_limits/ini_setting.rb b/lib/puppet/provider/splunk_limits/ini_setting.rb index 2995b161..5efe3790 100644 --- a/lib/puppet/provider/splunk_limits/ini_setting.rb +++ b/lib/puppet/provider/splunk_limits/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_output/ini_setting.rb b/lib/puppet/provider/splunk_output/ini_setting.rb index 0384def4..30509261 100644 --- a/lib/puppet/provider/splunk_output/ini_setting.rb +++ b/lib/puppet/provider/splunk_output/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_props/ini_setting.rb b/lib/puppet/provider/splunk_props/ini_setting.rb index f6984c5d..0cad9f57 100644 --- a/lib/puppet/provider/splunk_props/ini_setting.rb +++ b/lib/puppet/provider/splunk_props/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_server/ini_setting.rb b/lib/puppet/provider/splunk_server/ini_setting.rb index 73f8e232..93c1a6cf 100644 --- a/lib/puppet/provider/splunk_server/ini_setting.rb +++ b/lib/puppet/provider/splunk_server/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_transforms/ini_setting.rb b/lib/puppet/provider/splunk_transforms/ini_setting.rb index 3c9bd779..1665d8a8 100644 --- a/lib/puppet/provider/splunk_transforms/ini_setting.rb +++ b/lib/puppet/provider/splunk_transforms/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunk_web/ini_setting.rb b/lib/puppet/provider/splunk_web/ini_setting.rb index 8a7051bd..86b1fbf7 100644 --- a/lib/puppet/provider/splunk_web/ini_setting.rb +++ b/lib/puppet/provider/splunk_web/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunkforwarder_input/ini_setting.rb b/lib/puppet/provider/splunkforwarder_input/ini_setting.rb index bad069c2..93299e85 100644 --- a/lib/puppet/provider/splunkforwarder_input/ini_setting.rb +++ b/lib/puppet/provider/splunkforwarder_input/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunkforwarder_output/ini_setting.rb b/lib/puppet/provider/splunkforwarder_output/ini_setting.rb index 9fc06b2a..80c88369 100644 --- a/lib/puppet/provider/splunkforwarder_output/ini_setting.rb +++ b/lib/puppet/provider/splunkforwarder_output/ini_setting.rb @@ -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 + diff --git a/lib/puppet/provider/splunkforwarder_props/ini_setting.rb b/lib/puppet/provider/splunkforwarder_props/ini_setting.rb index 8317de66..e1d3d19d 100644 --- a/lib/puppet/provider/splunkforwarder_props/ini_setting.rb +++ b/lib/puppet/provider/splunkforwarder_props/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb b/lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb index a4816c08..45841ec2 100644 --- a/lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb +++ b/lib/puppet/provider/splunkforwarder_transforms/ini_setting.rb @@ -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 diff --git a/lib/puppet/provider/splunkforwarder_web/ini_setting.rb b/lib/puppet/provider/splunkforwarder_web/ini_setting.rb index 8286e024..4c239007 100644 --- a/lib/puppet/provider/splunkforwarder_web/ini_setting.rb +++ b/lib/puppet/provider/splunkforwarder_web/ini_setting.rb @@ -1,17 +1,8 @@ Puppet::Type.type(:splunkforwarder_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 - - 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, 'web.conf') - end - - def self.file_path - @file_path + def self.file_name + 'system/local/web.conf' end end diff --git a/lib/puppet/type/splunk_authentication.rb b/lib/puppet/type/splunk_authentication.rb index 5ea46ab7..0dc13ac8 100644 --- a/lib/puppet/type/splunk_authentication.rb +++ b/lib/puppet/type/splunk_authentication.rb @@ -1,24 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_authentication) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from authentication.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk authentication settings in authentication.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end + diff --git a/lib/puppet/type/splunk_authorize.rb b/lib/puppet/type/splunk_authorize.rb index b9979ee2..85528f8e 100644 --- a/lib/puppet/type/splunk_authorize.rb +++ b/lib/puppet/type/splunk_authorize.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_authorize) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from authorize.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk authorize settings in authorize.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_config.rb b/lib/puppet/type/splunk_config.rb index e7e9ae1f..654cb4c5 100644 --- a/lib/puppet/type/splunk_config.rb +++ b/lib/puppet/type/splunk_config.rb @@ -1,3 +1,10 @@ +# Require all of our types so the class names are resolvable for purging +Dir[File.dirname(__FILE__) + '/*.rb'].each do |file| + unless file == __FILE__ + require file + end +end + Puppet::Type.newtype(:splunk_config) do newparam(:name, :namevar => true) do desc 'splunk config' @@ -14,4 +21,120 @@ newparam(:server_confdir) do end + + ## Generate purge parameters for the splunk_config type + [ + :purge_inputs, + :purge_outputs, + :purge_authentication, + :purge_authorize, + :purge_distsearch, + :purge_indexes, + :purge_limits, + :purge_props, + :purge_server, + :purge_transforms, + :purge_web, + :purge_forwarder_inputs, + :purge_forwarder_outputs, + :purge_forwarder_props, + :purge_forwarder_transforms, + :purge_forwarder_web + ].each do |p| + newparam(p) do + newvalues(:true,:false) + defaultto :false + end + end + + # The generate method sets the correct paths for the providers + # and spawns any resources that need purging. + # + def generate + set_provider_paths + + resources = Array.new + + { + Puppet::Type::Splunk_output => self[:purge_outputs], + Puppet::Type::Splunk_input => self[:purge_inputs], + Puppet::Type::Splunk_authentication => self[:purge_authentication], + Puppet::Type::Splunk_authorize => self[:purge_authorize], + Puppet::Type::Splunk_distsearch => self[:purge_distsearch], + Puppet::Type::Splunk_indexes => self[:purge_indexes], + Puppet::Type::Splunk_props => self[:purge_props], + Puppet::Type::Splunk_server => self[:purge_server], + Puppet::Type::Splunk_transforms => self[:purge_transforms], + Puppet::Type::Splunk_web => self[:purge_web], + Puppet::Type::Splunkforwarder_input => self[:purge_forwarder_inputs], + Puppet::Type::Splunkforwarder_output => self[:purge_forwarder_outputs], + Puppet::Type::Splunkforwarder_props => self[:purge_forwarder_props], + Puppet::Type::Splunkforwarder_transforms => self[:purge_forwarder_transforms], + Puppet::Type::Splunkforwarder_web => self[:purge_forwarder_web] + }.each do |k,purge| + resources.concat(purge_splunk_resources(k)) if purge == :true + end + + return resources + end + + + def set_provider_paths + [ + :splunk_authentication, + :splunk_authorize, + :splunk_distsearch, + :splunk_indexes, + :splunk_limits, + :splunk_output, + :splunk_props, + :splunk_server, + :splunk_transforms, + :splunk_web + ].each do |res_type| + Puppet::Type.type(res_type).provider(:ini_setting).set_file_path(self[:server_confdir]) + end + [ + :splunkforwarder_input, + :splunkforwarder_output, + :splunkforwarder_props, + :splunkforwarder_transforms, + :splunkforwarder_web + ].each do |res_type| + Puppet::Type.type(res_type).provider(:ini_setting).set_file_path(self[:forwarder_confdir]) + end + end + + def purge_splunk_resources(klass) + type_name = klass.name + purge_resources = Array.new + puppet_resources = Array.new + + # Search the catalog for resource types matching the provided class + # type and build an array of puppet resources matching the namevar + # as section/setting + # + catalog_resources = catalog.resources.select { |r| r.is_a?(klass) } + catalog_resources.each do |res| + puppet_resources << res[:section] + "/" + res[:setting] + end + + + # Search the configured instances of the class type and purge them if + # the instance name (setion/setting) isn't found in puppet_resources + # + Puppet::Type.type(type_name).instances.each do |instance| + unless puppet_resources.include?(instance.name) + purge_resources << Puppet::Type.type(type_name).new( + :name => instance.name, + :section => instance[:section], + :setting => instance[:setting], + :ensure => :absent + ) + end + end + + return purge_resources + end + end diff --git a/lib/puppet/type/splunk_distsearch.rb b/lib/puppet/type/splunk_distsearch.rb index b1c4280c..080a435b 100644 --- a/lib/puppet/type/splunk_distsearch.rb +++ b/lib/puppet/type/splunk_distsearch.rb @@ -1,24 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_distsearch) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from distsearch.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc= "Manage distsearch entries in distsearch.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end + diff --git a/lib/puppet/type/splunk_indexes.rb b/lib/puppet/type/splunk_indexes.rb index 94d89ccf..976fb9c9 100644 --- a/lib/puppet/type/splunk_indexes.rb +++ b/lib/puppet/type/splunk_indexes.rb @@ -1,24 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_indexes) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from indexes.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk index settings in indexes.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end + diff --git a/lib/puppet/type/splunk_input.rb b/lib/puppet/type/splunk_input.rb index 9aaf8ff0..3e275120 100644 --- a/lib/puppet/type/splunk_input.rb +++ b/lib/puppet/type/splunk_input.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_input) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from inputs.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk input settings in inputs.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_limits.rb b/lib/puppet/type/splunk_limits.rb index bde20c23..748bfeda 100644 --- a/lib/puppet/type/splunk_limits.rb +++ b/lib/puppet/type/splunk_limits.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_limits) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from limits.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk limits settings in limits.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_output.rb b/lib/puppet/type/splunk_output.rb index 62bf4ef0..13b84871 100644 --- a/lib/puppet/type/splunk_output.rb +++ b/lib/puppet/type/splunk_output.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_output) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from outputs.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk output settings in outputs.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_props.rb b/lib/puppet/type/splunk_props.rb index 024367f3..94275c44 100644 --- a/lib/puppet/type/splunk_props.rb +++ b/lib/puppet/type/splunk_props.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_props) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from props.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk prop settings in props.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_server.rb b/lib/puppet/type/splunk_server.rb index 08025d0d..9df38bf7 100644 --- a/lib/puppet/type/splunk_server.rb +++ b/lib/puppet/type/splunk_server.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_server) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from server.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk server settings in server.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_transforms.rb b/lib/puppet/type/splunk_transforms.rb index 7eb4d86b..31562338 100644 --- a/lib/puppet/type/splunk_transforms.rb +++ b/lib/puppet/type/splunk_transforms.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_transforms) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from transforms.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk transforms settings in transforms.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunk_web.rb b/lib/puppet/type/splunk_web.rb index ec0a2da5..9c7ae84b 100644 --- a/lib/puppet/type/splunk_web.rb +++ b/lib/puppet/type/splunk_web.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunk_web) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from web.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunk web settings in web.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunkforwarder_input.rb b/lib/puppet/type/splunkforwarder_input.rb index 42d6747e..7efe5150 100644 --- a/lib/puppet/type/splunkforwarder_input.rb +++ b/lib/puppet/type/splunkforwarder_input.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunkforwarder_input) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from inputs.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunkforwarder input settings in inputs.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunkforwarder_output.rb b/lib/puppet/type/splunkforwarder_output.rb index b35ecdc6..4fff0306 100644 --- a/lib/puppet/type/splunkforwarder_output.rb +++ b/lib/puppet/type/splunkforwarder_output.rb @@ -1,24 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + + Puppet::Type.newtype(:splunkforwarder_output) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from outputs.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunkforwarder output settings in outputs.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunkforwarder_props.rb b/lib/puppet/type/splunkforwarder_props.rb index 85417b1f..20b485b6 100644 --- a/lib/puppet/type/splunkforwarder_props.rb +++ b/lib/puppet/type/splunkforwarder_props.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunkforwarder_props) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from props.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunkforwarder props settings in props.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunkforwarder_transforms.rb b/lib/puppet/type/splunkforwarder_transforms.rb index 8bbca49a..10d7a612 100644 --- a/lib/puppet/type/splunkforwarder_transforms.rb +++ b/lib/puppet/type/splunkforwarder_transforms.rb @@ -1,24 +1,6 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunkforwarder_transforms) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from transforms.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunkforwarder transforms settings in transforms.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end diff --git a/lib/puppet/type/splunkforwarder_web.rb b/lib/puppet/type/splunkforwarder_web.rb index 8dcca063..5215ee4b 100644 --- a/lib/puppet/type/splunkforwarder_web.rb +++ b/lib/puppet/type/splunkforwarder_web.rb @@ -1,24 +1,7 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/puppetlabs/splunk/type') + Puppet::Type.newtype(:splunkforwarder_web) do - ensurable - newparam(:name, :namevar => true) do - desc 'Setting name to manage from web.conf' - end - newproperty(:value) do - desc 'The value of the setting to be defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:setting) do - desc 'The setting being defined.' - munge do |v| - v.to_s.strip - end - end - newproperty(:section) do - desc 'The section the setting is defined under.' - munge do |v| - v.to_s.strip - end - end + @doc = "Manage splunkforwarder web settings in web.conf" + PuppetX::Puppetlabs::Splunk::Type.clone_type(self) end + diff --git a/lib/puppet_x/puppetlabs/splunk/type.rb b/lib/puppet_x/puppetlabs/splunk/type.rb new file mode 100644 index 00000000..c8fc8993 --- /dev/null +++ b/lib/puppet_x/puppetlabs/splunk/type.rb @@ -0,0 +1,46 @@ +module PuppetX + module Puppetlabs + module Splunk + module Type + + def self.clone_type(type) + type.ensurable + + type.define_singleton_method(:title_patterns) do + [ + [ /^([^\/]*)$/, [ [ :section ] ] ], + [ /^(.*\/\/.*)$/, [ [ :section ] ] ], + [ /^(.*)\/(.*)$/, + [ + [:section, lambda{|x| x} ], + [:setting, lambda{|x| x} ] + ] + ] + ] + end + type.newproperty(:value) do + desc 'The value of the setting to be defined.' + munge do |v| + v.to_s.strip + end + end + type.newparam(:setting) do + desc 'The setting being defined.' + isnamevar + munge do |v| + v.to_s.strip + end + end + type.newparam(:section) do + desc 'The section the setting is defined under.' + isnamevar + munge do |v| + v.to_s.strip + end + end + type.newparam(:name) + end + end + end + end +end diff --git a/manifests/forwarder.pp b/manifests/forwarder.pp index fe8bcf0c..9826bd04 100644 --- a/manifests/forwarder.pp +++ b/manifests/forwarder.pp @@ -55,6 +55,9 @@ $splunkd_listen = '127.0.0.1', $purge_inputs = false, $purge_outputs = false, + $purge_props = false, + $purge_transforms = false, + $purge_web = false, $pkg_provider = $splunk::params::pkg_provider, $forwarder_confdir = $splunk::params::forwarder_confdir, $forwarder_output = $splunk::params::forwarder_output, @@ -106,14 +109,16 @@ } # If the purge parameters have been set, remove all unmanaged entries from - # the inputs.conf and outputs.conf files, respectively. - if $purge_inputs { - resources { 'splunkforwarder_input': purge => true; } + # the respective config files. + + Splunk_config['splunk'] { + purge_forwarder_outputs => $purge_outputs, + purge_forwarder_inputs => $purge_forwarder_inputs, + purge_forwarder_props => $purge_forwarder_props, + purge_forwarder_transforms => $purge_forwarder_transforms, + purge_forwarder_web => $purge_forwarder_web } - if $purge_outputs { - resources { 'splunkforwarder_output': purge => true; } - } - + # This is a module that supports multiple platforms. For some platforms # there is non-generic configuration that needs to be declared in addition # to the agnostic resources declared here. diff --git a/manifests/init.pp b/manifests/init.pp index 9136b96d..e0fec418 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -119,56 +119,21 @@ tag => 'splunk_server' } - # If the purge parameters have been set, remove all unmanaged entries from - # the inputs.conf and outputs.conf files, respectively. - if $purge_authentication { - resources { 'splunk_authentication': purge => true; } - } - - if $purge_authorize { - resources { 'splunk_authorize': purge => true; } - } - - if $purge_distsearch { - resources { 'splunk_distsearch': purge => true; } - } - - if $purge_indexes { - resources { 'splunk_indexes': purge => true; } - } - - if $purge_inputs { - resources { 'splunk_input': purge => true; - 'splunkforwarder_input': purge => true; } - } - - if $purge_limits { - resources { 'splunk_limits': purge => true; } - } - if $purge_outputs { - resources { 'splunk_output': purge => true; - 'splunkforwarder_output': purge => true; } + # Purge resources if option set + Splunk_config['splunk'] { + purge_authentication => $purge_authentication, + purge_authorize => $purge_authorize, + purge_distsearch => $purge_distsearch, + purge_indexes => $purge_indexes, + purge_inputs => $purge_inputs, + purge_limits => $purge_limits, + purge_outputs => $purge_outputs, + purge_props => $purge_props, + purge_server => $purge_server, + purge_transforms => $purge_transforms, + purge_web => $purge_web } - - if $purge_props { - resources { 'splunk_props': purge => true; } - } - - - if $purge_server { - resources { 'splunk_server': purge => true; } - } - - - if $purge_transforms { - resources { 'splunk_transforms': purge => true; } - } - - if $purge_web { - resources { 'splunk_web': purge => true; } - } - # This is a module that supports multiple platforms. For some platforms # there is non-generic configuration that needs to be declared in addition # to the agnostic resources declared here. diff --git a/manifests/params.pp b/manifests/params.pp index 7f2a3899..5650b735 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -103,10 +103,10 @@ $forwarder_service = [ 'splunk' ] $password_config_file = "${forwarder_dir}/etc/passwd" $secret_file = "${forwarder_dir}/etc/splunk.secret" - $forwarder_confdir = "${forwarder_dir}/etc/system/local" + $forwarder_confdir = "${forwarder_dir}/etc" $server_src_subdir = 'splunk/linux' $server_service = [ 'splunk', 'splunkd', 'splunkweb' ] - $server_confdir = "${server_dir}/etc/system/local" + $server_confdir = "${server_dir}/etc" } 'SunOS': { $path_delimiter = '/' @@ -114,10 +114,10 @@ $forwarder_service = [ 'splunk' ] $password_config_file = "${forwarder_dir}/etc/passwd" $secret_file = "${forwarder_dir}/etc/splunk.secret" - $forwarder_confdir = "${forwarder_dir}/etc/system/local" + $forwarder_confdir = "${forwarder_dir}/etc" $server_src_subdir = 'splunk/solaris' $server_service = [ 'splunk', 'splunkd', 'splunkweb' ] - $server_confdir = "${server_dir}/etc/system/local" + $server_confdir = "${server_dir}/etc" } 'Windows': { $path_delimiter = '\\' @@ -125,10 +125,10 @@ $password_config_file = 'C:/Program Files/SplunkUniversalForwarder/etc/passwd' $secret_file = 'C:/Program Files/SplunkUniversalForwarder/etc/splunk.secret' $forwarder_service = [ 'SplunkForwarder' ] # UNKNOWN - $forwarder_confdir = "${forwarder_dir}/etc/system/local" + $forwarder_confdir = "${forwarder_dir}/etc" $server_src_subdir = 'splunk/windows' $server_service = [ 'Splunkd', 'SplunkWeb' ] # UNKNOWN - $server_confdir = "${server_dir}/etc/system/local" + $server_confdir = "${server_dir}/etc" $forwarder_install_options = [ 'AGREETOLICENSE=Yes', 'LAUNCHSPLUNK=0',