opennebula_nagios_probe 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmU0ZDE5MTZkYzUyMGVhMjNlNDJhZjU4YTA4MzQ4ZTE5YzI4ODllNQ==
5
+ data.tar.gz: !binary |-
6
+ NjM5MDdmZDUwZTE5MDBhNzBhNzc2NTNmOWZlOTUwZDI3MmQ5OWU4Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTg0NjhmMTFmMzFjMWM1OWQyZGM2ZGIxYmY5ODhiOGRkMzBiOGRlZmVmMGMx
10
+ OTRhYWU3NWMyZDJkOTQ1OTYyMmRkZWMxZWM5YTdmZmMzNGU4NWUzYmFlNWNm
11
+ YWZjYzg5MDk1OTJhZmUyMTBlYzhmMDU2Yzk3ZDg2NjVkNjFmNGM=
12
+ data.tar.gz: !binary |-
13
+ ZGVlYzkwOWUyZDQ0YTUzNmFhNTdlODk5Y2YwNDZiZTNjNDM4NjBjNGIzOGNi
14
+ N2U0NTlhODAzZjEwNTExMWJlMDJjMDhmNWY2OGFkNzZiZWFkZDBlZTM1MjBk
15
+ MTFiNjYwNzUzODVmMDI1OGY2YzQyMTBlNGRkOGNiOTY1ZDQ5Mjc=
@@ -0,0 +1,5 @@
1
+ # Project files
2
+ *.iml
3
+ .idea/
4
+ .bundle/
5
+ build/
@@ -0,0 +1,6 @@
1
+ LineLength:
2
+ Max: 120
3
+
4
+ MethodLength:
5
+ CountComments: false # count full line comments?
6
+ Max: 75
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+
7
+ branches:
8
+ only:
9
+ - master
10
+ - unstable
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ ##
2
+ source "http://rubygems.org"
3
+ ##
4
+
5
+ gem "nagios-probe"
6
+ gem "log4r"
7
+ gem "amazon-ec2"
8
+ gem "multipart-post"
9
+ gem "rake"
10
+ gem "occi-cli"
11
+ gem "opennebula-oca"
12
+ gem "occi-api", "~> 4.2"
13
+
14
+ group :test do
15
+ gem "rspec"
16
+ gem "vcr"
17
+ gem "webmock", "~>1.9.3"
18
+ end
@@ -0,0 +1,87 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.2)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ amazon-ec2 (0.9.17)
12
+ xml-simple (>= 1.0.12)
13
+ atomic (1.1.14)
14
+ crack (0.4.2)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.2.5)
17
+ hashie (2.0.5)
18
+ highline (1.6.20)
19
+ httparty (0.13.0)
20
+ json (~> 1.8)
21
+ multi_xml (>= 0.5.2)
22
+ i18n (0.6.9)
23
+ json (1.8.1)
24
+ log4r (1.1.10)
25
+ mini_portile (0.5.2)
26
+ minitest (4.7.5)
27
+ multi_json (1.8.4)
28
+ multi_xml (0.5.5)
29
+ multipart-post (2.0.0)
30
+ nagios-probe (0.1.2)
31
+ nokogiri (1.6.1)
32
+ mini_portile (~> 0.5.0)
33
+ occi-api (4.2.0)
34
+ httparty
35
+ json
36
+ occi-core (~> 4.2.10)
37
+ occi-cli (4.2.0)
38
+ highline
39
+ json
40
+ occi-api (~> 4.2.0)
41
+ occi-core (4.2.10)
42
+ activesupport (~> 4.0.0)
43
+ hashie
44
+ json
45
+ settingslogic
46
+ uuidtools (>= 2.1.3)
47
+ opennebula (4.4.0)
48
+ json
49
+ nokogiri
50
+ opennebula-oca (4.4.0)
51
+ opennebula (= 4.4.0)
52
+ rake (10.1.1)
53
+ rspec (2.14.1)
54
+ rspec-core (~> 2.14.0)
55
+ rspec-expectations (~> 2.14.0)
56
+ rspec-mocks (~> 2.14.0)
57
+ rspec-core (2.14.7)
58
+ rspec-expectations (2.14.5)
59
+ diff-lcs (>= 1.1.3, < 2.0)
60
+ rspec-mocks (2.14.5)
61
+ safe_yaml (1.0.1)
62
+ settingslogic (2.0.9)
63
+ thread_safe (0.1.3)
64
+ atomic
65
+ tzinfo (0.3.38)
66
+ uuidtools (2.1.4)
67
+ vcr (2.8.0)
68
+ webmock (1.9.3)
69
+ addressable (>= 2.2.7)
70
+ crack (>= 0.3.2)
71
+ xml-simple (1.1.3)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ amazon-ec2
78
+ log4r
79
+ multipart-post
80
+ nagios-probe
81
+ occi-api (~> 4.2)
82
+ occi-cli
83
+ opennebula-oca
84
+ rake
85
+ rspec
86
+ vcr
87
+ webmock (~> 1.9.3)
@@ -0,0 +1,36 @@
1
+ Nagios probes for OpenNebula v3.4 - v4.4
2
+ ========================================
3
+
4
+ [![Build Status](https://travis-ci.org/b3rserker/opennebula-nagios-probes.png?branch=unstable)](https://travis-ci.org/b3rserker/opennebula-nagios-probes)
5
+
6
+ Nagios probes for OpenNebula-related services e.g. oned RPC2, econe-server, occi-server and rOCCI server (GWDG implementation)
7
+
8
+ These probes are written in Ruby, Gemfile for bundler is included.
9
+
10
+ ## Requirements
11
+ 1.9.1 =< Ruby version =< 2.0.0
12
+
13
+ ## Usage
14
+
15
+ ~~~
16
+ ./check_opennebula.rb --username <USERNAME> --password <PASSWORD> --hostname <HOSTNAME> --port <PORT_NUMBER> --path /RPC2 --service oned
17
+ ./check_opennebula.rb --username <USERNAME> --password <PASSWORD> --hostname <HOSTNAME> --port <PORT_NUMBER> --service occi
18
+ ./check_opennebula.rb --username <USERNAME> --password <PASSWORD> --hostname <HOSTNAME> --port <PORT_NUMBER> --service rocci
19
+ ./check_opennebula.rb --username <USERNAME> --password <PASSWORD> --hostname <HOSTNAME> --port <PORT_NUMBER> --service econe
20
+ ~~~
21
+
22
+ and with optional
23
+
24
+ * `--timeout` (this option is, for now, ignored by OCCI and ECONE probes)
25
+ * `--protocol [https | http]`
26
+ * `--debug [number, 0-2]`
27
+ * `--check-network <ID>,<ID>,<ID>,...` (this option is ignored by the ECONE probe)
28
+ * `--check-storage <ID>,<ID>,<ID>,...` (not supported within rOCCI implementation)
29
+ * `--check-compute <ID>,<ID>,<ID>,...`
30
+
31
+ additional options for rOCCI and advanced features (X.509, VOMS, VM instantiation)
32
+ ~~~
33
+ ./check_opennebula.rb --cred <USER_PEM_BUNDLE_OR_PK12> --capath <CA_PATH> --cafile <OR_CA_BUNDLE> --password <PASSWORD> --hostname <HOSTNAME> --port <PORT_NUMBER> --service rocci --voms
34
+ ~~~
35
+
36
+ * `--createvm [ROCCI_TEMPLATE_NAME]` `--name [vmname]` (create, check and destroy VM specified by os_tpl#rocci_template_name or full_mixin_path)
@@ -0,0 +1,65 @@
1
+ require 'erb'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default target, runs probe:test'
6
+ task :default => 'probe:test'
7
+
8
+ namespace :probe do
9
+
10
+ directory 'build/check_opennebula'
11
+ RSpec::Core::RakeTask.new(:rspec)
12
+
13
+ desc 'Check for required dependencies'
14
+ task :dependencies do
15
+ puts 'Checking for required dependencies...'
16
+
17
+ `bundle check`
18
+ end
19
+
20
+ desc 'Run basic tests'
21
+ task :test do
22
+ puts 'Running basic tests...'
23
+
24
+ Rake::Task['probe:rspec'].invoke
25
+ end
26
+
27
+ desc 'Install the opennebula probe'
28
+ task :install => ['build/check_opennebula', 'probe:dependencies', 'probe:test'] do
29
+ puts 'Installing the opennebula probe...'
30
+
31
+ services = [:oned, :occi, :econe]
32
+ protocols = [:http, :https]
33
+
34
+ nagios_command_path = ENV['NAGIOS_COMMAND_PATH'] || '/etc/nagios-plugins/config'
35
+ nagios_plugin_path = ENV['NAGIOS_PLUGIN_PATH'] || '/usr/lib/nagios/plugins'
36
+ ruby_command_path = ENV['RUBY_COMMAND_PATH'] || ''
37
+
38
+ cfg = ERB.new File.new('conf/opennebula.cfg.erb').read
39
+
40
+ File.open('build/opennebula.cfg', 'w') {|file| file.write(cfg.result(binding)) }
41
+
42
+ cp_r 'lib', 'build/check_opennebula'
43
+ cp 'check_opennebula.rb', 'build/check_opennebula'
44
+
45
+ end
46
+
47
+ desc 'Uninstall the opennebula probe'
48
+ task :uninstall do
49
+ puts 'Uninstalling the opennebula probe...'
50
+
51
+ nagios_command_path = ENV['NAGIOS_COMMAND_PATH'] || '/etc/nagios-plugins/config'
52
+ nagios_plugin_path = ENV['NAGIOS_PLUGIN_PATH'] || '/usr/lib/nagios/plugins'
53
+
54
+ rm_rf "#{nagios_plugin_path}/check_opennebula"
55
+ rm "#{nagios_command_path}/opennebula.cfg"
56
+ end
57
+
58
+ desc 'Remove temporary files and directories created during installation process'
59
+ task :clean do
60
+ puts 'Removing temporary files and directories...'
61
+
62
+ rm_rf 'build'
63
+ end
64
+
65
+ end
@@ -0,0 +1,70 @@
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
+ # bundler integration and dependencies
19
+ require 'bundler/setup'
20
+ require 'log4r'
21
+
22
+ require File.expand_path('..', __FILE__) +'/../lib/opennebula_nagios_probe'
23
+
24
+ begin
25
+ # parse the arguments (type checks, required args etc.)
26
+ options = OptparseNagiosProbe.parse(ARGV)
27
+
28
+ # instantiate a probe
29
+ case options.service
30
+ when :oned
31
+ probe = OpenNebulaOnedProbe.new(options)
32
+ logger = Log4r::Logger.new 'OpenNebulaOnedProbe'
33
+ when :occi, :rocci
34
+ probe = OpenNebulaOcciProbe.new(options)
35
+ logger = Log4r::Logger.new 'OpenNebulaOcciProbe'
36
+ when :econe
37
+ probe = OpenNebulaEconeProbe.new(options)
38
+ logger = Log4r::Logger.new 'OpenNebulaEconeProbe'
39
+ end
40
+
41
+ # set the logger
42
+ logger.outputters = Log4r::Outputter.stderr
43
+ probe.logger = logger
44
+
45
+ case options.debug_level
46
+ when 0
47
+ logger.level = Log4r::FATAL
48
+ when 1
49
+ logger.level = Log4r::ERROR
50
+ when 2
51
+ logger.level = Log4r::DEBUG
52
+ else
53
+ logger.level = Log4r::FATAL
54
+ end
55
+
56
+ # run the probe
57
+ probe.run
58
+
59
+ # report the result in a nagios-compatible format
60
+ logger.info probe.message
61
+ logger.info "Probe returned: #{probe.retval.to_s}"
62
+ exit probe.retval
63
+
64
+ # catch all StandardErrors raised by parser or probes and treat them as a UKNOWN probe state too
65
+ rescue StandardError => e
66
+ logger.info "Fatal exception occured: #{e.message}"
67
+ logger.debug e.backtrace
68
+ logger.info UNKNOWN
69
+ exit UNKNOWN
70
+ end
@@ -0,0 +1,32 @@
1
+ #######################################################################################################################
2
+ ## Default path for Nagios3 command definitions is:
3
+ ## /etc/nagios-plugins/config
4
+ ## installed in:
5
+ ## <%= nagios_command_path %>
6
+ ##
7
+ ## Default path for Nagios3 plugins is:
8
+ ## /usr/lib/nagios/plugins
9
+ ## installed in:
10
+ ## <%= nagios_plugin_path %>
11
+ ##
12
+ ## Default path to Ruby is:
13
+ ## "" (i.e. empty, Ruby is provided by "/usr/bin/env ruby")
14
+ ## installed with:
15
+ ## <%= ruby_command_path %>
16
+ #######################################################################################################################
17
+
18
+ <% protocols.each do |protocol| %>
19
+ <% services.each do |service| %>
20
+ # 'check_opennebula_<%= service.to_s %>_<%= protocol.to_s %>_basic' command definition
21
+ define command{
22
+ command_name check_opennebula_<%= service.to_s %>_<%= protocol.to_s %>_basic
23
+ command_line <%= ruby_command_path %> <%= nagios_plugin_path %>/check_opennebula/check_opennebula.rb --service <%= service.to_s %> --protocol <%= protocol.to_s %> --hostname '$HOSTNAME$' --port '$ARG1$' --path '$ARG2$' --username '$ARG3$' --password '$ARG4$'
24
+ }
25
+
26
+ # 'check_opennebula_<%= service.to_s %>_<%= protocol.to_s %>_resources' command definition
27
+ define command{
28
+ command_name check_opennebula_<%= service.to_s %>_<%= protocol.to_s %>_resources
29
+ command_line <%= ruby_command_path %> <%= nagios_plugin_path %>/check_opennebula/check_opennebula.rb --service <%= service.to_s %> --protocol <%= protocol.to_s %> --hostname '$HOSTNAME$' --port '$ARG1$' --path '$ARG2$' --username '$ARG3$' --password '$ARG4$' --check-network '$ARG5$' --check-storage '$ARG6$' --check-compute '$ARG7$'
30
+ }
31
+ <% end %>
32
+ <% end %>
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ ###########################################################################
3
+ ## Licensed under the Apache License, Version 2.0 (the "License");
4
+ ## you may not use this file except in compliance with the License.
5
+ ## You may obtain a copy of the License at
6
+ ##
7
+ ## http://www.apache.org/licenses/LICENSE-2.0
8
+ ##
9
+ ## Unless required by applicable law or agreed to in writing, software
10
+ ## distributed under the License is distributed on an "AS IS" BASIS,
11
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ ## See the License for the specific language governing permissions and
13
+ ## limitations under the License.
14
+ ###########################################################################
15
+
16
+ # OpenNebulaProbe - this file serves only as proxy for development and including purposes.
17
+
18
+ # translate special symbols into readable ones
19
+ require 'English'
20
+
21
+ # include the probe files and a custom version of OCA
22
+ $LOAD_PATH << File.expand_path('..', __FILE__) + '/probe'
23
+
24
+ # include the probe classes and a custom argument parser
25
+ require 'opennebula_probe'
26
+ require 'optparse_nagios_probe'
27
+ require 'opennebula_oned_probe'
28
+ require 'opennebula_occi_probe'
29
+ require 'opennebula_econe_probe'
@@ -0,0 +1,50 @@
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__)
19
+ %w(nocci/resource nocci/network nocci/storage nocci/compute).each { |r| require r }
20
+ %w(rocci/resource rocci/network rocci/storage rocci/compute).each { |r| require r }
21
+
22
+ # OCCI Client class.
23
+ # ==== Options
24
+ # * options - Hash with provided command line arguments.
25
+
26
+ class OcciClient
27
+ def initialize(options)
28
+ @connection = options
29
+
30
+ # Select OCCI version
31
+ if options[:occi].to_s == 'rocci'
32
+ @occi_ver = 'Rocci'
33
+ else
34
+ @occi_ver = 'Occi'
35
+ end
36
+ end
37
+
38
+ # Dynamically selects the proper class
39
+ def network
40
+ @network ||= eval("#{@occi_ver}::Network.new @connection")
41
+ end
42
+
43
+ def storage
44
+ @storage ||= eval("#{@occi_ver}::Storage.new @connection")
45
+ end
46
+
47
+ def compute
48
+ @compute ||= eval("#{@occi_ver}::Compute.new @connection")
49
+ end
50
+ end
@@ -0,0 +1,20 @@
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
+ module Occi
18
+ class Compute < Resource
19
+ end
20
+ end