Class: Puppet::Provider::Naginator

Inherits:
ParsedFile
  • Object
show all
Defined in:
core_modules/nagios_core/lib/puppet/provider/naginator.rb

Overview

The base class for all Naginator providers.

Constant Summary collapse

NAME_STRING =
"## --PUPPET_NAME-- (called '_naginator_name' in the manifest)".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource = nil) ⇒ Naginator

Returns a new instance of Naginator.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 50

def initialize(resource = nil)
  if resource.is_a?(Nagios::Base)
    # We don't use a duplicate here, because some providers (ParsedFile, at least)
    # use the hash here for later events.
    @property_hash = resource
  elsif resource
    @resource = resource if resource
    # LAK 2007-05-09: Keep the model stuff around for backward compatibility
    @model = resource
    @property_hash = self.class.nagios_type.new
  else
    @property_hash = self.class.nagios_type.new
  end
end

Class Method Details

.nagios_typeObject

Retrieve the associated class from Nagios::Base.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 9

def self.nagios_type
  unless @nagios_type
    name = resource_type.name.to_s.sub(%r{^nagios_}, '')
    @nagios_type = Nagios::Base.type(name.to_sym)
    unless @nagios_type
      raise Puppet::DevError, _("Could not find nagios type '%{name}'") % { name: name }
    end

    # And add our 'ensure' settings, since they aren't a part of
    # Naginator by default
    @nagios_type.send(:attr_accessor, :ensure, :target, :on_disk)
  end
  @nagios_type
end

.parse(text) ⇒ Object



24
25
26
27
28
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 24

def self.parse(text)
  Nagios::Parser.new.parse(text.gsub(NAME_STRING, '_naginator_name'))
rescue => detail
  raise Puppet::Error, _('Could not parse configuration for %{resource}: %{detail}') % { resource: resource_type.name, detail: detail }, detail.backtrace
end

.skip_record?(_record) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 42

def self.skip_record?(_record)
  false
end

.to_file(records) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 30

def self.to_file(records)
  header + records.map { |record|
    # Remap the TYPE_name or _naginator_name params to the
    # name if the record is a template (register == 0)
    if record.to_s =~ %r{register\s+0}
      record.to_s.sub('_naginator_name', 'name').sub(record.type.to_s + '_name', 'name')
    else
      record.to_s.sub('_naginator_name', NAME_STRING)
    end
  }.join("\n")
end

.valid_attr?(_klass, attr_name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'core_modules/nagios_core/lib/puppet/provider/naginator.rb', line 46

def self.valid_attr?(_klass, attr_name)
  nagios_type.parameters.include?(attr_name)
end