nagios-promoo 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/nagios/promoo.rb +1 -0
- data/lib/nagios/promoo/appdb/.keep +0 -0
- data/lib/nagios/promoo/appdb/master.rb +40 -0
- data/lib/nagios/promoo/appdb/probes/.keep +0 -0
- data/lib/nagios/promoo/appdb/probes/appliances_probe.rb +40 -0
- data/lib/nagios/promoo/appdb/probes/base_probe.rb +23 -0
- data/lib/nagios/promoo/appdb/probes/sizes_probe.rb +40 -0
- data/lib/nagios/promoo/appdb/version.rb +7 -0
- data/lib/nagios/promoo/master.rb +3 -0
- data/lib/nagios/promoo/occi/probes/compute_probe.rb +3 -20
- data/lib/nagios/promoo/utils.rb +31 -0
- data/lib/nagios/promoo/version.rb +1 -1
- data/test/.keep +0 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c9c0d84676ca0268f352455386703693237e9bd
|
4
|
+
data.tar.gz: e56d04432bdb5f8e7eea7bfa91da6f49ad3c53d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c0abddc58be459ae25ea1ba3fcb4812c8fc1837e21d7cd0df57c9c90eb270b979f33fd47e89d8db35c08fdd70e07d4d12871b0f6b43be39e6d46a22a3149a6
|
7
|
+
data.tar.gz: 6b5b6174aab67c6777b92b703458a6162abc487f375d695cce208b77ed3847d300cde90c95a6d690e190b72e0e7dfb1e90a65e26ef378dd6272aa9dc11dfa45f
|
data/lib/nagios/promoo.rb
CHANGED
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Internal deps
|
2
|
+
require File.join(File.dirname(__FILE__), 'version')
|
3
|
+
|
4
|
+
# Define modules
|
5
|
+
module Nagios::Promoo::Appdb; end
|
6
|
+
module Nagios::Promoo::Appdb::Probes; end
|
7
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'probes', '*.rb')) { |probe| require probe.chomp('.rb') }
|
8
|
+
|
9
|
+
class Nagios::Promoo::Appdb::Master < ::Thor
|
10
|
+
class << self
|
11
|
+
# Hack to override the help message produced by Thor.
|
12
|
+
# https://github.com/wycats/thor/issues/261#issuecomment-16880836
|
13
|
+
def banner(command, namespace = nil, subcommand = nil)
|
14
|
+
"#{basename} appdb #{command.usage}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def available_probes
|
18
|
+
Nagios::Promoo::Appdb::Probes.constants.collect { |probe| Nagios::Promoo::Appdb::Probes.const_get(probe) }.reject { |probe| !probe.runnable? }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class_option :endpoint, type: :string, desc: 'Site\'s OCCI endpoint, as specified in GOCDB', default: 'http://localhost:3000/'
|
23
|
+
|
24
|
+
available_probes.each do |probe|
|
25
|
+
desc *probe.description
|
26
|
+
probe.options.each do |opt|
|
27
|
+
option opt.first, opt.last
|
28
|
+
end
|
29
|
+
class_eval %Q^
|
30
|
+
def #{probe.declaration}(*args)
|
31
|
+
#{probe}.new.run(options, args)
|
32
|
+
end
|
33
|
+
^
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'version', 'Print version of the AppDB probe set'
|
37
|
+
def version
|
38
|
+
puts Nagios::Promoo::Appdb::VERSION
|
39
|
+
end
|
40
|
+
end
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Internal deps
|
2
|
+
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
|
+
|
4
|
+
class Nagios::Promoo::Appdb::Probes::AppliancesProbe < Nagios::Promoo::Appdb::Probes::BaseProbe
|
5
|
+
class << self
|
6
|
+
def description
|
7
|
+
['appliances', 'Run a probe checking appliances in AppDB']
|
8
|
+
end
|
9
|
+
|
10
|
+
def options
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def declaration
|
15
|
+
"appliances"
|
16
|
+
end
|
17
|
+
|
18
|
+
def runnable?; true; end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(options, args = [])
|
22
|
+
count = nil
|
23
|
+
begin
|
24
|
+
count = Timeout::timeout(options[:timeout]) { check_appliances(options) }
|
25
|
+
fail "No appliances found in AppDB" if count < 1
|
26
|
+
rescue => ex
|
27
|
+
puts "APPLIANCES CRITICAL - #{ex.message}"
|
28
|
+
puts ex.backtrace if options[:debug]
|
29
|
+
exit 2
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "APPLIANCES OK - Found #{count} appliances in AppDB"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_appliances(options)
|
38
|
+
(appdb_provider(options)['image'] || []).count
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Nagios::Promoo::Appdb::Probes::BaseProbe
|
2
|
+
class << self
|
3
|
+
def runnable?; false; end
|
4
|
+
end
|
5
|
+
|
6
|
+
APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'
|
7
|
+
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'
|
8
|
+
|
9
|
+
def appdb_provider(options)
|
10
|
+
return @provider if @provider
|
11
|
+
|
12
|
+
response = HTTParty.post(APPDB_PROXY_URL, { :body => APPDB_REQUEST_FORM })
|
13
|
+
fail "Could not get site"\
|
14
|
+
"details from AppDB [#{response.code}]" unless response.success?
|
15
|
+
|
16
|
+
@provider = response.parsed_response['broker']['reply']['appdb']['provider'].select do |prov|
|
17
|
+
prov['endpoint_url'] && (prov['endpoint_url'].chomp('/') == options[:endpoint].chomp('/'))
|
18
|
+
end.first
|
19
|
+
fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @provider
|
20
|
+
|
21
|
+
@provider
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Internal deps
|
2
|
+
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
|
+
|
4
|
+
class Nagios::Promoo::Appdb::Probes::SizesProbe < Nagios::Promoo::Appdb::Probes::BaseProbe
|
5
|
+
class << self
|
6
|
+
def description
|
7
|
+
['sizes', 'Run a probe checking size templates in AppDB']
|
8
|
+
end
|
9
|
+
|
10
|
+
def options
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def declaration
|
15
|
+
"sizes"
|
16
|
+
end
|
17
|
+
|
18
|
+
def runnable?; true; end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(options, args = [])
|
22
|
+
count = nil
|
23
|
+
begin
|
24
|
+
count = Timeout::timeout(options[:timeout]) { check_sizes(options) }
|
25
|
+
fail "No size templates found in AppDB" if count < 1
|
26
|
+
rescue => ex
|
27
|
+
puts "SIZES CRITICAL - #{ex.message}"
|
28
|
+
puts ex.backtrace if options[:debug]
|
29
|
+
exit 2
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "SIZES OK - Found #{count} size templates in AppDB"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_sizes(options)
|
38
|
+
(appdb_provider(options)['template'] || []).count
|
39
|
+
end
|
40
|
+
end
|
data/lib/nagios/promoo/master.rb
CHANGED
@@ -17,6 +17,9 @@ class Nagios::Promoo::Master < ::Thor
|
|
17
17
|
desc 'occi PROBE', 'Run the given probe for OCCI'
|
18
18
|
subcommand 'occi', Nagios::Promoo::Occi::Master
|
19
19
|
|
20
|
+
desc 'appdb PROBE', 'Run the given probe for AppDB'
|
21
|
+
subcommand 'appdb', Nagios::Promoo::Appdb::Master
|
22
|
+
|
20
23
|
desc 'version', 'Print PROMOO version'
|
21
24
|
def version
|
22
25
|
puts Nagios::Promoo::VERSION
|
@@ -26,7 +26,6 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
|
|
26
26
|
|
27
27
|
CPU_SUM_WEIGHT = 1000
|
28
28
|
COMPUTE_NAME_PREFIX = "sam-nagios-promoo"
|
29
|
-
CACHE_DIR = '/tmp/nagios-promoo_cache'
|
30
29
|
APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'
|
31
30
|
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'
|
32
31
|
|
@@ -147,30 +146,14 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
|
|
147
146
|
@provider = parsed_response['broker']['reply']['appdb']['provider'].select do |prov|
|
148
147
|
prov['endpoint_url'] && (prov['endpoint_url'].chomp('/') == options[:endpoint].chomp('/'))
|
149
148
|
end.first
|
150
|
-
fail "Could not locate site by endpoint #{options[:endpoint]} in AppDB" unless @provider
|
149
|
+
fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @provider
|
151
150
|
|
152
151
|
@provider
|
153
152
|
end
|
154
153
|
|
155
|
-
def cache_fetch(key, expiration = 3600)
|
156
|
-
fail 'You have to provide a block!' unless block_given?
|
157
|
-
FileUtils.mkdir_p CACHE_DIR
|
158
|
-
filename = File.join(CACHE_DIR, key)
|
159
|
-
|
160
|
-
if cache_valid?(filename, expiration)
|
161
|
-
File.open(filename, 'r') { |file| JSON.parse file.read }
|
162
|
-
else
|
163
|
-
data = yield
|
164
|
-
File.open(filename, 'w') { |file| file.write JSON.pretty_generate(data) }
|
165
|
-
data
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def cache_valid?(filename, expiration)
|
170
|
-
File.exists?(filename) && ((Time.now - expiration) < File.stat(filename).mtime)
|
171
|
-
end
|
172
|
-
|
173
154
|
def normalize_mpuri(mpuri)
|
174
155
|
mpuri.gsub(/\/+$/, '').gsub(/:\d+$/, '')
|
175
156
|
end
|
157
|
+
|
158
|
+
include Nagios::Promoo::Utils::Cache
|
176
159
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Nagios::Promoo::Utils
|
2
|
+
module Cache
|
3
|
+
CACHE_DIR = '/tmp/nagios-promoo_cache'
|
4
|
+
|
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)
|
9
|
+
|
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
|
26
|
+
|
27
|
+
def cache_valid?(filename, expiration)
|
28
|
+
File.exists?(filename) && !File.zero?(filename) && ((Time.now - expiration) < File.stat(filename).mtime)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/.keep
ADDED
File without changes
|
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.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: occi-api
|
@@ -235,6 +235,13 @@ files:
|
|
235
235
|
- Rakefile
|
236
236
|
- bin/nagios-promoo
|
237
237
|
- lib/nagios/promoo.rb
|
238
|
+
- lib/nagios/promoo/appdb/.keep
|
239
|
+
- lib/nagios/promoo/appdb/master.rb
|
240
|
+
- lib/nagios/promoo/appdb/probes/.keep
|
241
|
+
- lib/nagios/promoo/appdb/probes/appliances_probe.rb
|
242
|
+
- lib/nagios/promoo/appdb/probes/base_probe.rb
|
243
|
+
- lib/nagios/promoo/appdb/probes/sizes_probe.rb
|
244
|
+
- lib/nagios/promoo/appdb/version.rb
|
238
245
|
- lib/nagios/promoo/master.rb
|
239
246
|
- lib/nagios/promoo/occi/.keep
|
240
247
|
- lib/nagios/promoo/occi/master.rb
|
@@ -251,8 +258,10 @@ files:
|
|
251
258
|
- lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb
|
252
259
|
- lib/nagios/promoo/opennebula/probes/xmlrpc_health_probe.rb
|
253
260
|
- lib/nagios/promoo/opennebula/version.rb
|
261
|
+
- lib/nagios/promoo/utils.rb
|
254
262
|
- lib/nagios/promoo/version.rb
|
255
263
|
- nagios-promoo.gemspec
|
264
|
+
- test/.keep
|
256
265
|
homepage: https://github.com/EGI-FCTF/nagios-promoo
|
257
266
|
licenses:
|
258
267
|
- Apache License, Version 2.0
|
@@ -277,4 +286,5 @@ rubygems_version: 2.4.6
|
|
277
286
|
signing_key:
|
278
287
|
specification_version: 4
|
279
288
|
summary: Nagios Probes for Monitoring OpenNebula and OCCI
|
280
|
-
test_files:
|
289
|
+
test_files:
|
290
|
+
- test/.keep
|