Class: Htmon::Icinga::Module

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

Keepalive, Load, Packages, Process

Defined Under Namespace

Classes: Keepalive, Load, Packages, Process

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.callbacksObject (readonly)

Returns the value of attribute callbacks.



56
57
58
# File 'lib/htmon/icinga/module.rb', line 56

def callbacks
  @callbacks
end

.metric_nameObject

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_dataObject (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

#hostnameObject

Returns the value of attribute hostname.



81
82
83
# File 'lib/htmon/icinga/module.rb', line 81

def hostname
  @hostname
end

#metricObject

Returns the value of attribute metric.



81
82
83
# File 'lib/htmon/icinga/module.rb', line 81

def metric
  @metric
end

#redisObject

Returns the value of attribute redis.



81
82
83
# File 'lib/htmon/icinga/module.rb', line 81

def redis
  @redis
end

#threshObject

Returns the value of attribute thresh.



81
82
83
# File 'lib/htmon/icinga/module.rb', line 81

def thresh
  @thresh
end

#warnObject

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

.modulesObject



58
59
60
# File 'lib/htmon/icinga/module.rb', line 58

def modules
  @modules ||= []
end

Instance Method Details

#resultObject



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
    message = c && c.call(post_value, warn, thresh)
    if message
      ret.level = type.to_s.gsub('on_', '')
      ret.message = message
      ret
    else
      nil
    end
  end.find{|x| x.instance_of? Result } or 
    Result.new("unexpect situation occured", :unknown)
end

#valueObject



109
110
111
# File 'lib/htmon/icinga/module.rb', line 109

def value
  @value ||= redis.get "metric::#{hostname}::#{self.metric}"
end