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}
Class Method Summary collapse
-
.check(params = {}) ⇒ Object
synchrony check, for manually calls.
- .check_name ⇒ Object
- .default_error(mes) ⇒ Object
- .interval ⇒ Object
- .url ⇒ 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.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/nagios/check.rb', line 5 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 logger.info "=> #{@tag}" @ok = [] @crit = [] @warn = [] @other = [] end |
Class Method Details
.check(params = {}) ⇒ Object
synchrony check, for manually calls
50 51 52 53 54 55 56 57 58 |
# File 'lib/nagios/check.rb', line 50 def self.check(params = {}) result = nil inst = self.new(params) do |res| result = res end inst.run end |
.check_name ⇒ Object
128 129 130 |
# File 'lib/nagios/check.rb', line 128 def check_name @check_name ||= self.name.underscore end |
.default_error(mes) ⇒ Object
60 61 62 |
# File 'lib/nagios/check.rb', line 60 def self.default_error(mes) [Nagios::OTHER, mes] end |
.interval ⇒ Object
136 137 138 |
# File 'lib/nagios/check.rb', line 136 def interval 5 * 60 end |
.url ⇒ Object
132 133 134 |
# File 'lib/nagios/check.rb', line 132 def url "http://localhost:3000/nagios/check?method=#{check_name}" end |
Instance Method Details
#result ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nagios/check.rb', line 20 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nagios/check.rb', line 36 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 |