Module: Watcher

Defined in:
lib/watcher.rb,
lib/watcher/base.rb,
lib/watcher/log_watcher.rb,
lib/watcher/http_watcher.rb

Overview

Handling for the Watcher objects in the system. The Watcher are not access directly, but handled through the static methods of this module. The module will also keep track of the watcher state and wrap the invocation procedure.

Defined Under Namespace

Classes: Base, HttpWatcher, LogWatcher

Constant Summary collapse

@@watch_runs =

Number of times the Watcher were called

0

Class Method Summary collapse

Class Method Details

.cleanup_watchersObject

Cleans up all Watcher



39
40
41
# File 'lib/watcher.rb', line 39

def cleanup_watchers
  registered_watchers.each { |w| w.cleanup if(w.respond_to?(:cleanup)) }
end

.register(name, config_options) ⇒ Object

Create a new watcher with the given configuration. The type identifies the watcher class that should be used.

This will not return the watcher object, as it is not to be used externally. The watcher will be registered internally, and called when the #watch_all! method is called

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/watcher.rb', line 16

def register(name, config_options)
  assit_kind_of(String, name)
  raise(ArgumentError, "Illegal options") unless(config_options.is_a?(Hash))
  type = config_options.get_value(:type, false)
  type = WatchDogger.camelize(type)
  watcher =  Watcher.const_get(type).new(config_options)
  watcher.setup_actions(config_options)
  severity = config_options.get_value(:severity, 100).to_i
  watcher.severity = severity
  watcher.name = name
  registered_watchers << watcher
  dog_log.debug('Watcher') { "Registered Watcher of type #{type}" }
end

.watch_all!Object

This will execute all registered Watcher, which, in turn, will execute their actions if necessary. Normally, this will run all Watcher each time this method is called. However, the watcher may implement conditions on which the check is skipped.



33
34
35
36
# File 'lib/watcher.rb', line 33

def watch_all!
  @last_check = Time.now
  registered_watchers.each { |w| w.send(:do_watch!) }
end