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.
@@ -1,31 +1,44 @@
1
1
  # Internal deps
2
2
  require File.join(File.dirname(__FILE__), 'base_probe')
3
3
 
4
- class Nagios::Promoo::Opennebula::Probes::XmlrpcHealthProbe < Nagios::Promoo::Opennebula::Probes::BaseProbe
5
- class << self
6
- def description
7
- ['xmlrpc-health', 'Run a probe checking OpenNebula\'s XML RPC service']
8
- end
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
- def options
11
- []
12
- end
17
+ def options
18
+ []
19
+ end
13
20
 
14
- def declaration
15
- "xmlrpc_health"
16
- end
21
+ def declaration
22
+ 'xmlrpc_health'
23
+ end
17
24
 
18
- def runnable?; true; end
19
- end
25
+ def runnable?
26
+ true
27
+ end
28
+ end
20
29
 
21
- def run(args = [])
22
- rc = Timeout::timeout(options[:timeout]) { client.get_version }
23
- fail rc.message if OpenNebula.is_error?(rc)
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
- puts "XMLRPC OK - OpenNebula #{rc} daemon is up and running"
26
- rescue => ex
27
- puts "XMLRPC CRITICAL - #{ex.message}"
28
- puts ex.backtrace if options[:debug]
29
- exit 2
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
@@ -1,7 +1,7 @@
1
1
  module Nagios
2
2
  module Promoo
3
3
  module Opennebula
4
- VERSION = "1.0.0"
4
+ VERSION = '1.0.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,31 +1,53 @@
1
- module Nagios::Promoo::Utils
2
- module Cache
3
- CACHE_DIR = '/tmp/nagios-promoo_cache'
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
- def cache_fetch(key, expiration = 3600)
6
- fail 'You have to provide a block!' unless block_given?
7
- FileUtils.mkdir_p CACHE_DIR
8
- filename = File.join(CACHE_DIR, key)
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
- if cache_valid?(filename, expiration)
11
- File.open(filename, 'r') { |file|
12
- file.flock(File::LOCK_SH)
13
- JSON.parse file.read
14
- }
15
- else
16
- data = yield
17
- File.open(filename, File::RDWR|File::CREAT, 0644) { |file|
18
- file.flock(File::LOCK_EX)
19
- file.write JSON.pretty_generate(data)
20
- file.flush
21
- file.truncate(file.pos)
22
- } unless data.blank?
23
- data
24
- end
25
- end
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
- def cache_valid?(filename, expiration)
28
- File.exists?(filename) && !File.zero?(filename) && ((Time.now - expiration) < File.stat(filename).mtime)
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
@@ -1,5 +1,5 @@
1
1
  module Nagios
2
2
  module Promoo
3
- VERSION = "1.1.0"
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
@@ -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 = %q{Nagios Probes for Monitoring OpenNebula and OCCI}
12
- spec.description = %q{Nagios Probes for Monitoring OpenNebula and OCCI}
13
- spec.homepage = 'https://github.com/EGI-FCTF/nagios-promoo'
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 = '>= 1.9.3'
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.1.0
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-03-30 00:00:00.000000000 Z
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/vmcatcher_probe.rb
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/EGI-FCTF/nagios-promoo
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: 1.9.3
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.8
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