Class: Nagios::Check
- Inherits:
-
Object
- Object
- Nagios::Check
- Defined in:
- lib/nagios/check.rb
Direct Known Subclasses
Constant Summary collapse
- TYPES =
%w{ok crit other warn}
Instance Attribute Summary collapse
-
#check_name ⇒ Object
readonly
Returns the value of attribute check_name.
Class Method Summary collapse
-
.check(params = {}) ⇒ Object
synchrony check, for manually calls.
- .check_name ⇒ Object
- .default_error(mes) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}, &callback) ⇒ Check
constructor
A new instance of Check.
- #result ⇒ Object
- #run(additional_params = nil) ⇒ Object (also: #check)
Constructor Details
#initialize(params = {}, &callback) ⇒ Check
Returns a new instance of Check.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nagios/check.rb', line 7 def initialize(params = {}, &callback) @params = params.with_indifferent_access @callback = callback @started_at = Time.now @tag = "#{self.class.name}/#{params.inspect}" @check_name = self.class.name.underscore.split("/").last logger.info "=> #{@tag}" @ok = [] @crit = [] @warn = [] @other = [] end |
Instance Attribute Details
#check_name ⇒ Object (readonly)
Returns the value of attribute check_name.
5 6 7 |
# File 'lib/nagios/check.rb', line 5 def check_name @check_name end |
Class Method Details
.check(params = {}) ⇒ Object
synchrony check, for manually calls
52 53 54 55 56 57 58 59 60 |
# File 'lib/nagios/check.rb', line 52 def self.check(params = {}) result = nil inst = self.new(params) do |res| result = res end inst.run end |
.check_name ⇒ Object
130 131 132 |
# File 'lib/nagios/check.rb', line 130 def check_name @check_name ||= self.name.underscore.split("/").last end |
Instance Method Details
#result ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nagios/check.rb', line 22 def result prefix = self.respond_to?(:message_prefix) ? : '' errors = prefix + [@crit, @warn, @other].flatten * '; ' if @crit.present? [Nagios::CRIT, errors] elsif @warn.present? [Nagios::WARN, errors] elsif @other.present? [Nagios::OTHER, errors] else @ok = ['OK'] if prefix.empty? && @ok.empty? [Nagios::OK, prefix + @ok * '; '] end end |
#run(additional_params = nil) ⇒ Object Also known as: check
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nagios/check.rb', line 38 def run(additional_params = nil) if additional_params && additional_params.is_a?(Hash) @params.merge!(additional_params.with_indifferent_access) end safe do execute send_result end end |