Class: Metis::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/metis/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, context) ⇒ Provider

Returns a new instance of Provider.



5
6
7
8
9
# File 'lib/metis/provider.rb', line 5

def initialize(definition, context)
  @definition = definition
  @context = context
  @response_code = Metis::STATUS_OK
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



3
4
5
# File 'lib/metis/provider.rb', line 3

def definition
  @definition
end

#response_codeObject (readonly)

Returns the value of attribute response_code.



3
4
5
# File 'lib/metis/provider.rb', line 3

def response_code
  @response_code
end

#response_messageObject (readonly)

Returns the value of attribute response_message.



3
4
5
# File 'lib/metis/provider.rb', line 3

def response_message
  @response_message
end

Instance Method Details

#critical(msg) ⇒ Object



22
23
24
25
26
27
# File 'lib/metis/provider.rb', line 22

def critical(msg)
  unless @response_code > Metis::STATUS_CRITICAL
    @response_code = Metis::STATUS_CRITICAL
    @response_message = msg
  end
end

#ok(msg = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/metis/provider.rb', line 29

def ok(msg=nil)
  unless @response_code > Metis::STATUS_OK
    @response_code = Metis::STATUS_OK
    @response_message = msg
  end
end

#paramsObject



11
12
13
# File 'lib/metis/provider.rb', line 11

def params
  definition.params
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/metis/provider.rb', line 36

def run
  Timeout.timeout @context.configuration.timeout do
    result = self.instance_eval(&definition.execute) if prepare
  ok(result) if result.is_a?(String)
  end

# catch a tmeout here... sometimes it can be raised here rather than in Client
# want it caught here rather than the more general one so the message returned here
# and from Client is ensured to be the same
rescue Timeout::Error => e
  critical("The check timed out")

rescue Exception => e
  critical("Exception raised: #{e.message}")
end

#warn(msg) ⇒ Object



15
16
17
18
19
20
# File 'lib/metis/provider.rb', line 15

def warn(msg)
  unless @response_code > Metis::STATUS_WARNING
    @response_code = Metis::STATUS_WARNING
    @response_message = msg
  end
end