nagios-promoo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c9c0d84676ca0268f352455386703693237e9bd
4
- data.tar.gz: e56d04432bdb5f8e7eea7bfa91da6f49ad3c53d2
3
+ metadata.gz: 2f7f2c421b78082e85f93d8b87f0a462098d0529
4
+ data.tar.gz: 7e9a8dfbdbae3725060df61d23a102d16371b799
5
5
  SHA512:
6
- metadata.gz: b2c0abddc58be459ae25ea1ba3fcb4812c8fc1837e21d7cd0df57c9c90eb270b979f33fd47e89d8db35c08fdd70e07d4d12871b0f6b43be39e6d46a22a3149a6
7
- data.tar.gz: 6b5b6174aab67c6777b92b703458a6162abc487f375d695cce208b77ed3847d300cde90c95a6d690e190b72e0e7dfb1e90a65e26ef378dd6272aa9dc11dfa45f
6
+ metadata.gz: cd841214286f739bf7f3acfab1c45507d0b59897e6f13889640be748a80dc3df8657b7b08e36d38fd38158c76f53145dad2baa0535e5ce4eb82139027ad446fa
7
+ data.tar.gz: f355d7bd0cbeae0643d7133b31f19843b2ebd12585896593906a125d56e5d5ce6eeb762812a24bf1f194c9a7f3b25145d2e3ddbc0acb52c8e0aae07fbf048da0
@@ -35,6 +35,6 @@ class Nagios::Promoo::Appdb::Probes::AppliancesProbe < Nagios::Promoo::Appdb::Pr
35
35
  private
36
36
 
37
37
  def check_appliances(options)
38
- (appdb_provider(options)['image'] || []).count
38
+ [appdb_provider(options)['image']].flatten.compact.count
39
39
  end
40
40
  end
@@ -35,6 +35,6 @@ class Nagios::Promoo::Appdb::Probes::SizesProbe < Nagios::Promoo::Appdb::Probes:
35
35
  private
36
36
 
37
37
  def check_sizes(options)
38
- (appdb_provider(options)['template'] || []).count
38
+ [appdb_provider(options)['template']].flatten.compact.count
39
39
  end
40
40
  end
