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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +11 -0
  3. data/Rakefile +1 -1
  4. data/app/app.rb +44 -298
  5. data/app/concerns/host_status_name_concerneable.rb +18 -0
  6. data/app/concerns/output_typeable.rb +22 -0
  7. data/app/controllers/api_help_controller.rb +25 -0
  8. data/app/controllers/host_status_controller.rb +82 -0
  9. data/{lib/nagira/hostgroup.rb → app/controllers/hostgroup_controller.rb} +1 -1
  10. data/app/controllers/resource_status_controler.rb +65 -0
  11. data/app/controllers/service_status_controler.rb +50 -0
  12. data/{lib/nagira/servicegroup.rb → app/controllers/servicegroups_controller.rb} +1 -1
  13. data/app/filters/after.rb +76 -0
  14. data/app/filters/before.rb +156 -0
  15. data/app/filters/configure.rb +34 -0
  16. data/app/helpers/put_helpers.rb +11 -0
  17. data/{lib/nagira → app/loggers}/simple_logger.rb +0 -0
  18. data/{lib/nagira → app/parsers}/background_parse.rb +0 -0
  19. data/{lib/nagira → app/parsers}/parser.rb +1 -9
  20. data/app/routes/get.rb +50 -0
  21. data/app/routes/get/config.rb +11 -0
  22. data/app/{get → routes/get}/objects.rb +4 -24
  23. data/app/routes/get/status.rb +98 -0
  24. data/app/{get → routes/get}/status/hostgroups.rb +3 -14
  25. data/app/routes/get/status/servicegroups.rb +16 -0
  26. data/app/{put → routes/put}/host.rb +1 -4
  27. data/app/{put → routes/put}/status.rb +13 -20
  28. data/app/writers/external_command_writer.rb +52 -0
  29. data/bin/nagira +1 -1
  30. data/config/defaults.rb +20 -12
  31. data/config/environment.rb +2 -1
  32. data/lib/nagira/timed_parse.rb +1 -1
  33. data/spec/01_background_parser.rb +5 -5
  34. data/spec/01_data_format/01_nagira_response_spec.rb +6 -6
  35. data/spec/01_data_format/02_0_status_spec.rb +1 -1
  36. data/spec/01_data_format/02_nagira_data_spec.rb +8 -8
  37. data/spec/01_data_format/03_api_spec.rb +3 -3
  38. data/spec/get/status/comments_spec.rb +2 -2
  39. data/spec/get/status/endpoints_spec.rb +11 -11
  40. data/spec/get/status/hostgroup.rb +3 -3
  41. data/spec/get/status/hosts_spec.rb +1 -1
  42. data/spec/get/status/servicegroup.rb +4 -4
  43. data/spec/get/status/services_spec.rb +1 -1
  44. data/spec/put/host_spec.rb +4 -4
  45. data/spec/put/status_spec.rb +5 -5
  46. data/spec/put/support.rb +3 -3
  47. data/spec/spec_helper.rb +3 -3
  48. data/version.txt +1 -1
  49. metadata +70 -60
  50. data/app/get/config.rb +0 -24
  51. data/app/get/status.rb +0 -189
  52. data/app/get/status/servicegroups.rb +0 -28
  53. data/app/put.rb +0 -53
  54. data/lib/nagira.rb +0 -67
data/bin/nagira CHANGED
@@ -4,7 +4,7 @@ begin
4
4
  require 'app.rb'
5
5
  rescue LoadError => e
6
6
  require 'rubygems'
7
- root = File.dirname(File.dirname(__FILE__))
7
+ root = File.dirname(__dir__)
8
8
  $: << (File.expand_path 'lib', root) << (File.expand_path 'app', root)
9
9
  require 'app'
10
10
  end
