nagios-promoo 0.0.6 → 0.1.0

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: 76dff93f07782caaba45b356e3aeef9861565a29
4
- data.tar.gz: 11f4809f563ca467f4d6010eb1771faf00d5f0f7
3
+ metadata.gz: 1787169d8cb255b046e890de4ff5916b6d43a548
4
+ data.tar.gz: 402a454be9941e1133c7ee3c65bbb973ab27623e
5
5
  SHA512:
6
- metadata.gz: f335f41c43a7c827935c8c5eb4a5ab6a72b4d2989d99ec84d1b2d6155180ff78456f7b0e8269958b6e3421299fad652ebb986478fa80cbb12a38ca6b1dafcc1e
7
- data.tar.gz: 0090b8d4b2f7685f451a2714d47cc430dbe6072a1d29d9a977dec8a449b615b2f8abb8a5d5ed1f969c5f9ea6b0e09c911b1ea9ac92596a50e73686a21f61cc37
6
+ metadata.gz: 4fb8f36c9fa1f65a67c4360f2f50d6bf5efc956368ac55cc96d9802b7efa9496524236bbc496df393aab30ad1fa795a7291aca3cff15e1be172d456d7274b265
7
+ data.tar.gz: 5ed803935e772f15a3ea1e4da16d96c3d960ac286dd0b5c05e706b60f0e7437f7fda00fc6341bd8d43c56e1810a8010690930dd90206c90e8f8267f936634204
data/lib/nagios/promoo.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  # Global deps
2
2
  require 'thor'
3
3
  require 'timeout'
4
+ require 'ox'
4
5
  require 'multi_xml'
5
- require 'multi_json'
6
6
  require 'httparty'
7
7
 
8
+ # Force multi_xml to use ox
9
+ MultiXml.parser = :ox
10
+
8
11
  # Define modules
9
12
  module Nagios; end
10
13
  module Nagios::Promoo; end
@@ -11,7 +11,8 @@ class Nagios::Promoo::Occi::Probes::CategoriesProbe < Nagios::Promoo::Occi::Prob
11
11
 
12
12
  def options
13
13
  [
14
- [:optional, { type: :array, default: [], desc: 'Identifiers of optional categories (optional by force)' }]
14
+ [:optional, { type: :array, default: [], desc: 'Identifiers of optional categories (optional by force)' }],
15
+ [:check_location, { type: :boolean, default: false, desc: 'Verify declared REST locations for INFRA resources' }],
15
16
  ]
16
17
  end
17
18
 
@@ -27,9 +28,22 @@ class Nagios::Promoo::Occi::Probes::CategoriesProbe < Nagios::Promoo::Occi::Prob
27
28
  categories -= options[:optional] if options[:optional]
28
29
 
29
30
  begin
30
- Timeout::timeout(options[:timeout]) {
31
- categories.each { |cat| fail "#{cat.inspect} is missing" unless client(options).model.get_by_id(cat, true) }
32
- }
31
+ Timeout::timeout(options[:timeout]) do
32
+ categories.each do |cat|
33
+ fail "#{cat.inspect} is missing" unless client(options).model.get_by_id(cat, true)
34
+ next unless options[:check_location] && Nagios::Promoo::Occi::Probes::KindsProbe::INFRA_KINDS.include?(cat)
35
+
36
+ # Make sure declared locations are actually available as REST
37
+ # endpoints. Failure will raise an exception, no need to do
38
+ # anything here. To keep requirements reasonable, only INFRA
39
+ # kinds are considered relevant for this part of the check.
40
+ begin
41
+ client(options).list(cat)
42
+ rescue => err
43
+ fail "Failed to verify declared REST location for #{cat.inspect} (#{err.message})"
44
+ end
45
+ end
46
+ end
33
47
  rescue => ex
34
48
  puts "CATEGORIES CRITICAL - #{ex.message}"
35
49
  puts ex.backtrace if options[:debug]
@@ -10,9 +10,8 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
10
10
  def options
11
11
  [
12
12
  [:mpuri, { type: :string, required: true, desc: 'AppDB MPURI referencing a virtual appliance' }],
13
+ [:with_storage, { type: :boolean, default: false, desc: 'Run test attaching a storage instance to compute instance' }],
13
14
  [:cache_expiration, { type: :numeric, default: 7200, desc: 'AppDB cache expiration (in seconds)' }],
14
- [:compute_timeout, { type: :numeric, default: 359, desc: 'Timeout for compute instantiation (in seconds)' }],
15
- [:appdb_timeout, { type: :numeric, default: 359, desc: 'Timeout for AppDB queries (in seconds)' }],
16
15
  [:cleanup, { type: :boolean, default: true, desc: 'Perform clean-up before launching a new instance' }],
17
16
  ]
18
17
  end
@@ -24,53 +23,97 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
24
23
  def runnable?; true; end
25
24
  end
26
25
 
26
+ READY_STATES = %w(active online).freeze
27
+ NONREADY_STATES = %w(inactive offline).freeze
28
+ ERROR_STATES = %w(error).freeze
29
+
27
30
  CPU_SUM_WEIGHT = 1000
28
31
  COMPUTE_NAME_PREFIX = "sam-nagios-promoo"
32
+ DEFAULT_STORAGE_SIZE = 1 # GB
29
33
  APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'
30
34
  APPDB_REQUEST_FORM = 'version=1.0&resource=broker&data=%3Cappdb%3Abroker%20xmlns%3Axs%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aappdb%3D%22http%3A%2F%2Fappdb.egi.eu%2Fapi%2F1.0%2Fappdb%22%3E%3Cappdb%3Arequest%20id%3D%22vaproviders%22%20method%3D%22GET%22%20resource%3D%22va_providers%22%3E%3Cappdb%3Aparam%20name%3D%22listmode%22%3Edetails%3C%2Fappdb%3Aparam%3E%3C%2Fappdb%3Arequest%3E%3C%2Fappdb%3Abroker%3E'
31
35
 
32
36
  def run(options, args = [])
33
- fail "Timeout (#{options[:timeout]}) must be higher than compute-timeout (#{options[:compute_timeout]}) "\
34
- "+ appdb-timeout (#{options[:appdb_timeout]})" if options[:timeout] <= (options[:compute_timeout] + options[:appdb_timeout])
35
-
36
- link = begin
37
- Timeout::timeout(options[:timeout]) { compute_create(*appdb_information(options), options) }
38
- rescue Timeout::Error => ex
39
- puts "COMPUTE CRITICAL - Probe execution timed out [#{options[:timeout]}s]"
40
- exit 2
41
- end
42
-
43
- puts "COMPUTE OK - Instance #{link.inspect} created & cleaned up"
37
+ links = begin
38
+ Timeout::timeout(options[:timeout]) { compute_provision(options) }
39
+ rescue Timeout::Error => ex
40
+ puts "COMPUTE CRITICAL - Probe execution timed out [#{options[:timeout]}s]"
41
+ exit 2
42
+ end
43
+
44
+ puts "COMPUTE OK - Instance(s) #{links[:compute].inspect} created & cleaned up"
44
45
  end
45
46
 
46
47
  private
47
48
 
48
- def compute_create(os_tpl, resource_tpl, options)
49
- link = nil
50
-
51
- begin
52
- 2.times { client(options).delete('compute') } if options[:cleanup]
53
- compute = client(options).get_resource('compute')
54
- compute.title = compute.hostname = "#{COMPUTE_NAME_PREFIX}-#{Time.now.to_i}"
55
-
56
- compute.mixins << get_mixin(os_tpl, 'os_tpl', options)
57
- compute.mixins << get_mixin(resource_tpl, 'resource_tpl', options)
58
-
59
- link = client(options).create(compute)
60
- wait4compute(link, options)
61
- rescue => ex
62
- puts "COMPUTE CRITICAL - #{ex.message}"
63
- puts ex.backtrace if options[:debug]
64
- exit 2
65
- ensure
66
- begin
67
- client(options).delete(link) unless link.blank?
68
- rescue => ex
69
- ## ignoring
70
- end
49
+ def compute_provision(options)
50
+ links = {}
51
+
52
+ compute_link = compute_create(options)
53
+ links[:compute] = compute_link
54
+ wait4ready(compute_link, options)
55
+
56
+ if options[:with_storage]
57
+ storage_link = storage_create(options)
58
+ links[:storage] = storage_link
59
+ wait4ready(storage_link, options)
60
+
61
+ slink = link_instances(compute_link, storage_link, options)
62
+ links[:storagelink] = slink
63
+ wait4ready(slink, options)
71
64
  end
