diff options
| author | Luke Kanies <luke@madstop.com> | 2007-12-31 14:37:03 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-12-31 14:37:03 -0600 |
| commit | 33e319a8be8e35fbe4a9ecb7e3185453b8239a83 (patch) | |
| tree | 15cb3788a9a3c783463e2cc129a7cf03c77498a0 | |
| parent | 68cde4f1babe3ebf61ffe215c6328faf7818d40f (diff) | |
| download | puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.tar.gz puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.tar.xz puppet-33e319a8be8e35fbe4a9ecb7e3185453b8239a83.zip | |
Added builtin support for all Nagios resource types.
I use Naginator to parse and generate the files, with
ParsedFile to handle record management and the like.
Note that each resource type itself is just a call to
a Factory method, since everything is just based on Naginator.
Given that, all of the tests are in a single unit/ral/types/nagios.rb
file, since I used a factory to generate them, too. This is probably
either unnecessary or insufficient, but it's as far as I'm
willing to go in testing them, and it did actually catch a few
bugs.
| -rw-r--r-- | CHANGELOG | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_command.rb | 31 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_contact.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_contactgroup.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_host.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_hostextinfo.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_hostgroup.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_hostgroupescalation.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_service.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_servicedependency.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_serviceescalation.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_serviceextinfo.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/nagios_timeperiod.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/util/nagios_maker.rb | 20 | ||||
| -rwxr-xr-x | spec/unit/ral/types/nagios.rb | 55 | ||||
| -rwxr-xr-x | spec/unit/util/nagios_maker.rb | 24 |
16 files changed, 135 insertions, 31 deletions
@@ -1,3 +1,6 @@ + Added builtin support for Nagios types using + Naginator to parse and generate the files. + 0.24.1 Updated vim filetype detection. (#900 and #963) diff --git a/lib/puppet/type/nagios_command.rb b/lib/puppet/type/nagios_command.rb index f366e9d72..0d0e11b17 100644 --- a/lib/puppet/type/nagios_command.rb +++ b/lib/puppet/type/nagios_command.rb @@ -1,30 +1,3 @@ -require 'puppet/external/nagios' -require 'puppet/external/nagios/base' +require 'puppet/util/nagios_maker' -Puppet::Type.newtype(:nagios_command) do - ensurable - - nagtype = Nagios::Base.type(:command) - - raise "No nagios type" unless nagtype - - newparam(nagtype.namevar, :namevar => true) do - desc "The name parameter for Nagios type %s" % nagtype.name - end - - nagtype.parameters.each do |param| - next if param == nagtype.namevar - - newproperty(param) do - desc "Nagios configuration file parameter." - end - end - - newproperty(:target) do - desc 'target' - - defaultto do - resource.class.defaultprovider.default_target - end - end -end +Puppet::Util::NagiosMaker.create_nagios_type :command diff --git a/lib/puppet/type/nagios_contact.rb b/lib/puppet/type/nagios_contact.rb new file mode 100644 index 000000000..d5a1f3cba --- /dev/null +++ b/lib/puppet/type/nagios_contact.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :contact diff --git a/lib/puppet/type/nagios_contactgroup.rb b/lib/puppet/type/nagios_contactgroup.rb new file mode 100644 index 000000000..b8f14c07b --- /dev/null +++ b/lib/puppet/type/nagios_contactgroup.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :contactgroup diff --git a/lib/puppet/type/nagios_host.rb b/lib/puppet/type/nagios_host.rb new file mode 100644 index 000000000..f2e03f6fb --- /dev/null +++ b/lib/puppet/type/nagios_host.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :host diff --git a/lib/puppet/type/nagios_hostextinfo.rb b/lib/puppet/type/nagios_hostextinfo.rb new file mode 100644 index 000000000..da8e08dd8 --- /dev/null +++ b/lib/puppet/type/nagios_hostextinfo.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :hostextinfo diff --git a/lib/puppet/type/nagios_hostgroup.rb b/lib/puppet/type/nagios_hostgroup.rb new file mode 100644 index 000000000..e1943beec --- /dev/null +++ b/lib/puppet/type/nagios_hostgroup.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :hostgroup diff --git a/lib/puppet/type/nagios_hostgroupescalation.rb b/lib/puppet/type/nagios_hostgroupescalation.rb new file mode 100644 index 000000000..21b39f681 --- /dev/null +++ b/lib/puppet/type/nagios_hostgroupescalation.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :hostgroupescalation diff --git a/lib/puppet/type/nagios_service.rb b/lib/puppet/type/nagios_service.rb new file mode 100644 index 000000000..22b987f56 --- /dev/null +++ b/lib/puppet/type/nagios_service.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :service diff --git a/lib/puppet/type/nagios_servicedependency.rb b/lib/puppet/type/nagios_servicedependency.rb new file mode 100644 index 000000000..0e3340c6e --- /dev/null +++ b/lib/puppet/type/nagios_servicedependency.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :servicedependency diff --git a/lib/puppet/type/nagios_serviceescalation.rb b/lib/puppet/type/nagios_serviceescalation.rb new file mode 100644 index 000000000..cb2af1545 --- /dev/null +++ b/lib/puppet/type/nagios_serviceescalation.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :serviceescalation diff --git a/lib/puppet/type/nagios_serviceextinfo.rb b/lib/puppet/type/nagios_serviceextinfo.rb new file mode 100644 index 000000000..6bdc70900 --- /dev/null +++ b/lib/puppet/type/nagios_serviceextinfo.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :serviceextinfo diff --git a/lib/puppet/type/nagios_timeperiod.rb b/lib/puppet/type/nagios_timeperiod.rb new file mode 100644 index 000000000..25a06d3ed --- /dev/null +++ b/lib/puppet/type/nagios_timeperiod.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :timeperiod diff --git a/lib/puppet/util/nagios_maker.rb b/lib/puppet/util/nagios_maker.rb index 7c019f55e..f1f85466f 100644 --- a/lib/puppet/util/nagios_maker.rb +++ b/lib/puppet/util/nagios_maker.rb @@ -19,9 +19,14 @@ module Puppet::Util::NagiosMaker desc "The name parameter for Nagios type %s" % nagtype.name end - nagtype.parameters.each do |param| + # 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 @@ -35,6 +40,17 @@ module Puppet::Util::NagiosMaker end end - type.provide(:naginator, :parent => Puppet::Provider::Naginator, :default_target => "/etc/nagios/#{full_name.to_s}.cfg") {} + 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 diff --git a/spec/unit/ral/types/nagios.rb b/spec/unit/ral/types/nagios.rb new file mode 100755 index 000000000..8aca7d401 --- /dev/null +++ b/spec/unit/ral/types/nagios.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/external/nagios' + +Nagios::Base.eachtype do |name, nagios_type| + puppet_type = Puppet::Type.type("nagios_" + name.to_s) + + describe puppet_type do + it "should be defined as a Puppet resource type" do + puppet_type.should_not be_nil + end + + it "should have documentation" do + puppet_type.instance_variable_get("@doc").should_not == "" + end + + it "should have %s as its namevar" % nagios_type.namevar do + puppet_type.namevar.should == nagios_type.namevar + end + + it "should have documentation for its %s parameter" % nagios_type.namevar do + puppet_type.attrclass(nagios_type.namevar).instance_variable_get("@doc").should_not be_nil + end + + it "should have an ensure property" do + puppet_type.should be_validproperty(:ensure) + end + + it "should have a target property" do + puppet_type.should be_validproperty(:target) + end + + it "should have documentation for its target property" do + puppet_type.attrclass(:target).instance_variable_get("@doc").should_not be_nil + end + + nagios_type.parameters.reject { |param| param == nagios_type.namevar or param.to_s =~ /^[0-9]/ }.each do |param| + it "should have a %s property" % param do + puppet_type.should be_validproperty(param) + end + + it "should have documentation for its %s property" % param do + puppet_type.attrclass(param).instance_variable_get("@doc").should_not be_nil + end + end + + nagios_type.parameters.find_all { |param| param.to_s =~ /^[0-9]/ }.each do |param| + it "should have not have a %s property" % param do + puppet_type.should_not be_validproperty(:param) + end + end + end +end diff --git a/spec/unit/util/nagios_maker.rb b/spec/unit/util/nagios_maker.rb index 145f8633a..0454b6503 100755 --- a/spec/unit/util/nagios_maker.rb +++ b/spec/unit/util/nagios_maker.rb @@ -63,6 +63,30 @@ describe Puppet::Util::NagiosMaker do @module.create_nagios_type(:test) end + it "should skip parameters that start with integers" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil + + @nagtype.stubs(:parameters).returns(["2dcoords".to_sym, :other]) + + type.expects(:newproperty).with(:other) + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should deduplicate the parameter list" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil + + @nagtype.stubs(:parameters).returns([:one, :one]) + + type.expects(:newproperty).with(:one) + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + it "should create a target property" do type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil |
