Class: Hive::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/hive/diagnostic.rb

Defined Under Namespace

Classes: InvalidParameterError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options) ⇒ Diagnostic

Returns a new instance of Diagnostic.



13
14
15
16
17
18
# File 'lib/hive/diagnostic.rb', line 13

def initialize(config, options)
  @options = options
  @config = config
  @serial = @options['serial']
  @device_api = @options['device_api']
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/hive/diagnostic.rb', line 11

def config
  @config
end

#device_apiObject (readonly)

Returns the value of attribute device_api.



11
12
13
# File 'lib/hive/diagnostic.rb', line 11

def device_api
  @device_api
end

#last_runObject

Returns the value of attribute last_run.



10
11
12
# File 'lib/hive/diagnostic.rb', line 10

def last_run
  @last_run
end

Instance Method Details

#fail(message = {}, data = {}) ⇒ Object



49
50
51
52
# File 'lib/hive/diagnostic.rb', line 49

def fail(message ={}, data = {})
  Hive.logger.info(message)
  Hive::Results.new("fail", message, data)
end

#pass(message = {}, data = {}) ⇒ Object



44
45
46
47
# File 'lib/hive/diagnostic.rb', line 44

def pass(message= {}, data = {})
  Hive.logger.info(message)
  Hive::Results.new("pass", message, data )
end

#runObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hive/diagnostic.rb', line 32

def run
  Hive.logger.info("Trying to run diagnostic '#{self.class}'")
  if should_run?  
    result = diagnose 
    result = repair(result) if result.failed?
    @last_run = result
  else
    Hive.logger.info("Diagnostic '#{self.class}' last ran less than five minutes before")
  end
  @last_run 
end

#should_run?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hive/diagnostic.rb', line 20

def should_run?
  return true if @last_run == nil
  time_now = Time.new.getutc
  last_run_time = @last_run.timestamp
  diff = ((time_now - last_run_time)/300).round
  if (diff > 2 && @last_run.passed?) || diff > 1
    true
  else
    false
  end
end