Class: Watcher::Base
Overview
Base class for all Watcher.
A watcher checks for a condition (e.g., if a web site responds, if a log file shows signs of trouble). Each watcher will have one or more actions attached that will be called if the watched condition is triggered.
Options
Each watcher will accept the following options, which are handled by the superclass:
- severity
-
Severity of the event. Each time the event is triggered, the watcher will add this value to the internal “severity”. If the internal severity reaches 100, the action is triggered. This means that with a severity of 100 the action is run each time the watcher triggers. With a severity of 1, it is only executed every 100th time. The global mechanism will reset the severity once the action is triggered. The watcher class may decide to reset the severity also on other occasions. Default: 100
- actions
-
The actions that should be executed when the watcher triggers. These are names of actions that have been set up previously. (Required)
- warn_actions
-
Additional actions that are executed if the watcher triggers, but the severity for a real action is not yet reached.
Each watcher object must respond to the #watch_it! method. It must check the watched condition and return nil or false if the condition is not met. If the condition is met, it may return true or an error message.
The Watcher may also respond to the #cleanup method - which will be used to clean up all existing Watcher on a clean shutdown.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#severity ⇒ Object
Returns the value of attribute severity.
Instance Method Summary collapse
-
#setup_actions(configuration) ⇒ Object
Sets up all actions for this watcher.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/watcher/base.rb', line 35 def name @name end |
#severity ⇒ Object
Returns the value of attribute severity.
34 35 36 |
# File 'lib/watcher/base.rb', line 34 def severity @severity end |
Instance Method Details
#setup_actions(configuration) ⇒ Object
Sets up all actions for this watcher
38 39 40 41 42 43 |
# File 'lib/watcher/base.rb', line 38 def setup_actions(configuration) action_config = configuration.get_list(:actions, false) action_config.each { |ac| add_action_to(actions, ac) } warn_config = configuration.get_list(:warn_actions, []) warn_config.each { |ac| add_action_to(warn_actions, ac) } end |