class Nagios::Promoo::Occi::Probes::CategoriesProbe

Probe for checking OCCI categories declared by endpoints.

@author Boris Parak <parak@cesnet.cz>

Public Class Methods

declaration() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 38
def declaration
  'categories'
end
description() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 15
def description
  ['categories', 'Run a probe checking for mandatory OCCI category definitions']
end
options() click to toggle source
# 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?() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 42
def runnable?
  true
end

Public Instance Methods

run(_args = []) click to toggle source
# 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

Private Instance Methods

all_categories() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 93
def all_categories
  %i[core_kinds infra_kinds infra_mixins context_mixins].reduce([]) do |memo, elm|
    memo.concat send(elm)
  end
end
context_mixins() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 89
def context_mixins
  Nagios::Promoo::Occi::Probes::MixinsProbe::CONTEXT_MIXINS
end
core_kinds() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 77
def core_kinds
  Nagios::Promoo::Occi::Probes::KindsProbe::CORE_KINDS
end
infra_kinds() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 81
def infra_kinds
  Nagios::Promoo::Occi::Probes::KindsProbe::INFRA_KINDS
end
infra_mixins() click to toggle source
# File lib/nagios/promoo/occi/probes/categories_probe.rb, line 85
def infra_mixins
  Nagios::Promoo::Occi::Probes::MixinsProbe::INFRA_MIXINS
end