Class: Nagios::Promoo::Appdb::Probes::SyncProbe

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

Overview

Probe for checking appliance synchronization between sites and AppDB.

Author:

Constant Summary collapse

IMAGE_LIST_TEMPLATE =
'https://$$TOKEN$$:[email protected]' \
'/store/vo/$$VO$$/image.list'.freeze

Constants inherited from BaseProbe

BaseProbe::APPDB_IS_URL, BaseProbe::DEFAULT_HEADERS, BaseProbe::GQL_APPLIANCES_BY_ENDPOINT, BaseProbe::GQL_SIZES_BY_ENDPOINT

Instance Attribute Summary

Attributes inherited from BaseProbe

#endpoint, #options, #vo

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProbe

#appliances_by_endpoint, #initialize, #sizes_by_endpoint

Constructor Details

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

Class Method Details

.declarationObject



58
59
60
# File 'lib/nagios/promoo/appdb/probes/sync_probe.rb', line 58

def declaration
  'sync'
end

.descriptionObject



13
14
15
16
17
18
19
# File 'lib/nagios/promoo/appdb/probes/sync_probe.rb', line 13

def description
  [
    'sync',
    'Run a probe checking consistency between a published VO-wide ' \
    'image list and appliances available at the site (via AppDB)'
  ]
end

.optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nagios/promoo/appdb/probes/sync_probe.rb', line 21

def options
  [
    [
      :vo,
      {
        type: :string,
        required: true,
        desc: 'Virtual Organization name (used to select the appropriate VO-wide image list)'
      }
    ],
    [
      :token,
      {
        type: :string,
        required: true,
        desc: 'AppDB authentication token (used to access the VO-wide image list)'
      }
    ],
    [
      :warning_after,
      {
        type: :numeric,
        default: 24,
        desc: 'A number of hours after list publication when missing or outdated appliances raise WARNING'
      }
    ],
    [
      :critical_after,
      {
        type: :numeric,
        default: 72,
        desc: 'A number of hours after list publication when missing or outdated appliances raise CRITICAL'
      }
    ]
  ]
end

.runnable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/nagios/promoo/appdb/probes/sync_probe.rb', line 62

def runnable?
  true
end

Instance Method Details

#run(_args = []) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/nagios/promoo/appdb/probes/sync_probe.rb', line 70

def run(_args = [])
  @_results = { found: [], outdated: [], missing: [], expected: [] }

  Timeout.timeout(options[:timeout]) { check_vmc_sync }

  wrong = @_results[:missing] + @_results[:outdated]
  if wrong.any?
    if (@_last_update + options[:critical_after].hours) < Time.now
      puts "SYNC CRITICAL - Appliance(s) #{wrong.inspect} missing " \
           "or outdated in #{vo.inspect} " \
           "more than #{options[:critical_after]} hours after list publication [#{@_last_update}]"
      exit 2
    end

    if (@_last_update + options[:warning_after].hours) < Time.now
      puts "SYNC WARNING - Appliance(s) #{wrong.inspect} missing " \
           "or outdated in #{vo.inspect} " \
           "more than #{options[:warning_after]} hours after list publication [#{@_last_update}]"
      exit 1
    end
  end

  puts "SYNC OK - All appliances registered in #{vo.inspect} " \
       "are available [#{@_results[:expected].count}]"
rescue => ex
  puts "SYNC UNKNOWN - #{ex.message}"
  puts ex.backtrace if options[:debug]
  exit 3
end