nagira 0.5.1 → 0.5.2
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 +11 -0
- data/Rakefile +1 -1
- data/app/app.rb +44 -298
- data/app/concerns/host_status_name_concerneable.rb +18 -0
- data/app/concerns/output_typeable.rb +22 -0
- data/app/controllers/api_help_controller.rb +25 -0
- data/app/controllers/host_status_controller.rb +82 -0
- data/{lib/nagira/hostgroup.rb → app/controllers/hostgroup_controller.rb} +1 -1
- data/app/controllers/resource_status_controler.rb +65 -0
- data/app/controllers/service_status_controler.rb +50 -0
- data/{lib/nagira/servicegroup.rb → app/controllers/servicegroups_controller.rb} +1 -1
- data/app/filters/after.rb +76 -0
- data/app/filters/before.rb +156 -0
- data/app/filters/configure.rb +34 -0
- data/app/helpers/put_helpers.rb +11 -0
- data/{lib/nagira → app/loggers}/simple_logger.rb +0 -0
- data/{lib/nagira → app/parsers}/background_parse.rb +0 -0
- data/{lib/nagira → app/parsers}/parser.rb +1 -9
- data/app/routes/get.rb +50 -0
- data/app/routes/get/config.rb +11 -0
- data/app/{get → routes/get}/objects.rb +4 -24
- data/app/routes/get/status.rb +98 -0
- data/app/{get → routes/get}/status/hostgroups.rb +3 -14
- data/app/routes/get/status/servicegroups.rb +16 -0
- data/app/{put → routes/put}/host.rb +1 -4
- data/app/{put → routes/put}/status.rb +13 -20
- data/app/writers/external_command_writer.rb +52 -0
- data/bin/nagira +1 -1
- data/config/defaults.rb +20 -12
- data/config/environment.rb +2 -1
- data/lib/nagira/timed_parse.rb +1 -1
- data/spec/01_background_parser.rb +5 -5
- data/spec/01_data_format/01_nagira_response_spec.rb +6 -6
- data/spec/01_data_format/02_0_status_spec.rb +1 -1
- data/spec/01_data_format/02_nagira_data_spec.rb +8 -8
- data/spec/01_data_format/03_api_spec.rb +3 -3
- data/spec/get/status/comments_spec.rb +2 -2
- data/spec/get/status/endpoints_spec.rb +11 -11
- data/spec/get/status/hostgroup.rb +3 -3
- data/spec/get/status/hosts_spec.rb +1 -1
- data/spec/get/status/servicegroup.rb +4 -4
- data/spec/get/status/services_spec.rb +1 -1
- data/spec/put/host_spec.rb +4 -4
- data/spec/put/status_spec.rb +5 -5
- data/spec/put/support.rb +3 -3
- data/spec/spec_helper.rb +3 -3
- data/version.txt +1 -1
- metadata +70 -60
- data/app/get/config.rb +0 -24
- data/app/get/status.rb +0 -189
- data/app/get/status/servicegroups.rb +0 -28
- data/app/put.rb +0 -53
- data/lib/nagira.rb +0 -67
data/bin/nagira
CHANGED
data/config/defaults.rb
CHANGED
@@ -12,10 +12,10 @@
|
|
12
12
|
DEFAULT = {
|
13
13
|
|
14
14
|
format_extensions: '\.(json|yaml|xml)$', # Regex for available
|
15
|
-
|
15
|
+
# formats: xml, json, yaml
|
16
16
|
|
17
17
|
format: :xml, # default format for application to send output, if
|
18
|
-
|
18
|
+
# format is not specified
|
19
19
|
|
20
20
|
|
21
21
|
# No path to file configuration file by default. Main nagios config
|
@@ -76,18 +76,26 @@ DEFAULT = {
|
|
76
76
|
|
77
77
|
}
|
78
78
|
|
79
|
-
require 'sinatra'
|
80
79
|
class Nagira < Sinatra::Base
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
81
|
+
BASE = File.dirname(__dir__).freeze
|
82
|
+
|
83
|
+
VERSION = File.read("#{BASE}/version.txt").strip.freeze
|
84
|
+
GITHUB = "http://dmytro.github.com/nagira/".freeze
|
85
|
+
##
|
86
|
+
# For every key in the DEFAULT hash create setting with the same name
|
87
|
+
# and value. Values can be overrriden in environment.rb file if
|
88
|
+
# required.
|
89
|
+
# @method define_methods_for_defaults
|
90
|
+
configure do
|
91
|
+
::DEFAULT.each do |key,val|
|
92
|
+
set key,val
|
93
|
+
end
|
90
94
|
end
|
91
|
-
end
|
92
95
|
|
96
|
+
##
|
97
|
+
# When this prefix added to routes convert output to ActiveResource
|
98
|
+
# compatible format (basically Array instead of Hash).
|
99
|
+
#
|
100
|
+
AR_PREFIX = "/ar"
|
93
101
|
end
|
data/config/environment.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'pry'
|
2
1
|
class Nagira < Sinatra::Base
|
3
2
|
|
4
3
|
|
@@ -21,6 +20,8 @@ class Nagira < Sinatra::Base
|
|
21
20
|
# Development and test environments use local files located in the
|
22
21
|
# development tree: ./test/data.
|
23
22
|
configure :development, :test do
|
23
|
+
require 'pry'
|
24
|
+
|
24
25
|
register Sinatra::Reloader
|
25
26
|
also_reload("#{root}/*.rb")
|
26
27
|
also_reload("#{root}/{config,app,lib}/**/*.rb")
|
data/lib/nagira/timed_parse.rb
CHANGED
@@ -9,7 +9,7 @@ module Nagios
|
|
9
9
|
# even if file changes often, we do not want to parse it more
|
10
10
|
# often, then this number of seconds.
|
11
11
|
|
12
|
-
TTL = ::DEFAULT[:ttl] || 0
|
12
|
+
TTL = 0# FIXME ::DEFAULT[:ttl] || 0
|
13
13
|
|
14
14
|
# Override constructor and parse method from ::Nagios::Objects or
|
15
15
|
# ::Nagios::Status classes, add instance variables to handle
|
@@ -4,23 +4,23 @@ require 'spec_helper'
|
|
4
4
|
describe "BackgroundParser" do
|
5
5
|
|
6
6
|
before {
|
7
|
-
|
8
|
-
|
7
|
+
Nagira::BackgroundParser.ttl = 1
|
8
|
+
Nagira::BackgroundParser.start = true
|
9
9
|
}
|
10
10
|
|
11
11
|
it "is configured" do
|
12
|
-
expect(
|
12
|
+
expect(Nagira::BackgroundParser).to be_configured
|
13
13
|
end
|
14
14
|
|
15
15
|
context "after start" do
|
16
16
|
|
17
17
|
before {
|
18
|
-
|
18
|
+
Nagira::BackgroundParser.run
|
19
19
|
sleep 0.1
|
20
20
|
}
|
21
21
|
|
22
22
|
it "is running" do
|
23
|
-
expect(
|
23
|
+
expect(Nagira::BackgroundParser).to be_alive
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -16,7 +16,7 @@ describe Nagira do
|
|
16
16
|
|
17
17
|
context "simple page load" do
|
18
18
|
TOP_PAGES.each do |page|
|
19
|
-
it "/#{page}
|
19
|
+
it "GET /#{page} " do
|
20
20
|
get "/#{page}"
|
21
21
|
expect(last_response).to be_ok
|
22
22
|
end
|
@@ -25,7 +25,7 @@ describe Nagira do
|
|
25
25
|
# Check 3 different formats
|
26
26
|
FORMATS.each do |format|
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "loads '#{page}.#{format}'" do
|
29
29
|
get "/#{page}.#{format}"
|
30
30
|
expect(last_response).to be_ok
|
31
31
|
end
|
@@ -53,11 +53,11 @@ describe Nagira do
|
|
53
53
|
expect(@header['Content-Type']).to match(/^application\/#{format}.*/)
|
54
54
|
end
|
55
55
|
|
56
|
-
it "body
|
56
|
+
it "body has content" do
|
57
57
|
expect(@body).to_not be_empty
|
58
58
|
end
|
59
59
|
|
60
|
-
it "#{format}
|
60
|
+
it "#{format} is parseable" do
|
61
61
|
case format
|
62
62
|
when 'json'
|
63
63
|
expect { JSON.parse @body }.not_to raise_error
|
@@ -71,8 +71,8 @@ describe Nagira do
|
|
71
71
|
|
72
72
|
end
|
73
73
|
|
74
|
-
context 'default format' do
|
75
|
-
it "/#{page}.#{Nagira.settings.format} response
|
74
|
+
context 'With the default format' do
|
75
|
+
it "/#{page}.#{Nagira.settings.format} response is the same as /#{page}" do
|
76
76
|
get "/#{page}.#{Nagira.settings.format}"
|
77
77
|
a = last_response.body
|
78
78
|
get "/#{page}"
|
@@ -27,7 +27,7 @@ describe Nagira do
|
|
27
27
|
#
|
28
28
|
# GET /objects/...
|
29
29
|
# ----------------------------------------
|
30
|
-
context "/objects" do
|
30
|
+
context "GET /objects" do
|
31
31
|
|
32
32
|
before :all do
|
33
33
|
get "/_objects"
|
@@ -39,7 +39,7 @@ describe Nagira do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
|
42
|
-
context 'hash key' do
|
42
|
+
context 'GET hash key' do
|
43
43
|
%w{host service contact timeperiod}.each do |obj|
|
44
44
|
it "objects[#{obj}] should exist" do
|
45
45
|
expect(@data[obj]).to be_a_kind_of Hash
|
@@ -48,7 +48,7 @@ describe Nagira do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
%w{host service contact timeperiod}.each do |obj|
|
51
|
-
context "/_objects/#{obj}" do
|
51
|
+
context "GET /_objects/#{obj}" do
|
52
52
|
|
53
53
|
it "should respond to HTTP resuest" do
|
54
54
|
get "/_objects/#{obj}.json"
|
@@ -69,7 +69,7 @@ describe Nagira do
|
|
69
69
|
# GET /status
|
70
70
|
# -----------------------------
|
71
71
|
|
72
|
-
context '/status' do
|
72
|
+
context 'GET /status' do
|
73
73
|
before :all do
|
74
74
|
get "/_status"
|
75
75
|
@data = JSON.parse last_response.body
|
@@ -81,16 +81,16 @@ describe Nagira do
|
|
81
81
|
@state = JSON.parse last_response.body
|
82
82
|
end
|
83
83
|
|
84
|
-
context "list of
|
85
|
-
it "full and state" do
|
84
|
+
context "Compare list of hostsnames" do
|
85
|
+
it "full and state are the same " do
|
86
86
|
expect(@data.keys).to eq @state.keys
|
87
87
|
end
|
88
88
|
|
89
|
-
it "list and state" do
|
89
|
+
it "list and state are the same " do
|
90
90
|
expect(@list).to eq @state.keys
|
91
91
|
end
|
92
92
|
|
93
|
-
it "list and data" do
|
93
|
+
it "list and data are the same " do
|
94
94
|
expect(@list).to eq @data.keys
|
95
95
|
end
|
96
96
|
end
|
@@ -13,7 +13,7 @@ describe Nagira do
|
|
13
13
|
|
14
14
|
|
15
15
|
|
16
|
-
context "API
|
16
|
+
context "GET API help" do
|
17
17
|
before :all do
|
18
18
|
get "/_api.json"
|
19
19
|
@data = JSON.parse last_response.body
|
@@ -30,11 +30,11 @@ describe Nagira do
|
|
30
30
|
METHODS.each do |method|
|
31
31
|
|
32
32
|
context method do
|
33
|
-
it "routes
|
33
|
+
it "routes are Array" do
|
34
34
|
expect(@data[method]).to be_a_kind_of Array if @data[method]
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
37
|
+
it "starts with slash" do
|
38
38
|
if @data[method]
|
39
39
|
@data[method].each do |path|
|
40
40
|
expect(path).to match( /^\//)
|
@@ -34,13 +34,13 @@ describe Nagira do
|
|
34
34
|
@host = JSON.parse(last_response.body).first
|
35
35
|
end
|
36
36
|
|
37
|
-
context "/_status/:host/_hostcomments" do
|
37
|
+
context "GET /_status/:host/_hostcomments" do
|
38
38
|
before { get "/_status/#{@host}/_hostcomments.json" }
|
39
39
|
it_should_behave_like :comment_data
|
40
40
|
end
|
41
41
|
|
42
42
|
|
43
|
-
context "/_status/:host/_servicecomments" do
|
43
|
+
context "GET /_status/:host/_servicecomments" do
|
44
44
|
before { get "/_status/#{@host}/_servicecomments.json" }
|
45
45
|
|
46
46
|
it_should_behave_like :comment_data
|
@@ -50,7 +50,7 @@ describe Nagira do
|
|
50
50
|
@app ||= Nagira
|
51
51
|
end
|
52
52
|
|
53
|
-
context "API endpoints" do
|
53
|
+
context "GET API endpoints" do
|
54
54
|
|
55
55
|
host = IMPLEMENTED[:hosts].first
|
56
56
|
hostgroup = 'all'
|
@@ -63,17 +63,17 @@ describe Nagira do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
|
66
|
-
context "/_status" do
|
66
|
+
context "GET /_status" do
|
67
67
|
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:hosts]
|
68
68
|
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:output] + ["_hosts"]
|
69
69
|
it_should_behave_like :fail_on_random_url, '/_status'
|
70
70
|
end
|
71
71
|
|
72
|
-
context "/_status/:host" do
|
72
|
+
context "GET /_status/:host" do
|
73
73
|
it_should_behave_like :respond_to_valid_url, "/_status/#{host}", IMPLEMENTED[:status]
|
74
74
|
it_should_behave_like :fail_on_random_url, "/_status/#{host}"
|
75
75
|
|
76
|
-
context "hostname with space" do
|
76
|
+
context "GET hostname with space" do
|
77
77
|
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}"
|
78
78
|
end
|
79
79
|
|
@@ -83,33 +83,33 @@ describe Nagira do
|
|
83
83
|
end
|
84
84
|
end # /_status/:host
|
85
85
|
|
86
|
-
context "/_status/:host/_services" do
|
86
|
+
context "GET /_status/:host/_services" do
|
87
87
|
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services"
|
88
88
|
it_should_behave_like :respond_to_valid_url, "/_status/#{host}/_services", ["SSH", "PING"]
|
89
89
|
|
90
|
-
context "hostname with space" do
|
90
|
+
context "GET hostname with space" do
|
91
91
|
it_should_behave_like :fail_on_bad_url, "/_status/#{spaces}/_services"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
|
96
|
-
context "custom hostname regex - host with spaces" do
|
96
|
+
context "GET custom hostname regex - host with spaces" do
|
97
97
|
|
98
98
|
it { pending "Need to figure out how to change hostname regex on the fly"; fail }
|
99
99
|
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}", nil, '\w[(%20)\w\-\.]+'
|
100
100
|
#it_should_behave_like :respond_to_valid_url, "/_status/#{spaces}/_services"
|
101
101
|
end # custom hostname regex
|
102
102
|
|
103
|
-
context "Hostgroups" do
|
103
|
+
context "GET Hostgroups" do
|
104
104
|
|
105
|
-
context "/_status/_hostgroups/:hostgroup" do
|
105
|
+
context "GET /_status/_hostgroups/:hostgroup" do
|
106
106
|
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}"
|
107
107
|
end
|
108
108
|
|
109
|
-
context "/_status/_hostgroups/:hostgroup/_service" do
|
109
|
+
context "GET /_status/_hostgroups/:hostgroup/_service" do
|
110
110
|
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}/_service"
|
111
111
|
end
|
112
|
-
context "/_status/_hostgroups/:hostgroup/_host" do
|
112
|
+
context "GET /_status/_hostgroups/:hostgroup/_host" do
|
113
113
|
it_should_behave_like :respond_to_valid_url, "/_status/_hostgroup/#{hostgroup}/_host"
|
114
114
|
end
|
115
115
|
end # Hostgroup
|
@@ -15,7 +15,7 @@ describe Nagira do
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
18
|
+
context "GET /_status/_hostgroup/@hostgroup " do
|
19
19
|
|
20
20
|
before do
|
21
21
|
get "/_status/_hostgroup/#{ @hostgroup }"
|
@@ -37,7 +37,7 @@ describe Nagira do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
|
40
|
-
context
|
40
|
+
context "GET /_status/_hostgroup/@hostgroup/_host" do
|
41
41
|
|
42
42
|
before do
|
43
43
|
get "/_status/_hostgroup/#{ @hostgroup }/_host"
|
@@ -54,7 +54,7 @@ describe Nagira do
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
-
context
|
57
|
+
context "GET /_status/_hostgroup/@hostgroup/_service" do
|
58
58
|
|
59
59
|
before do
|
60
60
|
get "/_status/_hostgroup/#{ @hostgroup }/_service"
|
@@ -11,7 +11,7 @@ describe Nagira do
|
|
11
11
|
@hosts = %w{archive kurobka airport}.sort
|
12
12
|
end
|
13
13
|
|
14
|
-
context
|
14
|
+
context "GET /_status/_servicegroup/@servicegroup " do
|
15
15
|
|
16
16
|
before do
|
17
17
|
get "/_status/_servicegroup/#{ @servicegroup }"
|
@@ -29,7 +29,7 @@ describe Nagira do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
context
|
32
|
+
context "GET /_status/_servicegroup/@servicegroup/_list" do
|
33
33
|
|
34
34
|
before do
|
35
35
|
get "/_status/_servicegroup/#{ @servicegroup }/_list"
|
@@ -46,7 +46,7 @@ describe Nagira do
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
-
context
|
49
|
+
context "GET /_status/_servicegroup/@servicegroup/_state" do
|
50
50
|
|
51
51
|
before do
|
52
52
|
get "/_status/_servicegroup/#{ @servicegroup }/_state"
|
@@ -67,7 +67,7 @@ describe Nagira do
|
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
70
|
+
context "Data completeness of GET /_status/_servicegroup/@servicegroup" do
|
71
71
|
|
72
72
|
before do
|
73
73
|
get "/_status/_servicegroup/#{ @servicegroup }"
|
data/spec/put/host_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative 'support'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "PUT hoststatus" do
|
6
6
|
|
7
7
|
dont_run_in_production(__FILE__) and break
|
8
8
|
|
@@ -29,11 +29,11 @@ describe Nagira do
|
|
29
29
|
# Tests
|
30
30
|
#
|
31
31
|
|
32
|
-
context "/_status" do
|
32
|
+
context "PUT /_status" do
|
33
33
|
it { pending "Not implemented"; fail }
|
34
34
|
end # ----------- "/_status" do
|
35
35
|
|
36
|
-
context "/_status/:host_name" do
|
36
|
+
context "PUT /_status/:host_name" do
|
37
37
|
let (:url) { "/_status/#{host}"}
|
38
38
|
|
39
39
|
before (:each) do
|
@@ -50,7 +50,7 @@ describe Nagira do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context "/_host_status/:host_name" do
|
53
|
+
context "PUT /_host_status/:host_name" do
|
54
54
|
it { pending "Not implemented" ; fail }
|
55
55
|
end # ----------- "/_host_status/:host_name"
|
56
56
|
|
data/spec/put/status_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require_relative 'support'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe "PUT service status" do
|
5
5
|
|
6
6
|
dont_run_in_production(__FILE__) and break
|
7
7
|
|
@@ -42,7 +42,7 @@ describe Nagira do
|
|
42
42
|
# Tests
|
43
43
|
#
|
44
44
|
|
45
|
-
context "/_status/:host/_services" do
|
45
|
+
context "PUT /_status/:host/_services" do
|
46
46
|
|
47
47
|
context :single do
|
48
48
|
|
@@ -87,7 +87,7 @@ describe Nagira do
|
|
87
87
|
|
88
88
|
it_should_behave_like :put_status
|
89
89
|
|
90
|
-
context "data check" do
|
90
|
+
context "PUT data check" do
|
91
91
|
subject { out["object"] }
|
92
92
|
|
93
93
|
it { expect(subject).to be_a_kind_of Array }
|
@@ -96,7 +96,7 @@ describe Nagira do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
context "/_status/:host_name/_services/:service_description" do
|
99
|
+
context "PUT /_status/:host_name/_services/:service_description" do
|
100
100
|
let(:url) { "/_status/#{host}/_services/PING" }
|
101
101
|
before do
|
102
102
|
put url, [{ return_code: 0, plugin_output: "All OK"}].to_json, content_type
|
@@ -126,7 +126,7 @@ describe Nagira do
|
|
126
126
|
# end # host does not exist
|
127
127
|
|
128
128
|
|
129
|
-
context "/_status/:host_name/_services/:service_description/_return_code/:return_code/_plugin_output/:plugin_output" do
|
129
|
+
context "PUT /_status/:host_name/_services/:service_description/_return_code/:return_code/_plugin_output/:plugin_output" do
|
130
130
|
it { pending "To be depreciated "; fail}
|
131
131
|
end
|
132
132
|
|