@@ -12,10 +12,10 @@
12
12
  DEFAULT = {
13
13
 
14
14
  format_extensions: '\.(json|yaml|xml)$', # Regex for available
15
- # formats: xml, json, yaml
15
+ # formats: xml, json, yaml
16
16
 
17
17
  format: :xml, # default format for application to send output, if
18
- # format is not specified
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
- # For every key in the DEFAULT hash create setting with the same name
84
- # and value. Values can be overrriden in environment.rb file if
85
- # required.
86
- # @method define_methods_for_defaults
87
- configure do
88
- ::DEFAULT.each do |key,val|
89
- set key,val
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
@@ -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")
@@ -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
- Nagios::BackgroundParser.ttl = 1
8
- Nagios::BackgroundParser.start = true
7
+ Nagira::BackgroundParser.ttl = 1
8
+ Nagira::BackgroundParser.start = true
9
9
  }
10
10
 
11
11
  it "is configured" do
12
- expect(Nagios::BackgroundParser).to be_configured
12
+ expect(Nagira::BackgroundParser).to be_configured
13
13
  end
14
14
 
15
15
  context "after start" do
16
16
 
17
17
  before {
18
- Nagios::BackgroundParser.run
18
+ Nagira::BackgroundParser.run
19
19
  sleep 0.1
20
20
  }
21
21
 
22
22
  it "is running" do
23
- expect(Nagios::BackgroundParser).to be_alive
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} should load" do
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 "should load '#{page}.#{format}' page" do
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 should have content" do
56
+ it "body has content" do
57
57
  expect(@body).to_not be_empty
58
58
  end
59
59
 
60
- it "#{format} should be parseable" do
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 should be the same as /#{page}" do
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}"
@@ -39,7 +39,7 @@ describe Nagira do
39
39
  "/_status/_list" => Array
40
40
  }.each do |url,klas|
41
41
 
42
- it "#{url} should return #{klas}" do
42
+ it "GET #{url} returns #{klas}" do
43
43
  get "#{url}.json"
44
44
  expect(JSON.parse(last_response.body)).to be_a_kind_of klas
45
45
  end
@@ -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 hosts should be the same" do
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 data" do
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 should be an Array" do
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 "should star with slash" do
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 "/_status/_hostgroup/@hostgroup " do
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 "/_status/_hostgroup/@hostgroup/_host" do
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 "/_status/_hostgroup/@hostgroup/_service" do
57
+ context "GET /_status/_hostgroup/@hostgroup/_service" do
58
58
 
59
59
  before do
60
60
  get "/_status/_hostgroup/#{ @hostgroup }/_service"
@@ -7,7 +7,7 @@ describe Nagira do
7
7
  @app ||= Nagira
8
8
  end
9
9
 
10
- context "/_hosts" do
10
+ context "GET /_hosts" do
11
11
 
12
12
  before :each do
13
13
  get "/_status/_list"
@@ -11,7 +11,7 @@ describe Nagira do
11
11
  @hosts = %w{archive kurobka airport}.sort
12
12
  end
13
13
 
14
- context "/_status/_servicegroup/@servicegroup " do
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 "/_status/_servicegroup/@servicegroup/_list" do
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 "/_status/_servicegroup/@servicegroup/_state" do
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 "Data completeness /_status/_servicegroup/@servicegroup" do
70
+ context "Data completeness of GET /_status/_servicegroup/@servicegroup" do
71
71
 
72
72
  before do
73
73
  get "/_status/_servicegroup/#{ @servicegroup }"
@@ -16,7 +16,7 @@ describe Nagira do
16
16
  @host = JSON.parse(last_response.body).first
17
17
  end
18
18
 
19
- context "/_hosts/:host/_services" do
19
+ context "GET /_hosts/:host/_services" do
20
20
 
21
21
  before :each do
22
22
  get "/_status/#{@host}/_services"
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require_relative 'support'
3
3
  require 'pp'
4
4
 
5
- describe Nagira do
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
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require_relative 'support'
3
3
 
4
- describe Nagira do
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