Class: Outpost::Application
- Inherits:
-
Object
- Object
- Outpost::Application
- Defined in:
- lib/outpost/application.rb
Overview
This class is the basic structure of an Outpost application. It provides the basic DSL for you to configure the monitoring of your services. Example:
class ExampleSuccess < Outpost::Application
name "Example"
using Outpost::Scouts::Http => 'master http server' do
:host => 'localhost', :port => 9595
report :up, :response_code => 200
end
end
The above example will set templates and every new instance of ExampleSuccess will have the same behavior. But all the methods are available to instances, so it is also possible to create Outpost applications as the following example:
my_outpost = Outpost::Application.new
my_outpost.name = 'Example'
my_outpost.using(Outpost::Scouts::Http => 'master http server') do
:host => 'localhost', :port => 9595
report :up, :response_code => 200
end
Instance Attribute Summary collapse
-
#last_status ⇒ Object
readonly
Returns the status of the last service check or nil if it didn’t happen.
-
#name ⇒ Object
Reader/setter for the name of this scout.
-
#notifiers ⇒ Object
readonly
Returns all the registered notifiers.
-
#reports ⇒ Object
readonly
Returns a list of Report containing the last results of the last check.
-
#scouts ⇒ Object
readonly
Returns all the registered scouts.
Class Method Summary collapse
-
.name(val = nil) ⇒ Object
Set the name of the scout.
- .name_template ⇒ Object
- .notifier_templates ⇒ Object
-
.notify(notifier, options = {}) ⇒ Object
Register a notifier class in the list of notifications.
- .scout_templates ⇒ Object
-
.using(scout_description) { ... } ⇒ Object
Register a scout in the list of scouts.
Instance Method Summary collapse
- #add_notifier(notifier_name, options) ⇒ Object
- #add_scout(scout_description, &block) ⇒ Object
-
#down? ⇒ Boolean
Returns true if the last status is :down.
-
#initialize ⇒ Application
constructor
New instance of a Outpost-based class.
-
#messages ⇒ Array<String>
Returns the messages of the latest service check.
-
#notify ⇒ Object
Runs all notifications associated with an Outpost-based class.
-
#run ⇒ Object
Execute all the scouts associated with an Outpost-based class and returns either :up or :down, depending on the results.
-
#up? ⇒ Boolean
Returns true if the last status is :up.
-
#warning? ⇒ Boolean
Returns true if the last status is :warning.
Constructor Details
#initialize ⇒ Application
New instance of a Outpost-based class.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/outpost/application.rb', line 95 def initialize @reports = {} @last_status = nil @scouts = Hash.new { |h, k| h[k] = {} } @notifiers = {} @name = self.class.name_template # Register scouts self.class.scout_templates.each do |template| add_scout(template[:scout_description], &template[:block]) end self.class.notifier_templates.each do |template| add_notifier(template[:notifier], template[:options]) end end |
Instance Attribute Details
#last_status ⇒ Object (readonly)
Returns the status of the last service check or nil if it didn’t happen.
80 81 82 |
# File 'lib/outpost/application.rb', line 80 def last_status @last_status end |
#name ⇒ Object
Reader/setter for the name of this scout
92 93 94 |
# File 'lib/outpost/application.rb', line 92 def name @name end |
#notifiers ⇒ Object (readonly)
Returns all the registered notifiers.
89 90 91 |
# File 'lib/outpost/application.rb', line 89 def notifiers @notifiers end |
#reports ⇒ Object (readonly)
Returns a list of Report containing the last results of the last check.
83 84 85 |
# File 'lib/outpost/application.rb', line 83 def reports @reports end |
#scouts ⇒ Object (readonly)
Returns all the registered scouts.
86 87 88 |
# File 'lib/outpost/application.rb', line 86 def scouts @scouts end |
Class Method Details
.name(val = nil) ⇒ Object
Set the name of the scout. Can be used by notifiers in order to have a better description of the service in question.
73 74 75 76 |
# File 'lib/outpost/application.rb', line 73 def name(val=nil) @name_template = val if val @name_template end |
.name_template ⇒ Object
36 37 38 |
# File 'lib/outpost/application.rb', line 36 def name_template @name_template || self.to_s end |
.notifier_templates ⇒ Object
32 33 34 |
# File 'lib/outpost/application.rb', line 32 def notifier_templates @notifier_templates || [] end |
.notify(notifier, options = {}) ⇒ Object
Register a notifier class in the list of notifications.
63 64 65 66 |
# File 'lib/outpost/application.rb', line 63 def notify(notifier, ={}) @notifier_templates ||= [] @notifier_templates << {:notifier => notifier, :options => } end |
.scout_templates ⇒ Object
28 29 30 |
# File 'lib/outpost/application.rb', line 28 def scout_templates @scout_templates || [] end |
.using(scout_description) { ... } ⇒ Object
Register a scout in the list of scouts.
46 47 48 49 50 51 52 |
# File 'lib/outpost/application.rb', line 46 def using(scout_description, &block) @scout_templates ||= [] @scout_templates << { :scout_description => scout_description, :block => block } end |
Instance Method Details
#add_notifier(notifier_name, options) ⇒ Object
124 125 126 |
# File 'lib/outpost/application.rb', line 124 def add_notifier(notifier_name, ) @notifiers[notifier_name] = end |
#add_scout(scout_description, &block) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/outpost/application.rb', line 113 def add_scout(scout_description, &block) config = ScoutConfig.new config.instance_eval(&block) scout_description.each do |scout, description| @scouts[scout][:description] = description @scouts[scout][:config] = config end end |
#down? ⇒ Boolean
Returns true if the last status is :down
162 163 164 |
# File 'lib/outpost/application.rb', line 162 def down? @last_status == :down end |
#messages ⇒ Array<String>
Returns the messages of the latest service check.
169 170 171 |
# File 'lib/outpost/application.rb', line 169 def reports.map { |_, r| r.to_s } end |
#notify ⇒ Object
Runs all notifications associated with an Outpost-based class.
141 142 143 144 145 146 147 148 149 |
# File 'lib/outpost/application.rb', line 141 def notify if reports.any? @notifiers.each do |notifier, | # .dup is NOT reliable = Marshal.load(Marshal.dump()) notifier.new().notify(self) end end end |
#run ⇒ Object
Execute all the scouts associated with an Outpost-based class and returns either :up or :down, depending on the results.
130 131 132 133 134 135 136 137 138 |
# File 'lib/outpost/application.rb', line 130 def run scouts.map do |scout, | @reports[[:description]] = run_scout(scout, ) end statuses = @reports.map { |_, r| r.status } @last_status = Report.summarize(statuses) end |
#up? ⇒ Boolean
Returns true if the last status is :up
152 153 154 |
# File 'lib/outpost/application.rb', line 152 def up? @last_status == :up end |
#warning? ⇒ Boolean
Returns true if the last status is :warning
157 158 159 |
# File 'lib/outpost/application.rb', line 157 def warning? @last_status == :warning end |