Class: NagiosResque::Check
- Inherits:
-
Object
- Object
- NagiosResque::Check
- Defined in:
- lib/nagios_resque/check.rb
Defined Under Namespace
Classes: ResqueRedis
Instance Method Summary collapse
- #critical? ⇒ Boolean
- #critical_message ⇒ Object
-
#initialize(options) ⇒ Check
constructor
A new instance of Check.
- #last_run_at ⇒ Object
- #ok_message ⇒ Object
- #passed_time ⇒ Object
-
#payload ⇒ Object
It is just (:class => @job, :args => []).to_json Don’t want to depend on resque gem which itself has many dependecies.
- #requeue ⇒ Object
- #warning? ⇒ Boolean
- #warning_message ⇒ Object
Constructor Details
#initialize(options) ⇒ Check
Returns a new instance of Check.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/nagios_resque/check.rb', line 3 def initialize() @host = [:host] || "localhost" @port = [:port] || 6379 @namespace = [:namespace] || "resque" @job = [:job] || 'NagiosResque::Job' @warning = [:warn] @critical = [:crit] @redis = ResqueRedis.new(:host => @host, :port => @port, :namespace => @namespace) end |
Instance Method Details
#critical? ⇒ Boolean
30 31 32 33 |
# File 'lib/nagios_resque/check.rb', line 30 def critical? return true unless passed_time @critical && (passed_time.nil? || @critical.first < passed_time) end |
#critical_message ⇒ Object
84 85 86 |
# File 'lib/nagios_resque/check.rb', line 84 def "haven't run in #{@critical.first} seconds" end |
#last_run_at ⇒ Object
35 36 37 38 39 |
# File 'lib/nagios_resque/check.rb', line 35 def last_run_at if time = @redis.get(NAGIOS_RESQUE_TIMESTAMP_KEY) Integer(time) end end |
#ok_message ⇒ Object
76 77 78 |
# File 'lib/nagios_resque/check.rb', line 76 def "last run at #{Time.at(last_run_at).strftime('%Y-%m-%d %H:%M:%S %z')}" end |
#passed_time ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nagios_resque/check.rb', line 41 def passed_time # need to cache because there is small time difference between checks return @passed_time if defined?(@passed_time) @passed_time = if time = last_run_at Integer(Time.now - time) else nil end end |
#payload ⇒ Object
It is just (:class => @job, :args => []).to_json Don’t want to depend on resque gem which itself has many dependecies
16 17 18 |
# File 'lib/nagios_resque/check.rb', line 16 def payload %Q({"class":"#{@job}","args":[]}) end |
#requeue ⇒ Object
20 21 22 23 24 |
# File 'lib/nagios_resque/check.rb', line 20 def requeue @redis.sadd 'queues', 'high' @redis.lrem 'queue:high', 0, payload @redis.rpush 'queue:high', payload end |
#warning? ⇒ Boolean
26 27 28 |
# File 'lib/nagios_resque/check.rb', line 26 def warning? @warning && (passed_time.nil? || @warning.include?(passed_time)) end |
#warning_message ⇒ Object
80 81 82 |
# File 'lib/nagios_resque/check.rb', line 80 def "haven't run in #{@warning.last} seconds" end |