nagios-promoo 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +27 -0
- data/README.md +8 -4
- data/Rakefile +6 -1
- data/lib/nagios/promoo.rb +12 -6
- data/lib/nagios/promoo/appdb/master.rb +52 -25
- data/lib/nagios/promoo/appdb/probes/appliances_probe.rb +50 -37
- data/lib/nagios/promoo/appdb/probes/base_probe.rb +60 -40
- data/lib/nagios/promoo/appdb/probes/sizes_probe.rb +50 -37
- data/lib/nagios/promoo/appdb/probes/sync_probe.rb +179 -0
- data/lib/nagios/promoo/appdb/version.rb +1 -1
- data/lib/nagios/promoo/master.rb +37 -19
- data/lib/nagios/promoo/occi/master.rb +58 -27
- data/lib/nagios/promoo/occi/probes/base_probe.rb +37 -24
- data/lib/nagios/promoo/occi/probes/categories_probe.rb +88 -46
- data/lib/nagios/promoo/occi/probes/compute_probe.rb +249 -202
- data/lib/nagios/promoo/occi/probes/kinds_probe.rb +83 -52
- data/lib/nagios/promoo/occi/probes/mixins_probe.rb +62 -37
- data/lib/nagios/promoo/occi/version.rb +1 -1
- data/lib/nagios/promoo/opennebula/master.rb +55 -26
- data/lib/nagios/promoo/opennebula/probes/base_probe.rb +35 -12
- data/lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb +138 -100
- data/lib/nagios/promoo/opennebula/probes/xmlrpc_health_probe.rb +34 -21
- data/lib/nagios/promoo/opennebula/version.rb +1 -1
- data/lib/nagios/promoo/utils.rb +47 -25
- data/lib/nagios/promoo/version.rb +1 -1
- data/nagios-promoo.gemspec +5 -4
- metadata +9 -6
- data/lib/nagios/promoo/appdb/probes/vmcatcher_probe.rb +0 -118
@@ -1,31 +1,44 @@
|
|
1
1
|
# Internal deps
|
2
2
|
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Nagios
|
5
|
+
module Promoo
|
6
|
+
module Opennebula
|
7
|
+
module Probes
|
8
|
+
# Probe for checking ONe XML RPC2 health.
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
class XmlrpcHealthProbe < Nagios::Promoo::Opennebula::Probes::BaseProbe
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
['xmlrpc-health', 'Run a probe checking OpenNebula\'s XML RPC service']
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
17
|
+
def options
|
18
|
+
[]
|
19
|
+
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
def declaration
|
22
|
+
'xmlrpc_health'
|
23
|
+
end
|
17
24
|
|
18
|
-
|
19
|
-
|
25
|
+
def runnable?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
def run(_args = [])
|
31
|
+
rc = Timeout.timeout(options[:timeout]) { client.get_version }
|
32
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
puts "XMLRPC OK - OpenNebula #{rc} daemon is up and running"
|
35
|
+
rescue => ex
|
36
|
+
puts "XMLRPC CRITICAL - #{ex.message}"
|
37
|
+
puts ex.backtrace if options[:debug]
|
38
|
+
exit 2
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
30
43
|
end
|
31
44
|
end
|
data/lib/nagios/promoo/utils.rb
CHANGED
@@ -1,31 +1,53 @@
|
|
1
|
-
module Nagios
|
2
|
-
module
|
3
|
-
|
1
|
+
module Nagios
|
2
|
+
module Promoo
|
3
|
+
# Namespace for helpers and aux utilities.
|
4
|
+
#
|
5
|
+
# @author Boris Parak <parak@cesnet.cz>
|
6
|
+
module Utils
|
7
|
+
# Caching helpers for arbitrary use.
|
8
|
+
#
|
9
|
+
# @author Boris Parak <parak@cesnet.cz>
|
10
|
+
module Cache
|
11
|
+
CACHE_DIR = '/tmp/nagios-promoo_cache'.freeze
|
4
12
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
13
|
+
def cache_fetch(key, expiration = 3600)
|
14
|
+
raise 'You have to provide a block!' unless block_given?
|
15
|
+
FileUtils.mkdir_p CACHE_DIR
|
16
|
+
filename = File.join(CACHE_DIR, key)
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
if cache_valid?(filename, expiration)
|
19
|
+
read_cache filename
|
20
|
+
else
|
21
|
+
write_cache filename, yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_cache(filename)
|
26
|
+
File.open(filename, 'r') do |file|
|
27
|
+
file.flock(File::LOCK_SH)
|
28
|
+
JSON.parse file.read
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def write_cache(filename, data)
|
33
|
+
return data if data.blank?
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
File.open(filename, File::RDWR | File::CREAT, 0o644) do |file|
|
36
|
+
file.flock(File::LOCK_EX)
|
37
|
+
file.write JSON.fast_generate(data)
|
38
|
+
file.flush
|
39
|
+
file.truncate(file.pos)
|
40
|
+
end
|
41
|
+
|
42
|
+
data
|
43
|
+
end
|
44
|
+
|
45
|
+
def cache_valid?(filename, expiration)
|
46
|
+
File.exist?(filename) \
|
47
|
+
&& !File.zero?(filename) \
|
48
|
+
&& ((Time.now - expiration) < File.stat(filename).mtime)
|
49
|
+
end
|
50
|
+
end
|
29
51
|
end
|
30
52
|
end
|
31
53
|
end
|
data/nagios-promoo.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'nagios/promoo/version'
|
@@ -8,9 +9,9 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = Nagios::Promoo::VERSION
|
9
10
|
spec.authors = ['Boris Parak']
|
10
11
|
spec.email = ['parak@cesnet.cz']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage = 'https://github.com/
|
12
|
+
spec.summary = 'Nagios Probes for Monitoring OpenNebula and OCCI'
|
13
|
+
spec.description = 'Nagios Probes for Monitoring OpenNebula and OCCI'
|
14
|
+
spec.homepage = 'https://github.com/arax/nagios-promoo'
|
14
15
|
spec.license = 'Apache License, Version 2.0'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -34,5 +35,5 @@ Gem::Specification.new do |spec|
|
|
34
35
|
spec.add_development_dependency 'rubocop', '>= 0.47', '< 1'
|
35
36
|
spec.add_development_dependency 'pry', '>= 0.10', '< 1'
|
36
37
|
|
37
|
-
spec.required_ruby_version = '>=
|
38
|
+
spec.required_ruby_version = '>= 2.2.0'
|
38
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios-promoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Parak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: occi-api
|
@@ -299,6 +299,9 @@ extensions: []
|
|
299
299
|
extra_rdoc_files: []
|
300
300
|
files:
|
301
301
|
- ".gitignore"
|
302
|
+
- ".rubocop.yml"
|
303
|
+
- ".rubocop_todo.yml"
|
304
|
+
- ".travis.yml"
|
302
305
|
- Gemfile
|
303
306
|
- LICENSE.txt
|
304
307
|
- README.md
|
@@ -311,7 +314,7 @@ files:
|
|
311
314
|
- lib/nagios/promoo/appdb/probes/appliances_probe.rb
|
312
315
|
- lib/nagios/promoo/appdb/probes/base_probe.rb
|
313
316
|
- lib/nagios/promoo/appdb/probes/sizes_probe.rb
|
314
|
-
- lib/nagios/promoo/appdb/probes/
|
317
|
+
- lib/nagios/promoo/appdb/probes/sync_probe.rb
|
315
318
|
- lib/nagios/promoo/appdb/version.rb
|
316
319
|
- lib/nagios/promoo/master.rb
|
317
320
|
- lib/nagios/promoo/occi/.keep
|
@@ -334,7 +337,7 @@ files:
|
|
334
337
|
- lib/nagios/promoo/version.rb
|
335
338
|
- nagios-promoo.gemspec
|
336
339
|
- test/.keep
|
337
|
-
homepage: https://github.com/
|
340
|
+
homepage: https://github.com/arax/nagios-promoo
|
338
341
|
licenses:
|
339
342
|
- Apache License, Version 2.0
|
340
343
|
metadata: {}
|
@@ -346,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
346
349
|
requirements:
|
347
350
|
- - ">="
|
348
351
|
- !ruby/object:Gem::Version
|
349
|
-
version:
|
352
|
+
version: 2.2.0
|
350
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
354
|
requirements:
|
352
355
|
- - ">="
|
@@ -354,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
357
|
version: '0'
|
355
358
|
requirements: []
|
356
359
|
rubyforge_project:
|
357
|
-
rubygems_version: 2.6.
|
360
|
+
rubygems_version: 2.6.10
|
358
361
|
signing_key:
|
359
362
|
specification_version: 4
|
360
363
|
summary: Nagios Probes for Monitoring OpenNebula and OCCI
|
@@ -1,118 +0,0 @@
|
|
1
|
-
# Internal deps
|
2
|
-
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
|
-
|
4
|
-
class Nagios::Promoo::Appdb::Probes::VmcatcherProbe < Nagios::Promoo::Appdb::Probes::BaseProbe
|
5
|
-
class << self
|
6
|
-
def description
|
7
|
-
['vmcatcher', 'Run a probe checking consistency between a vmcatcher image list and available appliances (via AppDB)']
|
8
|
-
end
|
9
|
-
|
10
|
-
def options
|
11
|
-
[
|
12
|
-
[:vo, { type: :string, required: true, desc: 'Virtual Organization name (used to select the appropriate VO-wide image list)' }],
|
13
|
-
[:token, { type: :string, required: true, desc: 'AppDB authentication token (used to access the VO-wide image list)' }],
|
14
|
-
[:warning_after, { type: :numeric, default: 24, desc: 'A number of hours after list publication when missing or outdated appliances raise WARNING' }],
|
15
|
-
[:critical_after, { type: :numeric, default: 72, desc: 'A number of hours after list publication when missing or outdated appliances raise CRITICAL' }],
|
16
|
-
]
|
17
|
-
end
|
18
|
-
|
19
|
-
def declaration
|
20
|
-
"vmcatcher"
|
21
|
-
end
|
22
|
-
|
23
|
-
def runnable?; true; end
|
24
|
-
end
|
25
|
-
|
26
|
-
IMAGE_LIST_TEMPLATE = "https://$$TOKEN$$:x-oauth-basic@vmcaster.appdb.egi.eu/store/vo/$$VO$$/image.list"
|
27
|
-
IMAGE_LIST_BOUNDARY_REGEXP = /boundary="(?<prefix>-+)(?<id>[[:alnum:]]+)"/
|
28
|
-
|
29
|
-
def run(args = [])
|
30
|
-
@_results = { found: [], outdated: [], missing: [], expected: [] }
|
31
|
-
|
32
|
-
Timeout::timeout(options[:timeout]) { check_vmc_sync }
|
33
|
-
|
34
|
-
wrong = @_results[:missing] + @_results[:outdated]
|
35
|
-
if wrong.any?
|
36
|
-
if (@_last_update + options[:critical_after].hours) < Time.now
|
37
|
-
puts "VMCATCHER CRITICAL - Appliance(s) #{wrong.inspect} missing " \
|
38
|
-
"or outdated in #{options[:vo].inspect} " \
|
39
|
-
"more than #{options[:critical_after]} hours after list publication [#{@_last_update}]"
|
40
|
-
exit 2
|
41
|
-
end
|
42
|
-
|
43
|
-
if (@_last_update + options[:warning_after].hours) < Time.now
|
44
|
-
puts "VMCATCHER WARNING - Appliance(s) #{wrong.inspect} missing " \
|
45
|
-
"or outdated in #{options[:vo].inspect} " \
|
46
|
-
"more than #{options[:warning_after]} hours after list publication [#{@_last_update}]"
|
47
|
-
exit 1
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
puts "VMCATCHER OK - All appliances registered in #{options[:vo].inspect} " \
|
52
|
-
"are available [#{@_results[:expected].count}]"
|
53
|
-
rescue => ex
|
54
|
-
puts "VMCATCHER UNKNOWN - #{ex.message}"
|
55
|
-
puts ex.backtrace if options[:debug]
|
56
|
-
exit 3
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def check_vmc_sync
|
62
|
-
vo_list.each do |hv_image|
|
63
|
-
mpuri_versionless = versionless_mpuri(hv_image['ad:mpuri'])
|
64
|
-
@_results[:expected] << mpuri_versionless
|
65
|
-
|
66
|
-
matching = provider_appliances.select { |appl| appl['mp_uri'] == mpuri_versionless }.first
|
67
|
-
|
68
|
-
unless matching
|
69
|
-
@_results[:missing] << mpuri_versionless
|
70
|
-
next
|
71
|
-
end
|
72
|
-
|
73
|
-
@_results[:outdated] << mpuri_versionless if hv_image['hv:version'] != matching['vmiversion']
|
74
|
-
@_results[:found] << mpuri_versionless
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def provider_appliances
|
79
|
-
return @_appliances if @_appliances
|
80
|
-
|
81
|
-
@_appliances = [appdb_provider['provider:image']].flatten.compact
|
82
|
-
@_appliances.keep_if { |appliance| appliance['voname'] == options[:vo] }
|
83
|
-
@_appliances.reject { |appliance| appliance['mp_uri'].blank? }
|
84
|
-
|
85
|
-
@_appliances.each do |appliance|
|
86
|
-
appliance['mp_uri'] = versionless_mpuri(appliance['mp_uri'])
|
87
|
-
end
|
88
|
-
|
89
|
-
@_appliances
|
90
|
-
end
|
91
|
-
|
92
|
-
def vo_list
|
93
|
-
return @_hv_images if @_hv_images
|
94
|
-
|
95
|
-
list_url = IMAGE_LIST_TEMPLATE.gsub('$$TOKEN$$', options[:token]).gsub('$$VO$$', options[:vo])
|
96
|
-
response = HTTParty.get list_url
|
97
|
-
fail "Could not get a VO-wide image list" \
|
98
|
-
"from #{list_url.inspect} [#{response.code}]" unless response.success?
|
99
|
-
|
100
|
-
list = JSON.parse OpenSSL::PKCS7.read_smime(response.parsed_response).data
|
101
|
-
fail "AppDB image list #{list_url.inspect} is empty or malformed" unless list && list['hv:imagelist']
|
102
|
-
|
103
|
-
list = list['hv:imagelist']
|
104
|
-
fail "AppDB image list #{list_url.inspect} has expired" unless DateTime.parse(list['dc:date:expires']) > Time.now
|
105
|
-
fail "AppDB image list #{list_url.inspect} doesn't contain images" unless list['hv:images']
|
106
|
-
|
107
|
-
@_last_update = DateTime.parse list['dc:date:created']
|
108
|
-
@_hv_images = list['hv:images'].collect { |im| im['hv:image'] }.reject { |im| im.blank? || im['ad:mpuri'].blank? }
|
109
|
-
end
|
110
|
-
|
111
|
-
def normalize_mpuri(mpuri)
|
112
|
-
mpuri.gsub(/\/+$/, '')
|
113
|
-
end
|
114
|
-
|
115
|
-
def versionless_mpuri(mpuri)
|
116
|
-
normalize_mpuri(mpuri).gsub(/:\d+$/, '')
|
117
|
-
end
|
118
|
-
end
|