nagira 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +5 -4
- data/spec/get/endpoints_spec.rb +88 -3
- data/version.txt +1 -1
- metadata +36 -44
- data/config/nagira.defaults.erb +0 -98
- data/spec/get/get_helper.rb +0 -50
- data/spec/get/objects/data_spec.rb +0 -25
- data/spec/get/objects/endpoints_spec.rb +0 -33
- data/spec/get/status/endpoints_spec.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be37e447b15c8087f82209470877a5fb202d77d
|
4
|
+
data.tar.gz: e9670a022cfbe3184264353ac346d2133b6eb258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 065f49e0b3c74dffb37dbffaf9273407a8a7d329b4cfd4448ce1c143a2426218f3b1119a3423795ccaf283d37f36ad1e096dd41ff675b662e607fe69f911519a
|
7
|
+
data.tar.gz: 7940f90fba42d4ab49f3fcb057a216654a2c7af9791a83fbc7d262dc99cdf48ba06d94c35cb5761d8f2817dc15a2653dba05c2b73355f95f1c8403e8a39ed285
|
data/History.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
-
|
1
|
+
|
2
|
+
### v.0.3.3
|
3
|
+
* Tue May 27 2014 -- Dmytro Kovalov
|
4
|
+
- Bugfix: fix parsing of service blocks https://github.com/dmytro/nagira/issues/27
|
5
|
+
|
5
6
|
### v.0.3.1
|
6
7
|
* Mon Aug 26 2013 -- Dmytro Kovalov
|
7
8
|
- Bugfix: fix for init.d script to load defaults file
|
data/spec/get/endpoints_spec.rb
CHANGED
@@ -1,4 +1,45 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Specs for implemetned API endpoints. Only check response: OK or 404.
|
5
|
+
#
|
6
|
+
|
7
|
+
shared_examples_for :fail_on_random_url do |base|
|
8
|
+
RANDOM.each do |url|
|
9
|
+
ep = "#{base}/#{url}"
|
10
|
+
it "fails on '#{ep}' string" do
|
11
|
+
get ep
|
12
|
+
last_response.status.should be 404
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples_for :respond_to_valid_url do |base, urls, custom_regex|
|
18
|
+
|
19
|
+
case urls
|
20
|
+
when Array
|
21
|
+
urls.each do |url|
|
22
|
+
ep = "#{base}/#{url}"
|
23
|
+
it "responds to #{ep}" do
|
24
|
+
get ep
|
25
|
+
last_response.should be_ok
|
26
|
+
end
|
27
|
+
end
|
28
|
+
when nil
|
29
|
+
ep = "#{base}"
|
30
|
+
it "responds to #{ep}" do
|
31
|
+
get ep
|
32
|
+
last_response.should be_ok
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
shared_examples_for :fail_on_bad_url do |url|
|
38
|
+
before { get url }
|
39
|
+
it "fails on #{url}" do
|
40
|
+
last_response.status.should be 404
|
41
|
+
end
|
42
|
+
end
|
2
43
|
|
3
44
|
describe Nagira do
|
4
45
|
|
@@ -10,9 +51,53 @@ describe Nagira do
|
|
10
51
|
|
11
52
|
context "API endpoints" do
|
12
53
|
|
54
|
+
host = IMPLEMENTED[:hosts].first
|
55
|
+
spaces = "host%20with%20space"
|
56
|
+
|
57
|
+
|
13
58
|
context :top do
|
14
59
|
it_should_behave_like :respond_to_valid_url, '', IMPLEMENTED[:top]
|
15
60
|
it_should_behave_like :fail_on_random_url, ''
|
16
61
|
end
|
17
|
-
|
18
|
-
|
62
|
+
|
63
|
+
|
64
|
+
context "/_status" do
|
65
|
+
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:hosts]
|
66
|
+
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:output] + ["_hosts"]
|
67
|
+
it_should_behave_like :fail_on_random_url, '/_status'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "/_status/:host" do
|
71
|
+
it_should_behave_like :respond_to_valid_url, "/_status/#{host}", IMPLEMENTED[:status]
|
72
|
+
it_should_behave_like :fail_on_random_url, "/_status/#{host}"
|
73
|
+
|
74
|
+
context "hostname with space" do
|
75
|
+
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}"
|
76
|
+
end
|
77
|
+
|
78
|
+
context :unknown_host do
|
79
|
+
it_should_behave_like :fail_on_bad_url, '/_status/unknown_host'
|
80
|
+
it_should_behave_like :fail_on_random_url, "/_status/unknown_host"
|
81
|
+
end
|
82
|
+
end # /_status/:host
|
83
|
+
|
84
|
+
context "/_status/:host/_services" do
|
85
|
+
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services"
|
86
|
+
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services", ["SSH", "PING"]
|
87
|
+
|
88
|
+
context "hostname with space" do
|
89
|
+
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}/_services"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
context "custom hostname regex - host with spaces" do
|
95
|
+
|
96
|
+
it { pending "Need to figure out how to change hostname regex on the fly" }
|
97
|
+
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}", nil, '\w[(%20)\w\-\.]+'
|
98
|
+
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}/_services"
|
99
|
+
end # custom hostname regex
|
100
|
+
|
101
|
+
end # API endpoints
|
102
|
+
|
103
|
+
end
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Kovalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,40 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2
|
19
|
+
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.2
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.2
|
33
|
+
version: '3.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.2
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.7.7
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.7.7
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,9 @@ dependencies:
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
- - '>='
|
74
77
|
- !ruby/object:Gem::Version
|
75
78
|
version: 0.0.2
|
76
79
|
type: :runtime
|
@@ -78,6 +81,9 @@ dependencies:
|
|
78
81
|
version_requirements: !ruby/object:Gem::Requirement
|
79
82
|
requirements:
|
80
83
|
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.0'
|
86
|
+
- - '>='
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: 0.0.2
|
83
89
|
- !ruby/object:Gem::Dependency
|
@@ -128,14 +134,20 @@ dependencies:
|
|
128
134
|
requirements:
|
129
135
|
- - ~>
|
130
136
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.2
|
137
|
+
version: '0.2'
|
138
|
+
- - '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.2.2
|
132
141
|
type: :runtime
|
133
142
|
prerelease: false
|
134
143
|
version_requirements: !ruby/object:Gem::Requirement
|
135
144
|
requirements:
|
136
145
|
- - ~>
|
137
146
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.2
|
147
|
+
version: '0.2'
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.2.2
|
139
151
|
- !ruby/object:Gem::Dependency
|
140
152
|
name: sinatra
|
141
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,20 +232,6 @@ dependencies:
|
|
220
232
|
- - ~>
|
221
233
|
- !ruby/object:Gem::Version
|
222
234
|
version: 1.2.1
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: redcarpet
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - '>='
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - '>='
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
235
|
- !ruby/object:Gem::Dependency
|
238
236
|
name: yard
|
239
237
|
requirement: !ruby/object:Gem::Requirement
|
@@ -278,21 +276,25 @@ executables:
|
|
278
276
|
extensions: []
|
279
277
|
extra_rdoc_files: []
|
280
278
|
files:
|
281
|
-
- bin/nagira
|
282
279
|
- History.md
|
283
280
|
- Rakefile
|
284
|
-
-
|
281
|
+
- bin/nagira
|
282
|
+
- bin/nagira-setup
|
283
|
+
- config/defaults.rb
|
284
|
+
- config/environment.rb
|
285
|
+
- config/nagira.defaults
|
286
|
+
- config/nagira.init_d
|
287
|
+
- lib/app.rb
|
285
288
|
- lib/app/routes/get/config.rb
|
286
289
|
- lib/app/routes/get/objects.rb
|
287
290
|
- lib/app/routes/get/status.rb
|
291
|
+
- lib/app/routes/put.rb
|
288
292
|
- lib/app/routes/put/host.rb
|
289
293
|
- lib/app/routes/put/status.rb
|
290
|
-
- lib/
|
291
|
-
- lib/app.rb
|
294
|
+
- lib/nagira.rb
|
292
295
|
- lib/nagira/background_parse.rb
|
293
296
|
- lib/nagira/nagios.rb
|
294
297
|
- lib/nagira/timed_parse.rb
|
295
|
-
- lib/nagira.rb
|
296
298
|
- lib/tasks/config.rake
|
297
299
|
- lib/tasks/debug.rake
|
298
300
|
- lib/tasks/doc.rake
|
@@ -303,38 +305,29 @@ files:
|
|
303
305
|
- spec/01_data_format/03_api_spec.rb
|
304
306
|
- spec/get/comments_spec.rb
|
305
307
|
- spec/get/endpoints_spec.rb
|
306
|
-
- spec/get/get_helper.rb
|
307
308
|
- spec/get/hosts_spec.rb
|
308
|
-
- spec/get/objects/data_spec.rb
|
309
|
-
- spec/get/objects/endpoints_spec.rb
|
310
309
|
- spec/get/services_spec.rb
|
311
|
-
- spec/get/status/endpoints_spec.rb
|
312
310
|
- spec/put/host_spec.rb
|
313
311
|
- spec/put/status_spec.rb
|
314
312
|
- spec/put/support.rb
|
315
313
|
- spec/spec_helper.rb
|
316
|
-
- config/defaults.rb
|
317
|
-
- config/environment.rb
|
318
|
-
- config/nagira.defaults
|
319
|
-
- config/nagira.defaults.erb
|
320
|
-
- config/nagira.init_d
|
321
314
|
- test/benchmark.rb
|
315
|
+
- test/data/bad/README
|
322
316
|
- test/data/bad/nagios.cfg
|
323
317
|
- test/data/bad/objects.cache
|
324
|
-
- test/data/bad/README
|
325
318
|
- test/data/bad/status.dat
|
326
319
|
- test/data/json/GET.txt
|
320
|
+
- test/data/json/README.txt
|
327
321
|
- test/data/json/host_check.json
|
328
322
|
- test/data/json/host_check.sh
|
329
323
|
- test/data/json/ping.json
|
330
324
|
- test/data/json/ping_and_http.json
|
331
325
|
- test/data/json/ping_and_http_check.sh
|
332
326
|
- test/data/json/ping_check.sh
|
333
|
-
- test/data/json/README.txt
|
334
327
|
- test/data/nagios.cfg
|
335
328
|
- test/data/objects.cache
|
336
329
|
- test/data/status.dat
|
337
|
-
-
|
330
|
+
- version.txt
|
338
331
|
homepage: http://dmytro.github.com/nagira
|
339
332
|
licenses:
|
340
333
|
- MIT
|
@@ -348,7 +341,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
348
341
|
requirements:
|
349
342
|
- - '>='
|
350
343
|
- !ruby/object:Gem::Version
|
351
|
-
version:
|
344
|
+
version: '0'
|
352
345
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
353
346
|
requirements:
|
354
347
|
- - '>='
|
@@ -356,9 +349,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
356
349
|
version: '0'
|
357
350
|
requirements: []
|
358
351
|
rubyforge_project:
|
359
|
-
rubygems_version: 2.
|
352
|
+
rubygems_version: 2.2.2
|
360
353
|
signing_key:
|
361
354
|
specification_version: 4
|
362
355
|
summary: 'Nagira : Nagios RESTful API'
|
363
356
|
test_files: []
|
364
|
-
has_rdoc:
|
data/config/nagira.defaults.erb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Defaults configuration file for Nagira
|
3
|
-
# --------------------------------------------
|
4
|
-
<% %w{ NAGIRA_PORT NAGIRA_BIND RACK_ENV NAGIRA_USER RVM_STRING NAGIRA_LOG NAGIRA_TTL NAGIRA_BG_PARSING NAGIOS_CFG_FILE NAGIOS_HOST_CUSTOM_REGEX}.each do |env| -%>
|
5
|
-
<% if env.downcase.to_sym -%>
|
6
|
-
<%= env -%>=<%="#{env}" -%>
|
7
|
-
<% end -%>
|
8
|
-
<% end -%>
|
9
|
-
#
|
10
|
-
# Examples below are default values.
|
11
|
-
#
|
12
|
-
# ----------------------
|
13
|
-
# Port. Default 4567
|
14
|
-
# ----------------------
|
15
|
-
# NAGIRA_PORT=
|
16
|
-
#
|
17
|
-
# ----------------------
|
18
|
-
# BIND
|
19
|
-
# ----------------------
|
20
|
-
# String specifying the hostname or IP address of the interface to
|
21
|
-
# listen on when the :run setting is enabled. The default value –
|
22
|
-
# '0.0.0.0' – causes the server to listen on all available
|
23
|
-
# interfaces. To listen on the loopback interface only, use: 'localhost'
|
24
|
-
#
|
25
|
-
# NAGIRA_BIND=localhost
|
26
|
-
#
|
27
|
-
# ----------------------
|
28
|
-
# Environment
|
29
|
-
# ----------------------
|
30
|
-
# Usually needs to be production
|
31
|
-
#
|
32
|
-
# RACK_ENV=production
|
33
|
-
#
|
34
|
-
# ----------------------
|
35
|
-
# Nagira user
|
36
|
-
# ----------------------
|
37
|
-
# Usually nagira process should be run by same user ID as Nagios. In
|
38
|
-
# many cases this is nagios user.
|
39
|
-
#
|
40
|
-
# NAGIRA_USER=nagios
|
41
|
-
#
|
42
|
-
# ----------------------
|
43
|
-
# RVM
|
44
|
-
# ----------------------
|
45
|
-
# RVM_STRING="rvm use default"
|
46
|
-
#
|
47
|
-
# ----------------------
|
48
|
-
# Log file
|
49
|
-
# ----------------------
|
50
|
-
# NAGIRA_LOG=/var/log/nagios/nagira.log
|
51
|
-
#
|
52
|
-
# ----------------------
|
53
|
-
# TTL for data
|
54
|
-
# ----------------------
|
55
|
-
# Number of seconds between re-parses. All Nagios file are parsed no
|
56
|
-
# more often than this. Default is 5 sec. Setting this to 0 or
|
57
|
-
# negative number disables TTL and backgroiund prser as well.
|
58
|
-
#
|
59
|
-
# NAGIRA_TTL=20
|
60
|
-
#
|
61
|
-
# ----------------------
|
62
|
-
# Background parsing
|
63
|
-
# ----------------------
|
64
|
-
# Set this to 0, to disable background parsing.
|
65
|
-
# NAGIRA_BG_PARSING=1
|
66
|
-
#
|
67
|
-
# ----------------------
|
68
|
-
# Nagios configuration file
|
69
|
-
# ----------------------
|
70
|
-
# Where main Nagios configuration file is located. usually this does
|
71
|
-
# not need to change.
|
72
|
-
#
|
73
|
-
# NAGIOS_CFG_FILE=/etc/nagios/nagios.cfg
|
74
|
-
#
|
75
|
-
# ----------------------
|
76
|
-
# Custom regex for hostnames
|
77
|
-
# ----------------------
|
78
|
-
#
|
79
|
-
# By default hostname regular expression accepts alpha-numerics,
|
80
|
-
# dashes and dots, as specified by http://tools.ietf.org/html/rfc952
|
81
|
-
# for hostnames. Extended to accept dots in the middle for FQHN's.
|
82
|
-
#
|
83
|
-
# Possible settings:
|
84
|
-
#
|
85
|
-
# - default: '\w([\w\-\.]+)?\w' FQHN
|
86
|
-
# - short hostname: '\w([\w\-]+)?\w'
|
87
|
-
# - FQHN allow space in hostname: '\w([\w\-\.(%20)]+)?\w'
|
88
|
-
#
|
89
|
-
# Explanation regarding spaces:
|
90
|
-
# ---------------------------------
|
91
|
-
#
|
92
|
-
# Nagios works OK with hostnames with spaces. This is against RFC's
|
93
|
-
# and can't really used for real hosts, but for aggregated checks
|
94
|
-
# (like cluster name for example), you might want to consider this
|
95
|
-
# option.
|
96
|
-
#
|
97
|
-
# NAGIOS_HOST_CUSTOM_REGEX='\w([\w\-\.]+)?\w'
|
98
|
-
#
|
data/spec/get/get_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
IMPLEMENTED = {
|
4
|
-
top: %w{ _api _status _objects _config _runtime},
|
5
|
-
output: %w{ _list _state _full }, # Type of requests as in varaible @output
|
6
|
-
hosts: %w{ archive tv },
|
7
|
-
status: %w{ _services _servicecomments _hostcomments },
|
8
|
-
objects: %w{ timeperiod command contactgroup hostgroup contact host service }
|
9
|
-
}
|
10
|
-
|
11
|
-
#
|
12
|
-
# Specs for implemetned API endpoints. Only check response: OK or 404.
|
13
|
-
#
|
14
|
-
|
15
|
-
shared_examples_for :fail_on_random_url do |base|
|
16
|
-
RANDOM.each do |url|
|
17
|
-
ep = "#{base}/#{url}"
|
18
|
-
it "fails on '#{ep}' string" do
|
19
|
-
get ep
|
20
|
-
last_response.status.should be 404
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
shared_examples_for :respond_to_valid_url do |base, urls, custom_regex|
|
26
|
-
|
27
|
-
case urls
|
28
|
-
when Array
|
29
|
-
urls.each do |url|
|
30
|
-
ep = "#{base}/#{url}"
|
31
|
-
it "responds to #{ep}" do
|
32
|
-
get ep
|
33
|
-
last_response.should be_ok
|
34
|
-
end
|
35
|
-
end
|
36
|
-
when nil
|
37
|
-
ep = "#{base}"
|
38
|
-
it "responds to #{ep}" do
|
39
|
-
get ep
|
40
|
-
last_response.should be_ok
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
shared_examples_for :fail_on_bad_url do |url|
|
46
|
-
before { get url }
|
47
|
-
it "fails on #{url}" do
|
48
|
-
last_response.status.should be 404
|
49
|
-
end
|
50
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative '../get_helper'
|
2
|
-
|
3
|
-
describe Nagira do
|
4
|
-
|
5
|
-
set :environment, :test # This should run only in test mode as it uses hardcoded host names
|
6
|
-
include Rack::Test::Methods
|
7
|
-
def app
|
8
|
-
@app ||= Nagira
|
9
|
-
end
|
10
|
-
|
11
|
-
subject { JSON.parse last_response.body }
|
12
|
-
|
13
|
-
context "Data structure" do
|
14
|
-
context "/_objects" do
|
15
|
-
|
16
|
-
let (:host) { IMPLEMENTED[:hosts].first }
|
17
|
-
|
18
|
-
it { get "/_objects" ; should be_a_kind_of Hash }
|
19
|
-
it { get "/_objects/_list" ; should be_a_kind_of Array }
|
20
|
-
it { get "/_objects/host" ; should be_a_kind_of Hash }
|
21
|
-
it { get "/_objects/host/#{host}" ; should be_a_kind_of Hash }
|
22
|
-
|
23
|
-
end
|
24
|
-
end # Data structure
|
25
|
-
end # describe Nagira
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative '../get_helper'
|
2
|
-
|
3
|
-
describe Nagira do
|
4
|
-
|
5
|
-
set :environment, :test # This should run only in test mode as it uses hardcoded host names
|
6
|
-
include Rack::Test::Methods
|
7
|
-
def app
|
8
|
-
@app ||= Nagira
|
9
|
-
end
|
10
|
-
|
11
|
-
context "API endpoints" do
|
12
|
-
context "/_objects" do
|
13
|
-
it_should_behave_like :respond_to_valid_url, "/_objects"
|
14
|
-
it_should_behave_like :respond_to_valid_url, "/_objects/_list"
|
15
|
-
|
16
|
-
|
17
|
-
it_should_behave_like :respond_to_valid_url, "/_objects", IMPLEMENTED[:objects]
|
18
|
-
it_should_behave_like :fail_on_random_url, "/_objects"
|
19
|
-
# AR- compatibility
|
20
|
-
it_should_behave_like :respond_to_valid_url, "/_objects", IMPLEMENTED[:objects].map(&:pluralize)
|
21
|
-
|
22
|
-
context :host do
|
23
|
-
host = IMPLEMENTED[:hosts].first
|
24
|
-
spaces = "host%20with%20space"
|
25
|
-
|
26
|
-
it_should_behave_like :respond_to_valid_url, "/_objects/host/#{host}"
|
27
|
-
it_should_behave_like :fail_on_bad_url, "/_objects/host/#{spaces}"
|
28
|
-
it_should_behave_like :respond_to_valid_url, "/_objects/host/#{host}/_list"
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end # API endpoints
|
33
|
-
end # describe Nagira
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Specs for implemetned API endpoints. Only check response: OK or 404.
|
5
|
-
#
|
6
|
-
|
7
|
-
shared_examples_for :fail_on_random_url do |base|
|
8
|
-
RANDOM.each do |url|
|
9
|
-
ep = "#{base}/#{url}"
|
10
|
-
it "fails on '#{ep}' string" do
|
11
|
-
get ep
|
12
|
-
last_response.status.should be 404
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
shared_examples_for :respond_to_valid_url do |base, urls, custom_regex|
|
18
|
-
|
19
|
-
case urls
|
20
|
-
when Array
|
21
|
-
urls.each do |url|
|
22
|
-
ep = "#{base}/#{url}"
|
23
|
-
it "responds to #{ep}" do
|
24
|
-
get ep
|
25
|
-
last_response.should be_ok
|
26
|
-
end
|
27
|
-
end
|
28
|
-
when nil
|
29
|
-
ep = "#{base}"
|
30
|
-
it "responds to #{ep}" do
|
31
|
-
get ep
|
32
|
-
last_response.should be_ok
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
shared_examples_for :fail_on_bad_url do |url|
|
38
|
-
before { get url }
|
39
|
-
it "fails on #{url}" do
|
40
|
-
last_response.status.should be 404
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe Nagira do
|
45
|
-
|
46
|
-
set :environment, :test # This should run only in test mode as it uses hardcoded host names
|
47
|
-
include Rack::Test::Methods
|
48
|
-
def app
|
49
|
-
@app ||= Nagira
|
50
|
-
end
|
51
|
-
|
52
|
-
context "API endpoints" do
|
53
|
-
|
54
|
-
host = IMPLEMENTED[:hosts].first
|
55
|
-
spaces = "host%20with%20space"
|
56
|
-
|
57
|
-
|
58
|
-
context :top do
|
59
|
-
it_should_behave_like :respond_to_valid_url, '', IMPLEMENTED[:top]
|
60
|
-
it_should_behave_like :fail_on_random_url, ''
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
context "/_status" do
|
65
|
-
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:hosts]
|
66
|
-
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:output] + ["_hosts"]
|
67
|
-
it_should_behave_like :fail_on_random_url, '/_status'
|
68
|
-
end
|
69
|
-
|
70
|
-
context "/_status/:host" do
|
71
|
-
it_should_behave_like :respond_to_valid_url, "/_status/#{host}", IMPLEMENTED[:status]
|
72
|
-
it_should_behave_like :fail_on_random_url, "/_status/#{host}"
|
73
|
-
|
74
|
-
context "hostname with space" do
|
75
|
-
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}"
|
76
|
-
end
|
77
|
-
|
78
|
-
context :unknown_host do
|
79
|
-
it_should_behave_like :fail_on_bad_url, '/_status/unknown_host'
|
80
|
-
it_should_behave_like :fail_on_random_url, "/_status/unknown_host"
|
81
|
-
end
|
82
|
-
end # /_status/:host
|
83
|
-
|
84
|
-
context "/_status/:host/_services" do
|
85
|
-
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services"
|
86
|
-
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services", ["SSH", "PING"]
|
87
|
-
|
88
|
-
context "hostname with space" do
|
89
|
-
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}/_services"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
context "custom hostname regex - host with spaces" do
|
95
|
-
|
96
|
-
it { pending "Need to figure out how to change hostname regex on the fly" }
|
97
|
-
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}", nil, '\w[(%20)\w\-\.]+'
|
98
|
-
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}/_services"
|
99
|
-
end # custom hostname regex
|
100
|
-
|
101
|
-
end # API endpoints
|
102
|
-
|
103
|
-
end
|