Class: Htmon::Icinga::Module
- Inherits:
-
Object
- Object
- Htmon::Icinga::Module
- Defined in:
- lib/htmon/icinga/module.rb,
lib/htmon/icinga/modules/load.rb,
lib/htmon/icinga/modules/process.rb,
lib/htmon/icinga/modules/packages.rb,
lib/htmon/icinga/modules/keepalive.rb
Defined Under Namespace
Classes: Keepalive, Load, Packages, Process
Class Attribute Summary collapse
-
.callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
.metric_name ⇒ Object
Returns the value of attribute metric_name.
-
.performance_data ⇒ Object
readonly
Returns the value of attribute performance_data.
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#metric ⇒ Object
Returns the value of attribute metric.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#thresh ⇒ Object
Returns the value of attribute thresh.
-
#warn ⇒ Object
Returns the value of attribute warn.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hostname: nil, thresh: nil, warn: nil, redis: nil, metric: nil) ⇒ Module
constructor
A new instance of Module.
- #result ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(hostname: nil, thresh: nil, warn: nil, redis: nil, metric: nil) ⇒ Module
Returns a new instance of Module.
83 84 85 |
# File 'lib/htmon/icinga/module.rb', line 83 def initialize hostname: nil, thresh: nil, warn: nil, redis: nil, metric: nil @hostname, @thresh, @warn, @redis, @metric = hostname, thresh, warn, redis, metric end |
Class Attribute Details
.callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
56 57 58 |
# File 'lib/htmon/icinga/module.rb', line 56 def callbacks @callbacks end |
.metric_name ⇒ Object
Returns the value of attribute metric_name.
55 56 57 |
# File 'lib/htmon/icinga/module.rb', line 55 def metric_name @metric_name end |
.performance_data ⇒ Object (readonly)
Returns the value of attribute performance_data.
56 57 58 |
# File 'lib/htmon/icinga/module.rb', line 56 def performance_data @performance_data end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
81 82 83 |
# File 'lib/htmon/icinga/module.rb', line 81 def hostname @hostname end |
#metric ⇒ Object
Returns the value of attribute metric.
81 82 83 |
# File 'lib/htmon/icinga/module.rb', line 81 def metric @metric end |
#redis ⇒ Object
Returns the value of attribute redis.
81 82 83 |
# File 'lib/htmon/icinga/module.rb', line 81 def redis @redis end |
#thresh ⇒ Object
Returns the value of attribute thresh.
81 82 83 |
# File 'lib/htmon/icinga/module.rb', line 81 def thresh @thresh end |
#warn ⇒ Object
Returns the value of attribute warn.
81 82 83 |
# File 'lib/htmon/icinga/module.rb', line 81 def warn @warn end |
Class Method Details
.callback(method, &block) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/htmon/icinga/module.rb', line 70 def callback method, &block @callbacks ||= {} if block_given? @callbacks[method] = block else @callbacks[method] end end |
.inherited(klass) ⇒ Object
62 63 64 |
# File 'lib/htmon/icinga/module.rb', line 62 def inherited klass modules << klass end |
.modules ⇒ Object
58 59 60 |
# File 'lib/htmon/icinga/module.rb', line 58 def modules @modules ||= [] end |
Instance Method Details
#result ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/htmon/icinga/module.rb', line 91 def result hv = self.class.callbacks[:handle_value] post_value = hv ? hv.call(value, self.metric) : value %i{on_ok on_warn on_crit}.map do |type| c = self.class.callbacks[type] ret = Result.new = c && c.call(post_value, warn, thresh) if ret.level = type.to_s.gsub('on_', '') ret. = ret else nil end end.find{|x| x.instance_of? Result } or Result.new("unexpect situation occured", :unknown) end |
#value ⇒ Object
109 110 111 |
# File 'lib/htmon/icinga/module.rb', line 109 def value @value ||= redis.get "metric::#{hostname}::#{self.metric}" end |