Class: Snmp2mkr::ConfigTypes::MetricDiscoveryRule

Inherits:
Base
  • Object
show all
Defined in:
lib/snmp2mkr/config_types/metric_discovery_rule.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#binded_context

Instance Method Summary collapse

Methods inherited from Base

#bind_context, #children, #evaluate, #initialize, #inspect

Constructor Details

This class inherits a constructor from Snmp2mkr::ConfigTypes::Base

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



22
23
24
# File 'lib/snmp2mkr/config_types/metric_discovery_rule.rb', line 22

def keys
  @keys
end

#metricsObject (readonly)

Returns the value of attribute metrics.



22
23
24
# File 'lib/snmp2mkr/config_types/metric_discovery_rule.rb', line 22

def metrics
  @metrics
end

Instance Method Details

#collect_childrenObject



24
25
26
27
28
29
# File 'lib/snmp2mkr/config_types/metric_discovery_rule.rb', line 24

def collect_children
  [
    @metrics,
    *@keys.values,
  ]
end

#setup(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/snmp2mkr/config_types/metric_discovery_rule.rb', line 7

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

  @metrics = MetricDefinitionCollection.new(metrics_hash)
  @keys = keys_hash.map { |k, v| [k, Oid.new(v)] }.to_h
end