Class: DogWatch::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/dogwatch/monitor.rb

Overview

Provides a container around each monitor block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, &block) ⇒ DogWatch::Model::Monitor

Parameters:

  • name (String) (defaults to: nil)
  • block (Proc)


16
17
18
19
20
21
# File 'lib/dogwatch/monitor.rb', line 16

def initialize(name = nil, &block)
  @name = name
  @monitors = []
  @config = nil
  instance_exec(&block)
end

Instance Attribute Details

#client(client = nil) ⇒ DogWatch::Model::Client (readonly)



45
46
47
# File 'lib/dogwatch/monitor.rb', line 45

def client
  @client
end

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/dogwatch/monitor.rb', line 11

def config
  @config
end

#responsesObject (readonly)

Returns the value of attribute responses.



10
11
12
# File 'lib/dogwatch/monitor.rb', line 10

def responses
  @responses
end

Instance Method Details

#getArray

Returns:

  • (Array)


33
34
35
36
37
38
39
40
41
42
# File 'lib/dogwatch/monitor.rb', line 33

def get
  @responses = @monitors.map do |m|
    validate = @client.validate(m)
    if validate.status == :error
      validate
    else
      @client.execute(m)
    end
  end
end

#monitor(name, &block) ⇒ Array

Parameters:

  • name (String)
  • block (Proc)

Returns:

  • (Array)


26
27
28
29
30
# File 'lib/dogwatch/monitor.rb', line 26

def monitor(name, &block)
  monitor = DogWatch::Model::Monitor.new(name)
  monitor.instance_eval(&block)
  @monitors << monitor
end