72
65
 
73
- link
66
+ links
67
+ rescue => ex
68
+ puts "COMPUTE CRITICAL - #{ex.message}"
69
+ puts ex.backtrace if options[:debug]
70
+ exit 2
71
+ ensure
72
+ mandatory_cleanup links, options
73
+ end
74
+
75
+ def compute_create(options)
76
+ client(options).delete('compute') if options[:cleanup]
77
+
78
+ compute = client(options).get_resource('compute')
79
+ compute.title = compute.hostname = "#{COMPUTE_NAME_PREFIX}-#{Time.now.to_i}"
80
+
81
+ os_tpl, resource_tpl = appdb_information(options)
82
+ compute.mixins << get_mixin(os_tpl, 'os_tpl', options)
83
+ compute.mixins << get_mixin(resource_tpl, 'resource_tpl', options)
84
+
85
+ client(options).create compute
86
+ end
87
+
88
+ def storage_create(options)
89
+ client(options).delete('storage') if options[:cleanup]
90
+
91
+ storage = client(options).get_resource('storage')
92
+ storage.title = "#{COMPUTE_NAME_PREFIX}-block-#{Time.now.to_i}"
93
+ storage.size = DEFAULT_STORAGE_SIZE # GB
94
+
95
+ client(options).create storage
96
+ end
97
+
98
+ def link_instances(compute_link, storage_link, options)
99
+ slink = client(options).get_link('storagelink')
100
+ slink.source = compute_link
101
+ slink.target = storage_link
102
+
103
+ client(options).create slink
104
+ end
105
+
106
+ def mandatory_cleanup(links, options)
107
+ mandatory_cleanup_part links[:storagelink], true, options
108
+ mandatory_cleanup_part links[:storage], false, options
109
+ mandatory_cleanup_part links[:compute], false, options
110
+ end
111
+
112
+ def mandatory_cleanup_part(link, wait4inactive, options)
113
+ client(options).delete link
114
+ wait4inactive(link, options) if wait4inactive
115
+ rescue => ex
116
+ # ignore
74
117
  end
75
118
 
76
119
  def get_mixin(term, type, options)
@@ -79,35 +122,34 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
79
122
  mxn
80
123
  end
81
124
 
82
- def wait4compute(link, options)
83
- state = 'inactive'
84
-
85
- begin
86
- Timeout::timeout(options[:compute_timeout]) {
87
- while state != 'active' do
88
- state = client(options).describe(link).first.state
89
- fail 'Failed to deploy an instance (resulting OCCI state was "error")' if state == 'error'
90
- sleep 5
91
- end
92
- }
93
- rescue Timeout::Error => ex
94
- puts "COMPUTE WARNING - Execution timed out while waiting for the instance to become active [#{options[:compute_timeout]}s]"
95
- exit 1
125
+ def wait4ready(link, options)
126
+ state = nil
127
+
128
+ while !READY_STATES.include?(state) do
129
+ state = client(options).describe(link).first.state
130
+ fail "Provisioning failure on #{link.inspect}" if ERROR_STATES.include?(state)
131
+ sleep 5
96
132
  end
97
133
  end
98
134
 
99
- def appdb_information(options)
100
- begin
101
- Timeout::timeout(options[:appdb_timeout]) {
102
- [appdb_appliance(options), appdb_smallest_size(options)]
103
- }
104
- rescue => ex
105
- puts "COMPUTE UNKNOWN - #{ex.message}"
106
- puts ex.backtrace if options[:debug]
107
- exit 3
135
+ def wait4inactive(link, options)
136
+ state = nil
137
+
138
+ while !NONREADY_STATES.include?(state) do
139
+ state = client(options).describe(link).first.state
140
+ fail "De-provisioning failure on #{link.inspect}" if ERROR_STATES.include?(state)
141
+ sleep 5
108
142
  end
109
143
  end
110
144
 
