Class: Nagios::Promoo::Occi::Probes::CategoriesProbe

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

Overview

Probe for checking OCCI categories declared by endpoints.

Author:

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::Occi::Probes::BaseProbe

Class Method Details

.declarationObject



38
39
40
# File 'lib/nagios/promoo/occi/probes/categories_probe.rb', line 38

def declaration
  'categories'
end

.descriptionObject



15
16
17
# File 'lib/nagios/promoo/occi/probes/categories_probe.rb', line 15

def description
  ['categories', 'Run a probe checking for mandatory OCCI category definitions']
end

.optionsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nagios/promoo/occi/probes/categories_probe.rb', line 19

def options
  [
    [
      :optional,
      {
        type: :array, default: [],
        desc: 'Identifiers of optional categories (optional by force)'
      }
    ],
    [
      :check_location,
      {
        type: :boolean, default: false,
        desc: 'Verify declared REST locations for INFRA resources'
      }
    ]
  ]
end

.runnable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/nagios/promoo/occi/probes/categories_probe.rb', line 42

def runnable?
  true
end

Instance Method Details

#run(_args = []) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nagios/promoo/occi/probes/categories_probe.rb', line 47

def run(_args = [])
  categories = all_categories
  categories -= options[:optional] if options[:optional]

  Timeout.timeout(options[:timeout]) do
    categories.each do |cat|
      raise "#{cat.inspect} is missing" unless client.model.get_by_id(cat, true)
      next unless options[:check_location] && infra_kinds.include?(cat)

      # Make sure declared locations are actually available as REST
      # endpoints. Failure will raise an exception, no need to do
      # anything here. To keep requirements reasonable, only INFRA
      # kinds are considered relevant for this part of the check.
      begin
        client.list(cat)
      rescue => ex
        raise "Failed to verify declared REST location for #{cat.inspect} (#{ex.message})"
      end
    end
  end

  puts 'CATEGORIES OK - All specified OCCI categories were found'
rescue => ex
  puts "CATEGORIES CRITICAL - #{ex.message}"
  puts ex.backtrace if options[:debug]
  exit 2
end