Class: SrvMonitor::Application
- Inherits:
-
Object
- Object
- SrvMonitor::Application
- Defined in:
- lib/srvmonitor/application.rb
Constant Summary collapse
- SERVER_OPTIONS =
[:host, :method, :user, :password]
Instance Attribute Summary collapse
-
#name(name) ⇒ Object
readonly
Returns the value of attribute name.
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
-
#scout_config ⇒ Object
readonly
Returns the value of attribute scout_config.
-
#scout_klass ⇒ Object
readonly
Returns the value of attribute scout_klass.
-
#scouts ⇒ Object
readonly
Returns the value of attribute scouts.
-
#servers(*args) ⇒ Object
readonly
Returns the value of attribute servers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#down? ⇒ Boolean
Returns true if the last status is :down.
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #label ⇒ Object
-
#report(status, params) ⇒ Object
Reads reporting as: report :up, :response_code => 200.
- #run(alert) ⇒ Object
- #scout(klass, args = {}) ⇒ Object
- #server(server, options = {}) ⇒ Object
-
#up? ⇒ Boolean
Returns true if the last status is :up.
-
#warning? ⇒ Boolean
Returns true if the last status is :warning.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
14 15 16 17 |
# File 'lib/srvmonitor/application.rb', line 14 def initialize @scouts = [] @reports = {} end |
Instance Attribute Details
#name(name) ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/srvmonitor/application.rb', line 4 def name @name end |
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
4 5 6 |
# File 'lib/srvmonitor/application.rb', line 4 def reports @reports end |
#scout_config ⇒ Object (readonly)
Returns the value of attribute scout_config.
3 4 5 |
# File 'lib/srvmonitor/application.rb', line 3 def scout_config @scout_config end |
#scout_klass ⇒ Object (readonly)
Returns the value of attribute scout_klass.
3 4 5 |
# File 'lib/srvmonitor/application.rb', line 3 def scout_klass @scout_klass end |
#scouts ⇒ Object (readonly)
Returns the value of attribute scouts.
3 4 5 |
# File 'lib/srvmonitor/application.rb', line 3 def scouts @scouts end |
#servers(*args) ⇒ Object (readonly)
Returns the value of attribute servers.
4 5 6 |
# File 'lib/srvmonitor/application.rb', line 4 def servers @servers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/srvmonitor/application.rb', line 4 def status @status end |
Class Method Details
.create(&block) ⇒ Object
8 9 10 11 12 |
# File 'lib/srvmonitor/application.rb', line 8 def self.create(&block) self.new.tap do |application| application.instance_eval(&block) end end |
Instance Method Details
#down? ⇒ Boolean
Returns true if the last status is :down
88 89 90 |
# File 'lib/srvmonitor/application.rb', line 88 def down? @status == :down end |
#label ⇒ Object
92 93 94 |
# File 'lib/srvmonitor/application.rb', line 92 def label @name || @scout_klass.to_s end |
#report(status, params) ⇒ Object
Reads reporting as:
report :up, :response_code => 200
gets stored as:
{:response_code => 200} = up
48 49 50 |
# File 'lib/srvmonitor/application.rb', line 48 def report(status, params) @reports[params] = status end |
#run(alert) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/srvmonitor/application.rb', line 52 def run(alert) puts "\n### Runing #{label}" statuses = [] tries = 0 @scouts.each do |scout| scout.run(@reports) if scout.status == alert[:if] if tries < alert[:retries] tries += 1 redo else tries = 0 statuses << scout.status end else statuses << scout.status end end @status = SrvMonitor::Report.summarize(statuses) end |
#scout(klass, args = {}) ⇒ Object
23 24 25 26 |
# File 'lib/srvmonitor/application.rb', line 23 def scout(klass, args={}) @scout_klass = klass @scout_config = args end |
#server(server, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/srvmonitor/application.rb', line 28 def server(server, ={}) server_config = .select{ |key, _| key if SERVER_OPTIONS.include?(key) } config = .delete_if{ |key, _| server_config.include?(key) } config[:server] = server.clone(server_config) @scouts << @scout_klass.new(@scout_config.merge config ) end |
#up? ⇒ Boolean
Returns true if the last status is :up
78 79 80 |
# File 'lib/srvmonitor/application.rb', line 78 def up? @status == :up end |
#warning? ⇒ Boolean
Returns true if the last status is :warning
83 84 85 |
# File 'lib/srvmonitor/application.rb', line 83 def warning? @status == :warning end |