145
+ def appdb_information(options)
146
+ [appdb_appliance(options), appdb_smallest_size(options)]
147
+ rescue => ex
148
+ puts "COMPUTE UNKNOWN - #{ex.message}"
149
+ puts ex.backtrace if options[:debug]
150
+ exit 3
151
+ end
152
+
111
153
  def appdb_appliance(options)
112
154
  appliance = nil
113
155
  appliance = [appdb_provider(options)['provider:image']].flatten.compact.select do |image|
@@ -138,7 +180,7 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
138
180
 
139
181
  parsed_response = cache_fetch('appdb-sites', options[:cache_expiration]) do
140
182
  response = HTTParty.post(APPDB_PROXY_URL, { :body => APPDB_REQUEST_FORM })
141
- fail "Could not get appliance"\
183
+ fail "Could not get appliance "\
142
184
  "details from AppDB [#{response.code}]" unless response.success?
143
185
  response.parsed_response
144
186
  end
@@ -10,7 +10,8 @@ class Nagios::Promoo::Occi::Probes::KindsProbe < Nagios::Promoo::Occi::Probes::B
10
10
  def options
11
11
  [
12
12
  [:kinds, { type: :string, enum: %w(core infra all), default: 'all', desc: 'Collection of mandatory kinds to check' }],
13
- [:optional, { type: :array, default: [], desc: 'Identifiers of optional kinds (optional by force)' }]
13
+ [:optional, { type: :array, default: [], desc: 'Identifiers of optional kinds (optional by force)' }],
14
+ [:check_location, { type: :boolean, default: false, desc: 'Verify declared REST locations for INFRA resources' }],
14
15
  ]
15
16
  end
16
17
 
@@ -42,9 +43,22 @@ class Nagios::Promoo::Occi::Probes::KindsProbe < Nagios::Promoo::Occi::Probes::B
42
43
  kinds -= options[:optional] if options[:optional]
43
44
 
44
45
  begin
45
- Timeout::timeout(options[:timeout]) {
46
- kinds.each { |kind| fail "#{kind.inspect} is missing" unless client(options).model.get_by_id(kind, true) }
47
- }
46
+ Timeout::timeout(options[:timeout]) do
47
+ kinds.each do |kind|
48
+ fail "#{kind.inspect} is missing" unless client(options).model.get_by_id(kind, true)
49
+ next unless options[:check_location] && INFRA_KINDS.include?(kind)
50
+
51
+ # Make sure declared locations are actually available as REST
52
+ # endpoints. Failure will raise an exception, no need to do
53
+ # anything here. To keep requirements reasonable, only INFRA
54
+ # kinds are considered relevant for this part of the check.
55
+ begin
56
+ client(options).list(kind)
57
+ rescue => err
58
+ fail "Failed to verify declared REST location for #{kind.inspect} (#{err.message})"
59
+ end
60
+ end
61
+ end
48
62
  rescue => ex
49
63
  puts "KINDS CRITICAL - #{ex.message}"
50
64
  puts ex.backtrace if options[:debug]
@@ -1,7 +1,7 @@
1
1
  module Nagios
2
2
  module Promoo
3
3
  module Occi
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module Nagios
2
2
  module Promoo
3
- VERSION = "0.0.6"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -18,14 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'occi-api', '~> 4.3'
21
+ spec.add_runtime_dependency 'occi-api', '~> 4.3', '>= 4.3.7'
22
22
  spec.add_runtime_dependency 'opennebula', '~> 4.14'
23
23
  spec.add_runtime_dependency 'thor'
24
24
  spec.add_runtime_dependency 'yell'
25
25
  spec.add_runtime_dependency 'activesupport'
26
26
  spec.add_runtime_dependency 'httparty'
27
- spec.add_runtime_dependency 'multi_xml'
28
- spec.add_runtime_dependency 'multi_json'
27
+ spec.add_runtime_dependency 'ox'
29
28
 
30
29
  spec.add_development_dependency 'bundler', '~> 1.7'
31
30
  spec.add_development_dependency 'rake', '~> 10.0'
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.6
4
+ version: 0.1.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: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2017-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: occi-api
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.3.7
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.3.7
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: opennebula
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -95,21 +101,7 @@ dependencies:
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
103
  - !ruby/object:Gem::Dependency
98
- name: multi_xml
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: multi_json
104
+ name: ox
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
107
  - - ">="