Class: Nagios::Promoo::Opennebula::Probes::VirtualMachineProbe

Inherits:
BaseProbe
  • Object
show all
Defined in:
lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb

Overview

Probe for checking VM instantiation via ONe RPC2.

Author:

Constant Summary collapse

VM_NAME_PREFIX =
'nagios-promoo'.freeze

Instance Attribute Summary

Attributes inherited from BaseProbe

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProbe

#client, #initialize

Constructor Details

This class inherits a constructor from Nagios::Promoo::Opennebula::Probes::BaseProbe

Class Method Details

.declarationObject



43
44
45
# File 'lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb', line 43

def declaration
  'virtual_machine'
end

.descriptionObject



13
14
15
# File 'lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb', line 13

def description
  ['virtual-machine', 'Run a probe instantiating a test instance in OpenNebula']
end

.optionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb', line 17

def options
  [
    [
      :template,
      {
        type: :string, default: 'monitoring',
        desc: 'Name referencing a template used for monitoring purposes'
      }
    ],
    [
      :vm_timeout,
      {
        type: :numeric, default: 180,
        desc: 'Timeout for VM instantiation (in seconds)'
      }
    ],
    [
      :cleanup,
      {
        type: :boolean, default: true,
        desc: 'Perform clean-up before launching a new instance'
      }
    ]
  ]
end

.runnable?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb', line 47

def runnable?
  true
end

Instance Method Details

#run(_args = []) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb', line 54

def run(_args = [])
  if options[:timeout] <= options[:vm_timeout]
    raise "Timeout (#{options[:timeout]}) must be higher than "\
         "vm-timeout (#{options[:vm_timeout]}) "
  end

  @_virtual_machine = nil

  Timeout.timeout(options[:timeout]) do
    cleanup if options[:cleanup]
    create
    wait4running
  end

  puts "VirtualMachine OK - Instance #{@_virtual_machine.id.inspect} of template "\
       "#{options[:template].inspect} successfully created & cleaned up"
rescue => ex
  puts "VirtualMachine CRITICAL - #{ex.message}"
  puts ex.backtrace if options[:debug]
  exit 2
ensure
  begin
    cleanup @_virtual_machine unless @_virtual_machine.blank?
  rescue => ex
    puts "VirtualMachine CRITICAL - #{ex.message}"
    puts ex.backtrace if options[:debug]
    exit 2
  end
end