opennebula_nagios_probe 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +6 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +18 -0
  6. data/Gemfile.lock +87 -0
  7. data/README.md +36 -0
  8. data/Rakefile +65 -0
  9. data/bin/check_opennebula +70 -0
  10. data/conf/opennebula.cfg.erb +32 -0
  11. data/lib/opennebula_nagios_probe.rb +29 -0
  12. data/lib/probe/occi/client.rb +50 -0
  13. data/lib/probe/occi/nocci/compute.rb +20 -0
  14. data/lib/probe/occi/nocci/network.rb +21 -0
  15. data/lib/probe/occi/nocci/resource.rb +96 -0
  16. data/lib/probe/occi/nocci/storage.rb +22 -0
  17. data/lib/probe/occi/rocci/compute.rb +70 -0
  18. data/lib/probe/occi/rocci/network.rb +21 -0
  19. data/lib/probe/occi/rocci/resource.rb +62 -0
  20. data/lib/probe/occi/rocci/storage.rb +22 -0
  21. data/lib/probe/opennebula_econe_probe.rb +108 -0
  22. data/lib/probe/opennebula_occi_probe.rb +126 -0
  23. data/lib/probe/opennebula_oned_probe.rb +101 -0
  24. data/lib/probe/opennebula_probe.rb +97 -0
  25. data/lib/probe/optparse_nagios_probe.rb +174 -0
  26. data/opennebula_nagios_probe.gemspec +32 -0
  27. data/spec/probe/fixtures/cassettes/econe/econe_critical_existing_resources.yml +75 -0
  28. data/spec/probe/fixtures/cassettes/econe/econe_critical_no_resources.yml +75 -0
  29. data/spec/probe/fixtures/cassettes/econe/econe_critical_nonexisting_resources.yml +75 -0
  30. data/spec/probe/fixtures/cassettes/econe/econe_warning_existing_resources.yml +75 -0
  31. data/spec/probe/fixtures/cassettes/econe/econe_warning_nonexisting_resources.yml +40 -0
  32. data/spec/probe/fixtures/cassettes/occi/occi_critical_existing_resources.yml +143 -0
  33. data/spec/probe/fixtures/cassettes/occi/occi_critical_no_resources.yml +143 -0
  34. data/spec/probe/fixtures/cassettes/occi/occi_critical_nonexisting_resources.yml +143 -0
  35. data/spec/probe/fixtures/cassettes/occi/occi_warning_existing_resources.yml +230 -0
  36. data/spec/probe/fixtures/cassettes/occi/occi_warning_nonexisting_resources.yml +49 -0
  37. data/spec/probe/fixtures/cassettes/oned/oned_critical_existing_resources.yml +131 -0
  38. data/spec/probe/fixtures/cassettes/oned/oned_critical_no_resources.yml +131 -0
  39. data/spec/probe/fixtures/cassettes/oned/oned_critical_nonexisting_resources.yml +131 -0
  40. data/spec/probe/fixtures/cassettes/oned/oned_warning_existing_resources.yml +671 -0
  41. data/spec/probe/fixtures/cassettes/oned/oned_warning_nonexisting_resources.yml +130 -0
  42. data/spec/probe/fixtures/cassettes/rocci/rocci_critical_existing_resources.yml +1220 -0
  43. data/spec/probe/fixtures/cassettes/rocci/rocci_critical_no_resources.yml +1220 -0
  44. data/spec/probe/fixtures/cassettes/rocci/rocci_critical_nonexisting_resources.yml +1220 -0
  45. data/spec/probe/fixtures/cassettes/rocci/rocci_warning_existing_resources.yml +817 -0
  46. data/spec/probe/fixtures/cassettes/rocci/rocci_warning_no_resources.yml +591 -0
  47. data/spec/probe/fixtures/cassettes/rocci/rocci_warning_nonexisting_resources.yml +640 -0
  48. data/spec/probe/opennebula_econe_probe_spec.rb +150 -0
  49. data/spec/probe/opennebula_occi_probe_spec.rb +149 -0
  50. data/spec/probe/opennebula_oned_probe_spec.rb +154 -0
  51. data/spec/probe/opennebula_rocci_probe_spec.rb +156 -0
  52. metadata +280 -0
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ ###########################################################################
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ###########################################################################
17
+
18
+ $LOAD_PATH << File.expand_path('..', __FILE__) + '/../../lib/probe'
19
+
20
+ require 'bundler/setup'
21
+ require 'vcr'
22
+ require 'webmock'
23
+ require 'nagios-probe'
24
+ require 'AWS'
25
+ require 'log4r'
26
+ require 'ostruct'
27
+
28
+ require 'opennebula_econe_probe'
29
+
30
+ RSpec::Core::DSL.describe OpenNebulaEconeProbe do
31
+ before do
32
+ WebMock.disable_net_connect! allow: 'localhost'
33
+
34
+ VCR.configure do |c|
35
+ c.cassette_library_dir = 'spec/probe/fixtures/cassettes/econe'
36
+ c.hook_into :webmock
37
+ c.allow_http_connections_when_no_cassette = true
38
+ end
39
+
40
+ @options = OpenStruct.new
41
+
42
+ @options.protocol = :https
43
+ @options.hostname = 'localhost'
44
+ @options.port = 2345
45
+ @options.path = '/'
46
+ @options.username = 'nagios-probes-test'
47
+ # @options.password = '1b5834c03b1a9fda89b38c081a6d99af634b046e'
48
+ @options.password = 'nagios-probes-pass'
49
+
50
+ @logger = Log4r::Logger.new 'EconeTestLogger'
51
+ @logger.outputters = Log4r::Outputter.stderr
52
+ # @logger.level = Log4r::DEBUG
53
+ @logger.level = Log4r::INFO
54
+ end
55
+
56
+ context 'with no resources' do
57
+ before :each do
58
+ @probe = OpenNebulaEconeProbe.new(@options)
59
+ @probe.logger = @logger
60
+ end
61
+
62
+ it 'checks basic connectivity with cassette' do
63
+ VCR.use_cassette('econe_critical_no_resources') do
64
+ @probe.check_crit.should be_false
65
+ end
66
+ end
67
+
68
+ # without a cassette the probe should report critical state
69
+ it 'checks basic connectivity without cassette' do
70
+ @probe.check_crit.should be_true
71
+ end
72
+
73
+ it 'checks for resource availability with cassette' do
74
+ VCR.use_cassette('econe_warning_no_resources') do
75
+ @probe.check_warn.should be_false
76
+ end
77
+ end
78
+
79
+ # without a cassette the probe should report warning state
80
+ it 'checks for resource availability without cassette' do
81
+ @probe.check_warn.should be_false
82
+ end
83
+ end
84
+
85
+ context 'with resources' do
86
+ before :each do
87
+ # resources should not have an effect on check_crit results
88
+ @options.storage = %w(ami-00000006 ami-00000007)
89
+ @options.compute = %w(11)
90
+
91
+ @probe = OpenNebulaEconeProbe.new(@options)
92
+ @probe.logger = @logger
93
+ end
94
+
95
+ it 'checks basic connectivity with cassette' do
96
+ VCR.use_cassette('econe_critical_existing_resources') do
97
+ @probe.check_crit.should be_false
98
+ end
99
+ end
100
+
101
+ # without a cassette the probe should report critical state
102
+ it 'checks basic connectivity without cassette' do
103
+ @probe.check_crit.should be_true
104
+ end
105
+
106
+ it 'checks for resource availability with cassette' do
107
+ VCR.use_cassette('econe_warning_existing_resources') do
108
+ @probe.check_warn.should be_false
109
+ end
110
+ end
111
+
112
+ # without a cassette the probe should report warning state
113
+ it 'checks for resource availability without cassette' do
114
+ @probe.check_warn.should be_true
115
+ end
116
+ end
117
+
118
+ context 'with nonexisting resources' do
119
+ before :each do
120
+ # resources should not have an effect on check_crit results
121
+ @options.storage = %w(ami-00000126 ami-00000127)
122
+ @options.compute = %w(22)
123
+
124
+ @probe = OpenNebulaEconeProbe.new(@options)
125
+ @probe.logger = @logger
126
+ end
127
+
128
+ it 'checks basic connectivity with cassette' do
129
+ VCR.use_cassette('econe_critical_nonexisting_resources') do
130
+ @probe.check_crit.should be_false
131
+ end
132
+ end
133
+
134
+ # without a cassette the probe should report critical state
135
+ it 'checks basic connectivity without cassette' do
136
+ @probe.check_crit.should be_true
137
+ end
138
+
139
+ it 'checks for resource availability with cassette' do
140
+ VCR.use_cassette('econe_warning_nonexisting_resources') do
141
+ @probe.check_warn.should be_true
142
+ end
143
+ end
144
+
145
+ # without a cassette the probe should report warning state
146
+ it 'checks for resource availability without cassette' do
147
+ @probe.check_warn.should be_true
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ ###########################################################################
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ###########################################################################
17
+
18
+ $LOAD_PATH << File.expand_path('..', __FILE__) + '/../../lib/probe'
19
+
20
+ require 'bundler/setup'
21
+ require 'vcr'
22
+ require 'webmock'
23
+ require 'log4r'
24
+ require 'ostruct'
25
+
26
+ require 'opennebula_occi_probe'
27
+
28
+ RSpec::Core::DSL.describe OpenNebulaOcciProbe do
29
+ before do
30
+ WebMock.disable_net_connect! allow: 'localhost'
31
+
32
+ VCR.configure do |c|
33
+ c.cassette_library_dir = 'spec/probe/fixtures/cassettes/occi'
34
+ c.hook_into :webmock
35
+ c.allow_http_connections_when_no_cassette = true
36
+ end
37
+
38
+ @options = OpenStruct.new
39
+
40
+ @options.protocol = :https
41
+ @options.hostname = 'localhost'
42
+ @options.port = 2345
43
+ @options.path = '/'
44
+ @options.username = 'nagios-probes-test'
45
+ @options.password = 'nagios-probes-pass'
46
+
47
+ @logger = Log4r::Logger.new 'OcciTestLogger'
48
+ @logger.outputters = Log4r::Outputter.stderr
49
+ # @logger.level = Log4r::DEBUG
50
+ @logger.level = Log4r::INFO
51
+ end
52
+
53
+ context 'with no resources' do
54
+ before :each do
55
+ @probe = OpenNebulaOcciProbe.new(@options)
56
+ @probe.logger = @logger
57
+ end
58
+
59
+ it 'checks basic connectivity with cassette' do
60
+ VCR.use_cassette('occi_critical_no_resources') do
61
+ @probe.check_crit.should be_false
62
+ end
63
+ end
64
+
65
+ # without a cassette the probe should report critical state
66
+ it 'checks basic connectivity without cassette' do
67
+ @probe.check_crit.should be_true
68
+ end
69
+
70
+ it 'checks for resource availability with cassette' do
71
+ VCR.use_cassette('occi_warning_no_resources') do
72
+ @probe.check_warn.should be_false
73
+ end
74
+ end
75
+
76
+ # without a cassette the probe should report warning state
77
+ it 'checks for resource availability without cassette' do
78
+ @probe.check_warn.should be_false
79
+ end
80
+ end
81
+
82
+ context 'with resources' do
83
+ before :each do
84
+ # resources should not have an effect on check_crit results
85
+ @options.network = %w(3 4)
86
+ @options.storage = %w(6 7)
87
+ @options.compute = %w(11)
88
+
89
+ @probe = OpenNebulaOcciProbe.new(@options)
90
+ @probe.logger = @logger
91
+ end
92
+
93
+ it 'checks basic connectivity with cassette' do
94
+ VCR.use_cassette('occi_critical_existing_resources') do
95
+ @probe.check_crit.should be_false
96
+ end
97
+ end
98
+
99
+ # without a cassette the probe should report critical state
100
+ it 'checks basic connectivity without cassette' do
101
+ @probe.check_crit.should be_true
102
+ end
103
+
104
+ it 'checks for resource availability with cassette' do
105
+ VCR.use_cassette('occi_warning_existing_resources') do
106
+ @probe.check_warn.should be_false
107
+ end
108
+ end
109
+
110
+ # without a cassette the probe should report warning state
111
+ it 'checks for resource availability without cassette' do
112
+ @probe.check_warn.should be_true
113
+ end
114
+ end
115
+
116
+ context 'with nonexisting resources' do
117
+ before :each do
118
+ # resources should not have an effect on check_crit results
119
+ @options.network = %w(16 17)
120
+ @options.storage = %w(126 127)
121
+ @options.compute = %w(22)
122
+
123
+ @probe = OpenNebulaOcciProbe.new(@options)
124
+ @probe.logger = @logger
125
+ end
126
+
127
+ it 'checks basic connectivity with cassette' do
128
+ VCR.use_cassette('occi_critical_nonexisting_resources') do
129
+ @probe.check_crit.should be_false
130
+ end
131
+ end
132
+
133
+ # without a cassette the probe should report critical state
134
+ it 'checks basic connectivity without cassette' do
135
+ @probe.check_crit.should be_true
136
+ end
137
+
138
+ it 'checks for resource availability with cassette' do
139
+ VCR.use_cassette('occi_warning_nonexisting_resources') do
140
+ @probe.check_warn.should be_true
141
+ end
142
+ end
143
+
144
+ # without a cassette the probe should report warning state
145
+ it 'checks for resource availability without cassette' do
146
+ @probe.check_warn.should be_true
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ ###########################################################################
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ###########################################################################
17
+
18
+ $LOAD_PATH << File.expand_path('..', __FILE__) + '/../../lib/probe'
19
+
20
+ require 'bundler/setup'
21
+ require 'vcr'
22
+ require 'webmock'
23
+ require 'log4r'
24
+ require 'ostruct'
25
+ require 'opennebula'
26
+
27
+ require 'opennebula_oned_probe'
28
+
29
+ RSpec::Core::DSL.describe OpenNebulaOnedProbe do
30
+ before do
31
+ WebMock.disable_net_connect! allow: 'localhost'
32
+
33
+ VCR.configure do |c|
34
+ c.cassette_library_dir = 'spec/probe/fixtures/cassettes/oned'
35
+ c.hook_into :webmock
36
+ # Do not fail if VCR cannot handle request, act as there was not any
37
+ c.allow_http_connections_when_no_cassette = true
38
+ end
39
+
40
+ @options = OpenStruct.new
41
+
42
+ @options.protocol = :https
43
+ @options.hostname = 'localhost'
44
+ @options.port = 2345
45
+ @options.path = '/RPC2'
46
+ @options.username = 'nagios-probes-test'
47
+ @options.password = 'nagios-probes-pass'
48
+
49
+ # Adjust for debug purposes
50
+ @options.debug = false
51
+
52
+ @logger = Log4r::Logger.new 'OnedTestLogger'
53
+ @logger.outputters = Log4r::Outputter.stderr
54
+ # @logger.level = Log4r::DEBUG
55
+ @logger.level = Log4r::INFO
56
+ end
57
+
58
+ context 'with no resources' do
59
+ before :each do
60
+ @probe = OpenNebulaOnedProbe.new(@options)
61
+ @probe.logger = @logger
62
+ end
63
+
64
+ it 'checks basic connectivity with cassette' do
65
+ VCR.use_cassette('oned_critical_no_resources') do
66
+ @probe.check_crit.should be_false
67
+ end
68
+ end
69
+
70
+ # without a cassette the probe should report critical state
71
+ it 'checks basic connectivity without cassette' do
72
+ @probe.check_crit.should be_true
73
+ end
74
+
75
+ it 'checks for resource availability with cassette' do
76
+ VCR.use_cassette('oned_warning_no_resources') do
77
+ @probe.check_warn.should be_false
78
+ end
79
+ end
80
+
81
+ # without a cassette the probe should report warning state
82
+ it 'checks for resource availability without cassette' do
83
+ @probe.check_warn.should be_false
84
+ end
85
+ end
86
+
87
+ context 'with resources' do
88
+ before :each do
89
+ # resources should not have an effect on check_crit results
90
+ @options.network = %w(3 4)
91
+ @options.storage = %w(6 7)
92
+ @options.compute = %w(11)
93
+
94
+ @probe = OpenNebulaOnedProbe.new(@options)
95
+ @probe.logger = @logger
96
+ end
97
+
98
+ it 'checks basic connectivity with cassette' do
99
+ VCR.use_cassette('oned_critical_existing_resources') do
100
+ @probe.check_crit.should be_false
101
+ end
102
+ end
103
+
104
+ # without a cassette the probe should report critical state
105
+ it 'checks basic connectivity without cassette' do
106
+ @probe.check_crit.should be_true
107
+ end
108
+
109
+ it 'checks for resource availability with cassette' do
110
+ VCR.use_cassette('oned_warning_existing_resources') do
111
+ @probe.check_warn.should be_false
112
+ end
113
+ end
114
+
115
+ # without a cassette the probe should report warning state
116
+ it 'checks for resource availability without cassette' do
117
+ @probe.check_warn.should be_true
118
+ end
119
+ end
120
+
121
+ context 'with nonexisting resources' do
122
+ before :each do
123
+ # resources should not have an effect on check_crit results
124
+ @options.network = %w(16 17)
125
+ @options.storage = %w(126 127)
126
+ @options.compute = %w(22)
127
+
128
+ @probe = OpenNebulaOnedProbe.new(@options)
129
+ @probe.logger = @logger
130
+ end
131
+
132
+ it 'checks basic connectivity with cassette' do
133
+ VCR.use_cassette('oned_critical_nonexisting_resources') do
134
+ @probe.check_crit.should be_false
135
+ end
136
+ end
137
+
138
+ # without a cassette the probe should report critical state
139
+ it 'checks basic connectivity without cassette' do
140
+ @probe.check_crit.should be_true
141
+ end
142
+
143
+ it 'checks for resource availability with cassette' do
144
+ VCR.use_cassette('oned_warning_nonexisting_resources') do
145
+ @probe.check_warn.should be_true
146
+ end
147
+ end
148
+
149
+ # without a cassette the probe should report warning state
150
+ it 'checks for resource availability without cassette' do
151
+ @probe.check_warn.should be_true
152
+ end
153
+ end
154
+ end