nagira 0.3.3 → 0.4.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.
- checksums.yaml +4 -4
- data/History.md +29 -23
- data/{lib → app}/app.rb +6 -7
- data/{lib/app/routes → app}/get/config.rb +0 -0
- data/{lib/app/routes → app}/get/objects.rb +0 -0
- data/{lib/app/routes → app}/get/status.rb +18 -15
- data/app/get/status/hostgroups.rb +49 -0
- data/{lib/app/routes → app}/put.rb +0 -0
- data/{lib/app/routes → app}/put/host.rb +0 -0
- data/{lib/app/routes → app}/put/status.rb +0 -0
- data/bin/nagira +3 -3
- data/config/defaults.rb +9 -10
- data/config/environment.rb +9 -10
- data/lib/nagira.rb +12 -8
- data/lib/nagira/hostgroup.rb +46 -0
- data/spec/00_configuration_spec.rb +21 -21
- data/spec/01_data_format/01_nagira_response_spec.rb +26 -26
- data/spec/01_data_format/02_0_status_spec.rb +11 -11
- data/spec/01_data_format/02_nagira_data_spec.rb +27 -27
- data/spec/01_data_format/03_api_spec.rb +12 -12
- data/spec/get/comments_spec.rb +15 -15
- data/spec/get/endpoints_spec.rb +34 -19
- data/spec/get/hostgroup.rb +79 -0
- data/spec/get/hosts_spec.rb +10 -10
- data/spec/get/services_spec.rb +8 -8
- data/spec/put/host_spec.rb +12 -12
- data/spec/put/status_spec.rb +23 -22
- data/spec/put/support.rb +24 -24
- data/spec/spec_helper.rb +3 -2
- data/version.txt +1 -1
- metadata +45 -27
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
#
|
4
4
|
# Test resonse to /_api GET
|
5
5
|
#
|
6
|
-
describe Nagira do
|
6
|
+
describe Nagira do
|
7
7
|
|
8
8
|
set :environment, ENV['RACK_ENV'] || :test
|
9
9
|
|
10
10
|
include Rack::Test::Methods
|
11
|
-
|
11
|
+
|
12
12
|
def app
|
13
13
|
@app ||= Nagira
|
14
14
|
end
|
@@ -16,30 +16,30 @@ describe Nagira do
|
|
16
16
|
|
17
17
|
|
18
18
|
context "API data" do
|
19
|
-
before :all do
|
19
|
+
before :all do
|
20
20
|
get "/_api.json"
|
21
21
|
@data = JSON.parse last_response.body
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should be array" do
|
25
|
-
@data.
|
24
|
+
it "should be array" do
|
25
|
+
expect(@data).to be_a_kind_of Hash
|
26
26
|
end
|
27
27
|
|
28
28
|
METHODS = %w{ GET PUT POST DELETE}
|
29
29
|
|
30
|
-
context "routes" do
|
31
|
-
|
30
|
+
context "routes" do
|
31
|
+
|
32
32
|
METHODS.each do |method|
|
33
|
-
|
34
|
-
context method do
|
33
|
+
|
34
|
+
context method do
|
35
35
|
it "routes should be an Array" do
|
36
|
-
@data[method].
|
36
|
+
expect(@data[method]).to be_a_kind_of Array if @data[method]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should star with slash" do
|
40
40
|
if @data[method]
|
41
41
|
@data[method].each do |path|
|
42
|
-
path.
|
42
|
+
expect(path).to match( /^\//)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/spec/get/comments_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
|
4
|
-
shared_examples_for :comment_data do
|
4
|
+
shared_examples_for :comment_data do
|
5
5
|
|
6
6
|
let(:data) { JSON.parse(last_response.body) }
|
7
7
|
|
@@ -14,44 +14,44 @@ shared_examples_for :comment_data do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
17
|
+
it { expect(subject).to be_a_kind_of Hash }
|
18
|
+
it { expect(subject).to have_key 'comment_id' }
|
19
|
+
it { expect(subject).to have_key 'comment_data' }
|
20
|
+
it { expect(subject).to have_key 'author' }
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
-
describe Nagira do
|
26
|
-
|
25
|
+
describe Nagira do
|
26
|
+
|
27
27
|
set :environment, ENV['RACK_ENV'] || :test
|
28
28
|
include Rack::Test::Methods
|
29
|
-
def app
|
29
|
+
def app
|
30
30
|
@app ||= Nagira
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
before :all do
|
34
34
|
get "/_status/_list.json"
|
35
35
|
@host = JSON.parse(last_response.body).first
|
36
36
|
end
|
37
37
|
|
38
|
-
context "/_status/:host/_hostcomments" do
|
38
|
+
context "/_status/:host/_hostcomments" do
|
39
39
|
before { get "/_status/#{@host}/_hostcomments.json" }
|
40
|
-
it_should_behave_like :comment_data
|
40
|
+
it_should_behave_like :comment_data
|
41
41
|
end
|
42
42
|
|
43
43
|
|
44
|
-
context "/_status/:host/_servicecomments" do
|
44
|
+
context "/_status/:host/_servicecomments" do
|
45
45
|
before { get "/_status/#{@host}/_servicecomments.json" }
|
46
46
|
|
47
47
|
it_should_behave_like :comment_data
|
48
48
|
|
49
49
|
let (:data) { JSON.parse(last_response.body).values.first.first }
|
50
|
-
it { data.
|
51
|
-
it { data.
|
50
|
+
it { expect(data).to have_key 'service_description' }
|
51
|
+
it { expect(data).to have_key 'host_name' }
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
-
|
56
|
+
|
57
57
|
end
|
data/spec/get/endpoints_spec.rb
CHANGED
@@ -4,12 +4,12 @@ require 'spec_helper'
|
|
4
4
|
# Specs for implemetned API endpoints. Only check response: OK or 404.
|
5
5
|
#
|
6
6
|
|
7
|
-
shared_examples_for :fail_on_random_url do |base|
|
7
|
+
shared_examples_for :fail_on_random_url do |base|
|
8
8
|
RANDOM.each do |url|
|
9
9
|
ep = "#{base}/#{url}"
|
10
10
|
it "fails on '#{ep}' string" do
|
11
11
|
get ep
|
12
|
-
last_response.status.
|
12
|
+
expect(last_response.status).to be 404
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -22,44 +22,45 @@ shared_examples_for :respond_to_valid_url do |base, urls, custom_regex|
|
|
22
22
|
ep = "#{base}/#{url}"
|
23
23
|
it "responds to #{ep}" do
|
24
24
|
get ep
|
25
|
-
last_response.
|
25
|
+
expect(last_response).to be_ok
|
26
26
|
end
|
27
27
|
end
|
28
28
|
when nil
|
29
29
|
ep = "#{base}"
|
30
30
|
it "responds to #{ep}" do
|
31
31
|
get ep
|
32
|
-
last_response.
|
32
|
+
expect(last_response).to be_ok
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
shared_examples_for :fail_on_bad_url do |url|
|
38
38
|
before { get url }
|
39
|
-
it "fails on #{url}" do
|
40
|
-
last_response.status.
|
39
|
+
it "fails on #{url}" do
|
40
|
+
expect(last_response.status).to eq 404
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe Nagira do
|
45
|
-
|
44
|
+
describe Nagira do
|
45
|
+
|
46
46
|
set :environment, :test # This should run only in test mode as it uses hardcoded host names
|
47
47
|
include Rack::Test::Methods
|
48
|
-
def app
|
48
|
+
def app
|
49
49
|
@app ||= Nagira
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
context "API endpoints" do
|
53
|
-
|
54
|
-
host = IMPLEMENTED[:hosts].first
|
53
|
+
|
54
|
+
host = IMPLEMENTED[:hosts].first
|
55
|
+
hostgroup = 'all'
|
55
56
|
spaces = "host%20with%20space"
|
56
57
|
|
57
58
|
|
58
|
-
context :top do
|
59
|
+
context :top do
|
59
60
|
it_should_behave_like :respond_to_valid_url, '', IMPLEMENTED[:top]
|
60
61
|
it_should_behave_like :fail_on_random_url, ''
|
61
62
|
end
|
62
|
-
|
63
|
+
|
63
64
|
|
64
65
|
context "/_status" do
|
65
66
|
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:hosts]
|
@@ -81,7 +82,7 @@ describe Nagira do
|
|
81
82
|
end
|
82
83
|
end # /_status/:host
|
83
84
|
|
84
|
-
context "/_status/:host/_services" do
|
85
|
+
context "/_status/:host/_services" do
|
85
86
|
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services"
|
86
87
|
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services", ["SSH", "PING"]
|
87
88
|
|
@@ -92,12 +93,26 @@ describe Nagira do
|
|
92
93
|
|
93
94
|
|
94
95
|
context "custom hostname regex - host with spaces" do
|
95
|
-
|
96
|
-
it { pending "Need to figure out how to change hostname regex on the fly" }
|
96
|
+
|
97
|
+
it { pending "Need to figure out how to change hostname regex on the fly"; fail }
|
97
98
|
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}", nil, '\w[(%20)\w\-\.]+'
|
98
99
|
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}/_services"
|
99
100
|
end # custom hostname regex
|
100
|
-
|
101
|
+
|
102
|
+
context "Hostgroups" do
|
103
|
+
|
104
|
+
context "/_status/_hostgroups/:hostgroup" do
|
105
|
+
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "/_status/_hostgroups/:hostgroup/_service" do
|
109
|
+
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}/_service"
|
110
|
+
end
|
111
|
+
context "/_status/_hostgroups/:hostgroup/_host" do
|
112
|
+
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}/_host"
|
113
|
+
end
|
114
|
+
end # Hostgroup
|
115
|
+
|
101
116
|
end # API endpoints
|
102
|
-
|
117
|
+
|
103
118
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Nagira do
|
3
|
+
|
4
|
+
set :environment, ENV['RACK_ENV'] || :test
|
5
|
+
include Rack::Test::Methods
|
6
|
+
def app
|
7
|
+
@app ||= Nagira
|
8
|
+
end
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
get "/_objects/hostgroup/_list.json"
|
12
|
+
@hostgroup = JSON.parse(last_response.body).first
|
13
|
+
|
14
|
+
get "/_objects/host/_list.json"
|
15
|
+
@hosts = JSON.parse(last_response.body).sort
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "/_status/_hostgroup/@hostgroup " do
|
20
|
+
|
21
|
+
before do
|
22
|
+
get "/_status/_hostgroup/#{ @hostgroup }"
|
23
|
+
@data = JSON.parse(last_response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns hostgroup Hash" do
|
27
|
+
expect(@data).to be_a_kind_of Hash
|
28
|
+
end
|
29
|
+
|
30
|
+
it "hostgroup Hash should contain all hosts" do
|
31
|
+
expect(@data.keys.sort).to eq @hosts
|
32
|
+
end
|
33
|
+
|
34
|
+
it "host data should have both host and service status" do
|
35
|
+
expect(@data['viy'].keys).to eq ['hoststatus', 'servicestatus']
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
context "/_status/_hostgroup/@hostgroup/_host" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
get "/_status/_hostgroup/#{ @hostgroup }/_host"
|
45
|
+
@data = JSON.parse(last_response.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns Hash" do
|
49
|
+
expect(@data).to be_a_kind_of Hash
|
50
|
+
end
|
51
|
+
|
52
|
+
it "host data should have host status attributes" do
|
53
|
+
expect(@data['viy'].keys).to include 'host_name', 'check_command' ,'check_interval'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "/_status/_hostgroup/@hostgroup/_service" do
|
59
|
+
|
60
|
+
before do
|
61
|
+
get "/_status/_hostgroup/#{ @hostgroup }/_service"
|
62
|
+
@data = JSON.parse(last_response.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns Hash" do
|
66
|
+
expect(@data).to be_a_kind_of Hash
|
67
|
+
end
|
68
|
+
|
69
|
+
it "service data should contain service names" do
|
70
|
+
expect(@data['viy'].keys).to include 'SSH', 'PING'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "service data should contain service attributes" do
|
74
|
+
expect(@data['viy']['SSH']).to include 'host_name', 'service_description'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/spec/get/hosts_spec.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Nagira do
|
4
|
-
|
3
|
+
describe Nagira do
|
4
|
+
|
5
5
|
set :environment, ENV['RACK_ENV'] || :test
|
6
6
|
include Rack::Test::Methods
|
7
|
-
def app
|
7
|
+
def app
|
8
8
|
@app ||= Nagira
|
9
9
|
end
|
10
|
-
|
11
|
-
context "/_hosts" do
|
12
10
|
|
13
|
-
|
11
|
+
context "/_hosts" do
|
12
|
+
|
13
|
+
before :each do
|
14
14
|
get "/_status/_list"
|
15
15
|
@data = JSON.parse(last_response.body)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "return hosts list " do
|
19
|
-
@data.
|
19
|
+
expect(@data).to be_a_kind_of Array
|
20
20
|
end
|
21
21
|
|
22
|
-
it "hostname is a string" do
|
23
|
-
@data.first.
|
22
|
+
it "hostname is a string" do
|
23
|
+
expect(@data.first).to be_a_kind_of String
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
|
29
29
|
end
|
data/spec/get/services_spec.rb
CHANGED
@@ -4,30 +4,30 @@ require 'spec_helper'
|
|
4
4
|
#
|
5
5
|
# Endpoint checks (i.e. check HTTP success) are in endpoints_spec.rb
|
6
6
|
|
7
|
-
describe Nagira do
|
8
|
-
|
7
|
+
describe Nagira do
|
8
|
+
|
9
9
|
set :environment, ENV['RACK_ENV'] || :test
|
10
10
|
include Rack::Test::Methods
|
11
|
-
def app
|
11
|
+
def app
|
12
12
|
@app ||= Nagira
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
before :all do
|
16
16
|
get "/_status/_list.json"
|
17
17
|
@host = JSON.parse(last_response.body).first
|
18
18
|
end
|
19
19
|
|
20
|
-
context "/_hosts/:host/_services" do
|
20
|
+
context "/_hosts/:host/_services" do
|
21
21
|
|
22
|
-
before :each do
|
22
|
+
before :each do
|
23
23
|
get "/_status/#{@host}/_services"
|
24
24
|
@data = JSON.parse(last_response.body)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "return services list " do
|
28
|
-
@data.
|
28
|
+
expect(@data).to be_a_kind_of Hash
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
|
33
33
|
end
|
data/spec/put/host_spec.rb
CHANGED
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
2
2
|
require_relative 'support'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
describe Nagira do
|
6
|
-
|
5
|
+
describe Nagira do
|
6
|
+
|
7
7
|
set :environment, :test # This is potentially desctructive test, run only in test mode
|
8
8
|
include Rack::Test::Methods
|
9
|
-
def app
|
9
|
+
def app
|
10
10
|
@app ||= Nagira
|
11
11
|
end
|
12
12
|
|
13
|
-
before :all do
|
13
|
+
before :all do
|
14
14
|
get "/_status/_list.json"
|
15
15
|
@host = JSON.parse(last_response.body).first
|
16
16
|
end
|
17
17
|
|
18
18
|
let (:content_type) { {'Content-Type' => 'application/json'} }
|
19
19
|
let (:host) { @host }
|
20
|
-
let (:input) {
|
20
|
+
let (:input) {
|
21
21
|
{
|
22
|
-
"status_code" => 0,
|
23
|
-
"plugin_output" => "Plugin said: Bla"
|
22
|
+
"status_code" => 0,
|
23
|
+
"plugin_output" => "Plugin said: Bla"
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
@@ -29,13 +29,13 @@ describe Nagira do
|
|
29
29
|
#
|
30
30
|
|
31
31
|
context "/_status" do
|
32
|
-
it { pending "Not implemented" }
|
32
|
+
it { pending "Not implemented"; fail }
|
33
33
|
end # ----------- "/_status" do
|
34
34
|
|
35
35
|
context "/_status/:host_name" do
|
36
36
|
let (:url) { "/_status/#{host}"}
|
37
37
|
|
38
|
-
before (:each) do
|
38
|
+
before (:each) do
|
39
39
|
put url, input.to_json, content_type
|
40
40
|
end
|
41
41
|
|
@@ -45,13 +45,13 @@ describe Nagira do
|
|
45
45
|
input.keys.each do |key|
|
46
46
|
(inp = input.dup).delete key
|
47
47
|
put url, inp.to_json, content_type
|
48
|
-
last_response.status.
|
48
|
+
expect(last_response.status).to eq 400
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context "/_host_status/:host_name" do
|
53
|
-
it { pending "Not implemented" }
|
54
|
-
end # ----------- "/_host_status/:host_name"
|
53
|
+
it { pending "Not implemented" ; fail }
|
54
|
+
end # ----------- "/_host_status/:host_name"
|
55
55
|
|
56
56
|
|
57
57
|
end # ----------- /_status/:host
|