class Snmp2mkr::ConfigTypes::VhostDiscoveryRule

Attributes

keys[R]
metrics[R]
name[R]
roles[R]

Public Instance Methods

collect_children() click to toggle source
# File lib/snmp2mkr/config_types/vhost_discovery_rule.rb, line 33
def collect_children
  [
    *@metrics,
    *@keys.values,
    *@roles,
    @name,
  ]
end
setup(hash) click to toggle source
# File lib/snmp2mkr/config_types/vhost_discovery_rule.rb, line 9
def setup(hash)
  metrics_hash = hash.fetch('metrics')
  if !metrics_hash.kind_of?(Hash) || metrics_hash.any? { |k,v| !k.kind_of?(String) }
    raise TypeError, "#{self.class} metrics must be a Hash<String, Object)>"
  end

  keys_hash = hash.fetch('keys')
  if !keys_hash.kind_of?(Hash) || keys_hash.any? { |k,v| !k.kind_of?(String) }
    raise TypeError, "#{self.class} keys must be a Hash<String, Object>"
  end

  roles = hash.fetch('roles', [])
  if !roles.kind_of?(Array) || roles.any? { |k,v| !k.kind_of?(String) }
    raise TypeError, "#{self.class} roles must be a Array<String>"
  end

  @keys = keys_hash.map { |k, v| [k, Oid.new(v)] }.to_h
  @name = TemplateString.new(hash.fetch('name'))
  @roles = roles.map { |v| TemplateString.new(v) }
  @metrics = MetricDefinitionCollection.new(metrics_hash)
end