@@ -0,0 +1,123 @@
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
+ [:missing_critical, { type: :numeric, default: 2, desc: 'Number of missing appliances to be considered CRITICAL' }],
15
+ [:outdated_critical, { type: :numeric, default: 5, desc: 'Number of outdated appliances to be considered 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(options, args = [])
30
+ results = begin
31
+ Timeout::timeout(options[:timeout]) { check_vmc_sync(options) }
32
+ rescue => ex
33
+ puts "VMCATCHER CRITICAL - #{ex.message}"
34
+ puts ex.backtrace if options[:debug]
35
+ exit 2
36
+ end
37
+
38
+ if results[:missing].count >= options[:missing_critical]
39
+ puts "VMCATCHER CRITICAL - #{results[:missing].count} appliance(s) in #{options[:vo].inspect} missing"
40
+ exit 2
41
+ end
42
+
43
+ ## TODO: checking for outdated appliances is not working yet
44
+ ##
45
+ # if results[:outdated].count >= options[:outdated_critical]
46
+ # puts "VMCATCHER CRITICAL - #{results[:outdated].count} appliance(s) in #{options[:vo].inspect} outdated"
47
+ # exit 2
48
+ # end
49
+ #
50
+ # if results[:outdated].count > 0
51
+ # puts "VMCATCHER WARNING - #{results[:outdated].count} appliances in #{options[:vo].inspect} outdated"
52
+ # exit 1
53
+ # end
54
+
55
+ puts "VMCATCHER OK - All appliances registered in #{options[:vo].inspect} are available [#{results[:expected].count}]"
56
+ end
57
+
58
+ private
59
+
60
+ def check_vmc_sync(options)
61
+ results = { found: [], outdated: [], missing: [], expected: [] }
62
+
63
+ vo_list(options).each do |mpuri|
64
+ mpuri_versionless = versionless_mpuri(mpuri)
65
+ mpuri_normalized = normalize_mpuri(mpuri)
66
+ results[:expected] << mpuri_versionless
67
+
68
+ if normalized_appliances(options).include?(mpuri_normalized)
69
+ results[:found] << mpuri_normalized
70
+ elsif versionless_appliances(options).include?(mpuri_versionless)
71
+ results[:found] << mpuri_versionless
72
+ results[:outdated] << mpuri_versionless
73
+ else
74
+ results[:missing] << mpuri_versionless
75
+ end
76
+ end
77
+
78
+ results
79
+ end
80
+
81
+ def provider_appliances(options)
82
+ images = [appdb_provider(options)['image']].flatten.compact
83
+ images.collect { |image| image['mp_uri'] }.reject { |mpuri| mpuri.blank? }
84
+ end
85
+
86
+ def normalized_appliances(options)
87
+ provider_appliances(options).collect { |mpuri| normalize_mpuri(mpuri) }
88
+ end
89
+
90
+ def versionless_appliances(options)
91
+ provider_appliances(options).collect { |mpuri| versionless_mpuri(mpuri) }
92
+ end
93
+
94
+ def vo_list(options)
95
+ return @mpuris if @mpuris
96
+
97
+ list = nil
98
+ begin
99
+ list_url = IMAGE_LIST_TEMPLATE.gsub('$$TOKEN$$', options[:token]).gsub('$$VO$$', options[:vo])
100
+ response = HTTParty.get(list_url)
101
+ fail "Could not get a VO-wide image list" \
102
+ "from #{list_url.inspect} [#{response.code}]" unless response.success?
103
+
104
+ list = JSON.parse(OpenSSL::PKCS7.read_smime(response.parsed_response).data) # TODO: validate the signature?
105
+ fail "AppDB image list #{list_url.inspect} does " \
106
+ "not contain images" unless list && list['hv:imagelist'] && list['hv:imagelist']['hv:images']
107
+ rescue => ex
108
+ puts "VMCATCHER UNKNOWN - #{ex.message}"
109
+ puts ex.backtrace if options[:debug]
110
+ exit 3
111
+ end
112
+
113
+ @mpuris = list['hv:imagelist']['hv:images'].collect { |im| im['hv:image']['ad:mpuri'] }.reject { |uri| uri.blank? }
114
+ end
115
+
116
+ def normalize_mpuri(mpuri)
117
+ mpuri.gsub(/\/+$/, '')
118
+ end
119
+
120
+ def versionless_mpuri(mpuri)
121
+ normalize_mpuri(mpuri).gsub(/:\d+$/, '')
122
+ end
123
+ end
@@ -110,9 +110,9 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
110
110
 
111
111
  def appdb_appliance(options)
112
112
  appliance = nil
113
- appliance = appdb_provider(options)['image'].select do |image|
113
+ appliance = [appdb_provider(options)['image']].flatten.compact.select do |image|
114
114
  image['mp_uri'] && (normalize_mpuri(image['mp_uri']) == normalize_mpuri(options[:mpuri]))
115
- end.first if appdb_provider(options)['image']
115
+ end.first
116
116
  fail "Site does not have an appliance with MPURI "\
117
117
  "#{normalize_mpuri(options[:mpuri]).inspect} published in AppDB" if appliance.blank?
118
118
 
@@ -121,12 +121,12 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
121
121
 
122
122
  def appdb_smallest_size(options)
123
123
  sizes = []
124
- appdb_provider(options)['template'].each do |template|
124
+ [appdb_provider(options)['template']].flatten.compact.each do |template|
125
125
  sizes << [
126
126
  template['resource_name'].split('#').last,
127
127
  template['main_memory_size'].to_i + (template['physical_cpus'].to_i * CPU_SUM_WEIGHT)
128
128
  ]
129
- end if appdb_provider(options)['template']
129
+ end
130
130
  fail "No appliance sizes available in AppDB" if sizes.blank?
131
131
  sizes.sort! { |x,y| x.last <=> y.last }
132
132
 
@@ -1,5 +1,5 @@
1
1
  module Nagios
2
2
  module Promoo
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  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: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-06 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: occi-api
@@ -241,6 +241,7 @@ files:
241
241
  - lib/nagios/promoo/appdb/probes/appliances_probe.rb
242
242
  - lib/nagios/promoo/appdb/probes/base_probe.rb
243
243
  - lib/nagios/promoo/appdb/probes/sizes_probe.rb
244
+ - lib/nagios/promoo/appdb/probes/vmcatcher_probe.rb
244
245
  - lib/nagios/promoo/appdb/version.rb
245
246
  - lib/nagios/promoo/master.rb
246
247
  - lib/nagios/promoo/occi/.keep