nagira 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +9 -0
- data/lib/app/routes/get/status.rb +22 -7
- data/lib/app/routes/put/host.rb +1 -1
- data/spec/get/comments_spec.rb +57 -0
- data/spec/get/endpoints_spec.rb +72 -0
- data/spec/put/host_spec.rb +34 -27
- data/spec/put/support.rb +1 -2
- data/spec/spec_helper.rb +9 -0
- data/test/data/status.dat +27 -0
- data/version.txt +1 -1
- metadata +4 -3
- data/lib/nagira/version.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a336625df06fa45529696e6c76a24a514c658acc
|
4
|
+
data.tar.gz: 06c24925a8f55086540c180432c78a16012c9bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea2dbe47313fa3f3b1a5ca50e328cff6e35df7869918fea89022a7ccb1856a54cab7a62bf123406d681394bb9bf9a735bbd140892fa6fee3b3a83d8ef0fd3ccd
|
7
|
+
data.tar.gz: 9008b71560d0196af7130b684d814d3512a22a6c694d2b966f6932841e5fc8703ddaf73fe53de514a1167b48304a011655eea8e5c33e059525c5b0b0e5d974eb
|
data/History.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### v.0.2.12
|
2
|
+
* Thr Aug 08 2013 -- Dmytro Kovalov
|
3
|
+
- Implementation for GET comments endpoints:
|
4
|
+
- /_status/:hostname/_services
|
5
|
+
- /_status/:hostname/_hostcomments
|
6
|
+
- /_status/:hostname/_servicecomments
|
7
|
+
* July, Aug 2013
|
8
|
+
- RSpec tests
|
9
|
+
- GET endpoints checks
|
1
10
|
### v.0.2.10, v.0.2.11
|
2
11
|
* Fri Jul 19 2013 -- Dmytro Kovalov
|
3
12
|
- Gem versions fixes in gemspec, use gemspec in Gemfile.
|
@@ -60,7 +60,6 @@ class Nagira < Sinatra::Base
|
|
60
60
|
#
|
61
61
|
get "/_status/:hostname/_services/:service_name" do |hostname,service|
|
62
62
|
|
63
|
-
|
64
63
|
hostname = hostname.to_i if hostname =~ /^\d+$/
|
65
64
|
if @status && @status[hostname]
|
66
65
|
if @output == :state
|
@@ -76,23 +75,36 @@ class Nagira < Sinatra::Base
|
|
76
75
|
# @method get_status_hostname_services
|
77
76
|
# @!macro hostname
|
78
77
|
#
|
79
|
-
#
|
78
|
+
# Endpoints:
|
79
|
+
# - GET /_status/:hostname/_services
|
80
|
+
# - GET /_status/:hostname/_hostcomments
|
81
|
+
# - GET /_status/:hostname/_servicecomments
|
82
|
+
#
|
83
|
+
# Read +services+, +hostcomments+ or +servicecomments+ for single
|
84
|
+
# host.
|
80
85
|
#
|
81
86
|
# @!macro accepted
|
82
87
|
# @!macro state
|
83
88
|
# @!macro list
|
84
89
|
# @!macro full
|
85
|
-
get
|
90
|
+
get %r{^/_status/(?<hostname>[\w\-\.]+)/_(?<service>(services|hostcomments|servicecomments))$} do |hostname,service|
|
86
91
|
|
87
92
|
hostname = hostname.to_i if hostname =~ /^\d+$/
|
93
|
+
key = case service
|
94
|
+
when 'services'
|
95
|
+
'servicestatus'
|
96
|
+
else
|
97
|
+
service
|
98
|
+
end
|
99
|
+
|
88
100
|
if @status && @status[hostname]
|
89
101
|
case @output
|
90
102
|
when :list
|
91
|
-
@data = @status[hostname][
|
103
|
+
@data = @status[hostname][key].keys
|
92
104
|
when :state
|
93
105
|
@data = @status.each { |k,v| @data[k] = v.slice("host_name", "service_description", "current_state") }
|
94
106
|
else
|
95
|
-
@data = @status[hostname][
|
107
|
+
@data = @status[hostname][key]
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
@@ -104,7 +116,10 @@ class Nagira < Sinatra::Base
|
|
104
116
|
#
|
105
117
|
# Return all hosts status.
|
106
118
|
#
|
107
|
-
# If no output modifier provided, outputs full hosttatus information
|
119
|
+
# If no output modifier provided, outputs full hosttatus information
|
120
|
+
# for each host. Not including services information. When +_full+
|
121
|
+
# modifier is provided data include hoststatus, servicestatus and
|
122
|
+
# all comments (servicecomments and hostcomments) for hosts.
|
108
123
|
#
|
109
124
|
# Alias: get /_status is the same thing as get /_status/_hosts with
|
110
125
|
# ActiveResource compatibility, i.e. for */_hosts request Nagira
|
@@ -119,7 +134,7 @@ class Nagira < Sinatra::Base
|
|
119
134
|
# - plural resources: N/A
|
120
135
|
# - object access by ID: N/A
|
121
136
|
|
122
|
-
get /^\/_status(\/_hosts)
|
137
|
+
get /^\/_status(\/_hosts)?$/ do
|
123
138
|
|
124
139
|
@data = @status.dup
|
125
140
|
|
data/lib/app/routes/put/host.rb
CHANGED
@@ -22,7 +22,7 @@ class Nagira < Sinatra::Base
|
|
22
22
|
# $ curl -i -H "Accept: application/json" -d @host.json -X
|
23
23
|
# PUT http://localhost:4567/_status/svaroh
|
24
24
|
#
|
25
|
-
# => {"
|
25
|
+
# => {"result": true, "object": [{"data": {"host_name":"svaroh",
|
26
26
|
# "status_code": "0", "plugin_output": "ping OK", "action":
|
27
27
|
# "PROCESS_HOST_CHECK_RESULT"}, "result":true, "messages": []}]}
|
28
28
|
#
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
shared_examples_for :comment_data do
|
5
|
+
|
6
|
+
let(:data) { JSON.parse(last_response.body) }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
case data
|
10
|
+
when Array
|
11
|
+
data.first
|
12
|
+
when Hash
|
13
|
+
data.values.first.first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it { should be_a_kind_of Hash }
|
18
|
+
it { should have_key 'comment_id' }
|
19
|
+
it { should have_key 'comment_data' }
|
20
|
+
it { should have_key 'author' }
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe Nagira do
|
26
|
+
|
27
|
+
set :environment, ENV['RACK_ENV'] || :test
|
28
|
+
include Rack::Test::Methods
|
29
|
+
def app
|
30
|
+
@app ||= Nagira
|
31
|
+
end
|
32
|
+
|
33
|
+
before :all do
|
34
|
+
get "/_status/_list.json"
|
35
|
+
@host = JSON.parse(last_response.body).first
|
36
|
+
end
|
37
|
+
|
38
|
+
context "/_status/:host/_hostcomments" do
|
39
|
+
before { get "/_status/#{@host}/_hostcomments.json" }
|
40
|
+
it_should_behave_like :comment_data
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
context "/_status/:host/_servicecomments" do
|
45
|
+
before { get "/_status/#{@host}/_servicecomments.json" }
|
46
|
+
|
47
|
+
it_should_behave_like :comment_data
|
48
|
+
|
49
|
+
let (:data) { JSON.parse(last_response.body).values.first.first }
|
50
|
+
it { data.should have_key 'service_description' }
|
51
|
+
it { data.should have_key 'host_name' }
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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|
|
18
|
+
urls.each do |url|
|
19
|
+
ep = "#{base}/#{url}"
|
20
|
+
it "responds to #{ep}" do
|
21
|
+
get ep
|
22
|
+
last_response.should be_ok
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_examples_for :fail_on_bad_url do |url|
|
28
|
+
before { get url }
|
29
|
+
it "fails on #{url}" do
|
30
|
+
last_response.status.should be 404
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Nagira do
|
35
|
+
|
36
|
+
set :environment, :test # This should run only in test mode as it uses hardcoded host names
|
37
|
+
include Rack::Test::Methods
|
38
|
+
def app
|
39
|
+
@app ||= Nagira
|
40
|
+
end
|
41
|
+
|
42
|
+
context "API endpoints" do
|
43
|
+
|
44
|
+
host = IMPLEMENTED[:hosts].first
|
45
|
+
|
46
|
+
context :top do
|
47
|
+
it_should_behave_like :respond_to_valid_url, '', IMPLEMENTED[:top]
|
48
|
+
it_should_behave_like :fail_on_random_url, ''
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
context "/_status" do
|
53
|
+
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:hosts]
|
54
|
+
it_should_behave_like :respond_to_valid_url, "/_status", IMPLEMENTED[:output] + ["_hosts"]
|
55
|
+
it_should_behave_like :fail_on_random_url, '/_status'
|
56
|
+
end
|
57
|
+
|
58
|
+
context "/_status/:host" do
|
59
|
+
it_should_behave_like :respond_to_valid_url, "/_status/#{host}", IMPLEMENTED[:status]
|
60
|
+
it_should_behave_like :fail_on_random_url, "/_status/#{host}"
|
61
|
+
|
62
|
+
context :unknown_host do
|
63
|
+
it_should_behave_like :fail_on_bad_url, '/_status/unknown_host'
|
64
|
+
it_should_behave_like :fail_on_random_url, "/_status/unknown_host"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end # API endpoints
|
70
|
+
|
71
|
+
|
72
|
+
end
|
data/spec/put/host_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require_relative 'support'
|
3
|
+
require 'pp'
|
2
4
|
|
3
5
|
describe Nagira do
|
4
6
|
|
@@ -8,45 +10,50 @@ describe Nagira do
|
|
8
10
|
@app ||= Nagira
|
9
11
|
end
|
10
12
|
|
11
|
-
let (:content_type) { {'Content-Type' => 'application/json'} }
|
12
|
-
|
13
13
|
before :all do
|
14
|
-
|
14
|
+
get "/_status/_list.json"
|
15
|
+
@host = JSON.parse(last_response.body).first
|
16
|
+
end
|
17
|
+
|
18
|
+
let (:content_type) { {'Content-Type' => 'application/json'} }
|
19
|
+
let (:host) { @host }
|
20
|
+
let (:input) {
|
21
|
+
{
|
15
22
|
"status_code" => 0,
|
16
23
|
"plugin_output" => "Plugin said: Bla"
|
17
24
|
}
|
25
|
+
}
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
# --------------------------------------------
|
28
|
+
# Tests
|
29
|
+
#
|
21
30
|
|
22
|
-
|
31
|
+
context "/_status" do
|
32
|
+
it { pending "Not implemented" }
|
33
|
+
end # ----------- "/_status" do
|
23
34
|
|
24
|
-
context "
|
25
|
-
let (:url) { "/_status/#{
|
26
|
-
|
27
|
-
context "single check" do
|
28
|
-
|
29
|
-
it "with no hostname" do
|
30
|
-
pending
|
31
|
-
# put url, @data, content_type
|
32
|
-
|
33
|
-
# pp [url, @data, last_response.body]
|
34
|
-
# last_response.should be_ok
|
35
|
-
end
|
35
|
+
context "/_status/:host_name" do
|
36
|
+
let (:url) { "/_status/#{host}"}
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
last_response.should_not be_ok
|
41
|
-
end
|
38
|
+
before (:each) do
|
39
|
+
put url, input.to_json, content_type
|
40
|
+
end
|
42
41
|
|
42
|
+
it_should_behave_like :put_status
|
43
43
|
|
44
|
+
it "should fail with missing data" do
|
45
|
+
input.keys.each do |key|
|
46
|
+
(inp = input.dup).delete key
|
47
|
+
put url, inp.to_json, content_type
|
48
|
+
last_response.status.should eq 400
|
49
|
+
end
|
44
50
|
end
|
45
51
|
|
46
|
-
|
47
|
-
pending
|
48
|
-
end
|
52
|
+
context "/_host_status/:host_name" do
|
53
|
+
it { pending "Not implemented" }
|
54
|
+
end # ----------- "/_host_status/:host_name"
|
55
|
+
|
49
56
|
|
50
|
-
end # /_status/:host
|
57
|
+
end # ----------- /_status/:host
|
51
58
|
|
52
59
|
end
|
data/spec/put/support.rb
CHANGED
@@ -38,7 +38,6 @@ shared_examples_for :json_success_response do
|
|
38
38
|
end
|
39
39
|
subject { @ret }
|
40
40
|
|
41
|
-
#it { subject.}
|
42
41
|
end
|
43
42
|
|
44
43
|
shared_examples_for :write_to_nagios_cmd_file do
|
@@ -49,7 +48,7 @@ shared_examples_for :write_to_nagios_cmd_file do
|
|
49
48
|
|
50
49
|
it "writes to nagios.cmd file" do
|
51
50
|
File.should exist(cmd)
|
52
|
-
File.read(cmd).should =~ /^\[\d+\]
|
51
|
+
File.read(cmd).should =~ /^\[\d+\] PROCESS_(SERVICE|HOST)_CHECK_RESULT;#{host}/
|
53
52
|
end
|
54
53
|
|
55
54
|
after (:each) do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,3 +2,12 @@ $: << File.dirname(__FILE__) + '/../lib/'
|
|
2
2
|
require_relative '../lib/nagira.rb'
|
3
3
|
require_relative '../lib/app.rb'
|
4
4
|
require 'rack/test'
|
5
|
+
|
6
|
+
IMPLEMENTED = {
|
7
|
+
top: %w{ _api _status _objects _config _runtime},
|
8
|
+
output: %w{ _list _state _full }, # Type of requests as in varaible @output
|
9
|
+
hosts: %w{ archive tv },
|
10
|
+
status: %w{ _services _servicecomments _hostcomments }
|
11
|
+
}
|
12
|
+
|
13
|
+
RANDOM = %w{ _bla _foo bla foo ahdhjdjda }
|
data/test/data/status.dat
CHANGED
@@ -1650,3 +1650,30 @@ contactstatus {
|
|
1650
1650
|
service_notifications_enabled=1
|
1651
1651
|
}
|
1652
1652
|
|
1653
|
+
servicecomment {
|
1654
|
+
host_name=archive
|
1655
|
+
service_description=Disk space
|
1656
|
+
entry_type=4
|
1657
|
+
comment_id=38
|
1658
|
+
source=0
|
1659
|
+
persistent=0
|
1660
|
+
entry_time=1373457035
|
1661
|
+
expires=0
|
1662
|
+
expire_time=0
|
1663
|
+
author=dmytro
|
1664
|
+
comment_data=Need to verify what to delete.
|
1665
|
+
}
|
1666
|
+
|
1667
|
+
hostcomment {
|
1668
|
+
host_name=archive
|
1669
|
+
entry_type=1
|
1670
|
+
comment_id=40
|
1671
|
+
source=1
|
1672
|
+
persistent=1
|
1673
|
+
entry_time=1375778132
|
1674
|
+
expires=0
|
1675
|
+
expire_time=0
|
1676
|
+
author=dmytro
|
1677
|
+
comment_data=Testing Host Comment --dk
|
1678
|
+
}
|
1679
|
+
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.12
|
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.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Kovalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -292,13 +292,14 @@ files:
|
|
292
292
|
- lib/nagira/background_parse.rb
|
293
293
|
- lib/nagira/nagios.rb
|
294
294
|
- lib/nagira/timed_parse.rb
|
295
|
-
- lib/nagira/version.rb
|
296
295
|
- lib/nagira.rb
|
297
296
|
- spec/00_configuration_spec.rb
|
298
297
|
- spec/01_data_format/01_nagira_response_spec.rb
|
299
298
|
- spec/01_data_format/02_0_status_spec.rb
|
300
299
|
- spec/01_data_format/02_nagira_data_spec.rb
|
301
300
|
- spec/01_data_format/03_api_spec.rb
|
301
|
+
- spec/get/comments_spec.rb
|
302
|
+
- spec/get/endpoints_spec.rb
|
302
303
|
- spec/get/hosts_spec.rb
|
303
304
|
- spec/get/services_spec.rb
|
304
305
|
- spec/put/host_spec.rb
|
data/lib/nagira/version.rb
DELETED