diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-01-02 07:27:20 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-01-02 07:27:20 +1100 |
commit | 61c408591fb1b35d0c5d55d6c47f1acfb50882f6 (patch) | |
tree | bd8720e8315ace700bcd7dd34a9a98ac8fcc17c3 /lib/puppet/util/nagios_maker.rb | |
parent | 2f9c13b44fa8602424d1ab4331b3b0c3806c30a8 (diff) | |
parent | 1dfcb63e0f9de1fd2f15c98ee9a6f242e3fb9325 (diff) | |
download | puppet-61c408591fb1b35d0c5d55d6c47f1acfb50882f6.tar.gz puppet-61c408591fb1b35d0c5d55d6c47f1acfb50882f6.tar.xz puppet-61c408591fb1b35d0c5d55d6c47f1acfb50882f6.zip |
Merge branch '0.24.x' of git://reductivelabs.com/puppet into 0.24.x
Diffstat (limited to 'lib/puppet/util/nagios_maker.rb')
-rw-r--r-- | lib/puppet/util/nagios_maker.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/puppet/util/nagios_maker.rb b/lib/puppet/util/nagios_maker.rb new file mode 100644 index 000000000..f1f85466f --- /dev/null +++ b/lib/puppet/util/nagios_maker.rb @@ -0,0 +1,56 @@ +require 'puppet/external/nagios' +require 'puppet/external/nagios/base' +require 'puppet/provider/naginator' + +module Puppet::Util::NagiosMaker + # Create a new nagios type, using all of the parameters + # from the parser. + def self.create_nagios_type(name) + name = name.to_sym + full_name = ("nagios_" + name.to_s).to_sym + + raise(Puppet::DevError, "No nagios type for %s" % name) unless nagtype = Nagios::Base.type(name) + + type = Puppet::Type.newtype(full_name) {} + + type.ensurable + + type.newparam(nagtype.namevar, :namevar => true) do + desc "The name parameter for Nagios type %s" % nagtype.name + end + + # We deduplicate the parameters because it makes sense to allow Naginator to have dupes. + nagtype.parameters.uniq.each do |param| + next if param == nagtype.namevar + + # We can't turn these parameter names into constants, so at least for now they aren't + # supported. + next if param.to_s =~ /^[0-9]/ + + type.newproperty(param) do + desc "Nagios configuration file parameter." + end + end + + type.newproperty(:target) do + desc 'target' + + defaultto do + resource.class.defaultprovider.default_target + end + end + + provider = type.provide(:naginator, :parent => Puppet::Provider::Naginator, :default_target => "/etc/nagios/#{full_name.to_s}.cfg") {} + + type.desc "The Nagios type #{name.to_s}. This resource type is autogenerated using the + model developed in Naginator_, and all of the Nagios types are generated using the + same code and the same library. + + This type generates Nagios configuration statements in Nagios-parseable configuration + files. By default, the statements will be added to ``#{provider.default_target}, but + you can send them to a different file by setting their ``target`` attribute. + + .. _naginator: http://reductivelabs.com/trac/naginator + " + end +end |