nagira 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fccef39db4a2a093a2f1012341d446dbd65da419
|
4
|
+
data.tar.gz: 2353f6f868237d0ac59d441c12395905af898659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f7624063fe10514a995b2d6d97445b149aa59ed25452db6aca3a6f7a36565cc286ea8a0b10da51b71d026eeea341b437740c330baa423100086ce9690135e3
|
7
|
+
data.tar.gz: 9c1e64e4ca497953d794a5016473b94a401b4ef3e40095112d183a1fe3e5df7d687583737a7a1c1d85935d2318173a85978a0a2562a945862776ae9ca59057b1
|
data/History.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### v0.4.0
|
2
|
+
* Wed Dec 24 2014 -- Dmytro Kovalov
|
3
|
+
- new API endpoints
|
4
|
+
- GET /\_status/_hosthgroup/:name
|
5
|
+
- GET /\_status/_hosthgroup/:name/_host
|
6
|
+
- GET /\_status/_hosthgroup/:name/_service
|
7
|
+
- update API docs (API.md)
|
1
8
|
|
2
9
|
### v.0.3.3
|
3
10
|
* Tue May 27 2014 -- Dmytro Kovalov
|
@@ -43,11 +50,11 @@
|
|
43
50
|
|
44
51
|
* Mon Apr 15 2013 -- Dmytro Kovalov
|
45
52
|
- Extend ActiveResource support
|
46
|
-
- add prefix /ar
|
53
|
+
- add prefix /ar
|
47
54
|
- AR_PREFIX constant for the same
|
48
55
|
- covert all output ot Array if it's ActiveResource
|
49
56
|
- ActiveResource supportewd now in /_objects, /_status
|
50
|
-
|
57
|
+
|
51
58
|
### v.0.2.6
|
52
59
|
|
53
60
|
* Tue Mar 26 2013 -- Ivan Gusev
|
@@ -69,24 +76,24 @@
|
|
69
76
|
- Add partial ActiveSupport routes
|
70
77
|
- `/_objects/host` works as well as `/_objects/hosts`
|
71
78
|
- selection objects by ID is TODO
|
72
|
-
* Feb 19, 2013 -- Dmytro Kovalov
|
73
|
-
- Background parser.
|
74
|
-
|
79
|
+
* Feb 19, 2013 -- Dmytro Kovalov
|
80
|
+
- Background parser.
|
81
|
+
|
75
82
|
To avoid delays on HTTP request from user. All data are parsed in separate thread.
|
76
83
|
- configurable TTL for background parsing
|
77
84
|
- can be disabled
|
78
|
-
- Start-up section for the Nagira app.
|
85
|
+
- Start-up section for the Nagira app.
|
79
86
|
|
80
|
-
All Nagios files are validated at start-up, rather than on first HTTP request.
|
87
|
+
All Nagios files are validated at start-up, rather than on first HTTP request.
|
81
88
|
|
82
89
|
If there are permission problem or file don't exist error is reported to user.
|
83
|
-
* Feb 9, 2013
|
90
|
+
* Feb 9, 2013
|
84
91
|
- Merge all custom changes to `ruby-nagios` into upstream, use `ruby-nagios` as gem, not git sub-module
|
85
|
-
- `nagios.cfg` file selection is in `ruby-nagios` now.
|
92
|
+
- `nagios.cfg` file selection is in `ruby-nagios` now.
|
86
93
|
|
87
94
|
Look for config in `/etc/nagios*/` and `/usr/local/nagios/etc/`. Can be overridden by `NAGIOS_CFG_FILE` environment.
|
88
|
-
|
89
|
-
### v.0.2.1
|
95
|
+
|
96
|
+
### v.0.2.1
|
90
97
|
|
91
98
|
* Wed Dec 19 2012 - Dmytro Kovalov
|
92
99
|
- fix for DOS formatted and spaces in config ; better error reporting for spec. fixes #8
|
@@ -96,49 +103,48 @@
|
|
96
103
|
- ERB template for /etc/init./d file
|
97
104
|
- Fixes for YARD formatting
|
98
105
|
- Use Travis CI for Nagira testing
|
99
|
-
* Thu Oct 4 19:45:00 JST 2012
|
106
|
+
* Thu Oct 4 19:45:00 JST 2012
|
100
107
|
|
101
108
|
### v.0.2.0
|
102
109
|
|
103
110
|
- lot of bug fixes
|
104
111
|
- API: first working PUT API for process host status and process service status external commands
|
105
112
|
* 2012-09-28 Dmytro Kovalov - v. 0.1.5
|
106
|
-
- many changes for testing files nagios.cfg, objects, status. Tested to work both in dev/test and production environments.
|
113
|
+
- many changes for testing files nagios.cfg, objects, status. Tested to work both in dev/test and production environments.
|
107
114
|
- more documentation
|
108
115
|
- API: additional modifier for output: `_full`. By default now `/_status` returns Hash with hoststatus only. Use ../_full to get both hoststatus and sevicestatus.
|
109
116
|
|
110
|
-
### v. 0.1.4
|
117
|
+
### v. 0.1.4
|
111
118
|
|
112
|
-
* 2012-09-26 Dmytro Kovalov -
|
119
|
+
* 2012-09-26 Dmytro Kovalov -
|
113
120
|
- added support for JSON-P parameters (?callback=<nam>)
|
114
121
|
- change API to have all keywords underscored, to avoid clashes with object names (`/_status`, `_objects`, `/_status/_list` etc).
|
115
122
|
|
116
|
-
### v. 0.1.3
|
123
|
+
### v. 0.1.3
|
117
124
|
|
118
|
-
* 2012-06-8 Dmytro Kovalov
|
125
|
+
* 2012-06-8 Dmytro Kovalov
|
119
126
|
- specs for /config, /status, /objects - simple page loads and data
|
120
127
|
checks;
|
121
128
|
- /api route;
|
122
129
|
- bugfixes;
|
123
130
|
- YARD documentation;
|
124
131
|
|
125
|
-
### v. 0.1.2
|
132
|
+
### v. 0.1.2
|
126
133
|
|
127
|
-
* 2012-06-2 Dmytro Kovalov
|
128
|
-
- spec for configuration files
|
134
|
+
* 2012-06-2 Dmytro Kovalov
|
135
|
+
- spec for configuration files
|
129
136
|
- spec for basic responses from Sinatra (`GET /objects`, `GET /status`)
|
130
137
|
- CONFIGURATION.rdoc
|
131
138
|
- configuration cleanup
|
132
139
|
* 2012-05-22 Dmytro Kovalov
|
133
|
-
- start using Gemfile
|
140
|
+
- start using Gemfile
|
134
141
|
- INSTALL.rdoc - simple description of installation procedure
|
135
142
|
* 2012-01-12 Dmytro Kovalov
|
136
143
|
- History.rdoc and version.txt files
|
137
144
|
- Routes for objects configuration GET's
|
138
145
|
- FEATURES.rdoc
|
139
|
-
- YARD documentation
|
146
|
+
- YARD documentation
|
140
147
|
* 2012-01-02 Dmytro Kovalov
|
141
148
|
- First Sinatra application to return service state information
|
142
149
|
* 2011-12-25 @dmytro
|
143
150
|
- Started Github project
|
144
|
-
|
data/{lib → app}/app.rb
RENAMED
@@ -51,7 +51,6 @@ require 'nagira'
|
|
51
51
|
# Nagios.
|
52
52
|
#
|
53
53
|
class Nagira < Sinatra::Base
|
54
|
-
|
55
54
|
set :app_file, __FILE__
|
56
55
|
|
57
56
|
##
|
@@ -61,7 +60,7 @@ class Nagira < Sinatra::Base
|
|
61
60
|
# @overload before("Initial Config")
|
62
61
|
configure do
|
63
62
|
|
64
|
-
$nagios = {
|
63
|
+
$nagios = { }
|
65
64
|
$nagios[:config] = Nagios::Config.new Nagira.settings.nagios_cfg
|
66
65
|
$nagios[:config].parse
|
67
66
|
|
@@ -276,12 +275,12 @@ class Nagira < Sinatra::Base
|
|
276
275
|
|
277
276
|
|
278
277
|
##
|
279
|
-
# @method argument_error
|
278
|
+
# @method argument_error
|
280
279
|
# @overload after("ArgumentError")
|
281
280
|
#
|
282
281
|
# Return 400 if result of PUT operation is not success.
|
283
282
|
#
|
284
|
-
after do
|
283
|
+
after do
|
285
284
|
return unless request.put?
|
286
285
|
halt [400, @data.send("to_#{@format}") ] if ! @data[:result]
|
287
286
|
end
|
@@ -370,6 +369,6 @@ class Nagira < Sinatra::Base
|
|
370
369
|
|
371
370
|
end
|
372
371
|
|
373
|
-
require "app/
|
374
|
-
require "app/
|
375
|
-
require "app/
|
372
|
+
require "app/put/status"
|
373
|
+
require "app/put/host"
|
374
|
+
require "app/put"
|
File without changes
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'status/hostgroups'
|
2
|
+
|
1
3
|
class Nagira < Sinatra::Base
|
2
4
|
# @!macro [attach] sinatra.get
|
3
5
|
#
|
@@ -20,16 +22,16 @@ class Nagira < Sinatra::Base
|
|
20
22
|
# @!macro [new] service_name
|
21
23
|
# @param [String] :service_name Configured Nagios service for the host
|
22
24
|
#
|
23
|
-
# @!macro [new] accepted
|
25
|
+
# @!macro [new] accepted
|
24
26
|
#
|
25
27
|
# <b>Accepted output type modifiers:</b>
|
26
28
|
#
|
27
|
-
# @!macro [new] list
|
29
|
+
# @!macro [new] list
|
28
30
|
#
|
29
31
|
# - +/_list+ : Short list of available objects, depending on the
|
30
32
|
# current request context: hosts, services, etc.
|
31
33
|
#
|
32
|
-
# @!macro [new] state
|
34
|
+
# @!macro [new] state
|
33
35
|
#
|
34
36
|
# - +/_state+ - Instead of full status information send only
|
35
37
|
# current state. For hosts up/down, for services OK, Warn,
|
@@ -37,10 +39,10 @@ class Nagira < Sinatra::Base
|
|
37
39
|
#
|
38
40
|
# @!macro [new] full
|
39
41
|
#
|
40
|
-
# - +/_full+ - Show full status information. When used in
|
41
|
-
# /_status/_full call will display full hoststaus and
|
42
|
+
# - +/_full+ - Show full status information. When used in
|
43
|
+
# /_status/_full call will display full hoststaus and
|
42
44
|
# servicestatus information for each host.
|
43
|
-
#
|
45
|
+
#
|
44
46
|
#
|
45
47
|
|
46
48
|
# Status routes
|
@@ -48,6 +50,7 @@ class Nagira < Sinatra::Base
|
|
48
50
|
|
49
51
|
##
|
50
52
|
# @method get_status_hostname_services_service_name
|
53
|
+
# @overload get("/_status/:hostname/_services/:service_name")
|
51
54
|
#
|
52
55
|
# @!macro hostname
|
53
56
|
# @!macro service_name
|
@@ -75,13 +78,13 @@ class Nagira < Sinatra::Base
|
|
75
78
|
# @method get_status_hostname_services
|
76
79
|
# @!macro hostname
|
77
80
|
#
|
78
|
-
# Endpoints:
|
81
|
+
# Endpoints:
|
79
82
|
# - GET /_status/:hostname/_services
|
80
83
|
# - GET /_status/:hostname/_hostcomments
|
81
84
|
# - GET /_status/:hostname/_servicecomments
|
82
85
|
#
|
83
86
|
# Read +services+, +hostcomments+ or +servicecomments+ for single
|
84
|
-
# host.
|
87
|
+
# host.
|
85
88
|
#
|
86
89
|
# @!macro accepted
|
87
90
|
# @!macro state
|
@@ -91,12 +94,12 @@ class Nagira < Sinatra::Base
|
|
91
94
|
|
92
95
|
hostname = hostname.to_i if hostname =~ /^\d+$/
|
93
96
|
key = case service
|
94
|
-
when 'services'
|
97
|
+
when 'services'
|
95
98
|
'servicestatus'
|
96
99
|
else
|
97
100
|
service
|
98
101
|
end
|
99
|
-
|
102
|
+
|
100
103
|
if @status && @status[hostname]
|
101
104
|
case @output
|
102
105
|
when :list
|
@@ -114,7 +117,7 @@ class Nagira < Sinatra::Base
|
|
114
117
|
##
|
115
118
|
# @method get_status
|
116
119
|
#
|
117
|
-
# Return all hosts status.
|
120
|
+
# Return all hosts status.
|
118
121
|
#
|
119
122
|
# If no output modifier provided, outputs full hosttatus information
|
120
123
|
# for each host. Not including services information. When +_full+
|
@@ -133,12 +136,12 @@ class Nagira < Sinatra::Base
|
|
133
136
|
# Support for (see API):
|
134
137
|
# - plural resources: N/A
|
135
138
|
# - object access by ID: N/A
|
136
|
-
|
139
|
+
|
137
140
|
get /^\/_status(\/_hosts)?$/ do
|
138
141
|
|
139
142
|
@data = @status.dup
|
140
143
|
|
141
|
-
case @output
|
144
|
+
case @output
|
142
145
|
when :state
|
143
146
|
@data.each { |k,v| @data[k] = v['hoststatus'].slice("host_name", "current_state") }
|
144
147
|
when :list
|
@@ -151,7 +154,7 @@ class Nagira < Sinatra::Base
|
|
151
154
|
|
152
155
|
nil
|
153
156
|
end
|
154
|
-
|
157
|
+
|
155
158
|
# Hoststatus for single host
|
156
159
|
#
|
157
160
|
# @method get_status_hostname
|
@@ -174,7 +177,7 @@ class Nagira < Sinatra::Base
|
|
174
177
|
|
175
178
|
hostname = hostname.to_i if hostname =~ /^\d+$/
|
176
179
|
@data = @status[hostname]['hoststatus'].dup if @status.has_key? hostname
|
177
|
-
|
180
|
+
|
178
181
|
if @output == :state
|
179
182
|
@data = @data.slice("host_name", "current_state")
|
180
183
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Nagira < Sinatra::Base
|
2
|
+
# @!macro [attach] sinatra.get
|
3
|
+
#
|
4
|
+
# @overload get "$1"
|
5
|
+
#
|
6
|
+
# @return HTTP response. Hash formatted in the format defined by
|
7
|
+
# requested output type(XML, YAML or JSON).
|
8
|
+
#
|
9
|
+
|
10
|
+
|
11
|
+
require 'pry'
|
12
|
+
|
13
|
+
register Sinatra::Namespace
|
14
|
+
namespace "/_status/_hostgroup" do
|
15
|
+
|
16
|
+
##
|
17
|
+
# @method get_status_hostgroup
|
18
|
+
#
|
19
|
+
# Return full status of the hostgroup: including host status and
|
20
|
+
# service status.
|
21
|
+
#
|
22
|
+
get "/:hostgroup" do |hostgroup|
|
23
|
+
@data = Hostgroup.new(hostgroup).full
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# @method get_status_hostgroup_service
|
29
|
+
#
|
30
|
+
# Endpoint:
|
31
|
+
# - GET /_status/_hostgroup/:hostgroup/_service
|
32
|
+
#
|
33
|
+
get "/:hostgroup/_service" do |hostgroup|
|
34
|
+
@data = Hostgroup.new(hostgroup).service_status
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# @method get_status_hostgroup_host
|
40
|
+
# @overload get("/_status/_hostgroup/:hostgroup/_host")
|
41
|
+
#
|
42
|
+
# Endpoint:
|
43
|
+
# - GET /_status/_hostgroup/:host
|
44
|
+
get "/:hostgroup/_host" do |hostgroup|
|
45
|
+
@data = Hostgroup.new(hostgroup).host_status
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/bin/nagira
CHANGED
@@ -4,8 +4,8 @@ begin
|
|
4
4
|
require 'app.rb'
|
5
5
|
rescue LoadError => e
|
6
6
|
require 'rubygems'
|
7
|
-
|
8
|
-
|
9
|
-
require 'app
|
7
|
+
root = File.dirname(File.dirname(__FILE__))
|
8
|
+
$: << (File.expand_path 'lib', root) << (File.expand_path 'app', root)
|
9
|
+
require 'app'
|
10
10
|
end
|
11
11
|
Nagira.run!
|
data/config/defaults.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
DEFAULT = {
|
14
|
-
|
14
|
+
|
15
15
|
format_extensions: '\.(json|yaml|xml)$', # Regex for available
|
16
16
|
# formats: xml, json, yaml
|
17
17
|
|
@@ -21,15 +21,15 @@ DEFAULT = {
|
|
21
21
|
|
22
22
|
# No path to file configuration file by default. Main nagios config
|
23
23
|
# is defined by +nagios_cfg_glob+ or by Sintra's
|
24
|
-
# +settings.nagios_cfg+ variable.
|
24
|
+
# +settings.nagios_cfg+ variable.
|
25
25
|
#
|
26
26
|
# status_cfg and objects_cfg are defined by parsing of nagios_cfg
|
27
27
|
# file. Sinatra's setting override parsed values.
|
28
|
-
nagios_cfg: nil,
|
28
|
+
nagios_cfg: nil,
|
29
29
|
status_cfg: nil,
|
30
30
|
objects_cfg: nil,
|
31
31
|
command_file: nil,
|
32
|
-
|
32
|
+
|
33
33
|
##
|
34
34
|
# ttl used in Nagios::TimedParse module - extension
|
35
35
|
# to Nagios modules.
|
@@ -40,9 +40,9 @@ DEFAULT = {
|
|
40
40
|
# if file changes often, we do not want to parse it more often, then
|
41
41
|
# this number of seconds. To disable timed parsing, set
|
42
42
|
# ttl to 0 or negative number.
|
43
|
-
|
43
|
+
|
44
44
|
ttl: ENV['NAGIRA_TTL'].to_i || 5,
|
45
|
-
|
45
|
+
|
46
46
|
##
|
47
47
|
# start_background_parser used in Nagios::BackgroundParse class.
|
48
48
|
#
|
@@ -59,13 +59,13 @@ DEFAULT = {
|
|
59
59
|
# By default hostname regular expression accepts alpha-numerics,
|
60
60
|
# dashes and dots, as specified by http://tools.ietf.org/html/rfc952
|
61
61
|
# for hostnames. Extended to accept dots in the middle for FQHN's.
|
62
|
-
#
|
62
|
+
#
|
63
63
|
#
|
64
64
|
# - default: '\w([\w\-\.]+)?\w'
|
65
65
|
# - simple hostname: '\w([\w\-]+)?\w'
|
66
|
-
# - allow space in hostname: '\w([\w\-\.(%20)]+)?\w'
|
66
|
+
# - allow space in hostname: '\w([\w\-\.(%20)]+)?\w'
|
67
67
|
#
|
68
|
-
# Explanation regarding spaces:
|
68
|
+
# Explanation regarding spaces:
|
69
69
|
# ---------------------------------
|
70
70
|
#
|
71
71
|
# Nagios works OK with hostnames with spaces. This is against RFC's
|
@@ -75,7 +75,6 @@ DEFAULT = {
|
|
75
75
|
|
76
76
|
hostname_regex: ENV['NAGIOS_HOST_CUSTOM_REGEX'] || '\w([\w\-\.]+)?\w'
|
77
77
|
|
78
|
-
|
79
78
|
}
|
80
79
|
|
81
80
|
require 'sinatra'
|
data/config/environment.rb
CHANGED
@@ -6,25 +6,24 @@ class Nagira < Sinatra::Base
|
|
6
6
|
|
7
7
|
set :port, ENV['NAGIRA_PORT'].to_i if ENV['NAGIRA_PORT']
|
8
8
|
set :bind, ENV['NAGIRA_BIND'] if ENV['NAGIRA_BIND']
|
9
|
+
set :root, File.dirname(File.dirname(__FILE__))
|
9
10
|
|
10
|
-
configure do
|
11
|
+
configure do
|
11
12
|
set :format, :json
|
12
13
|
end
|
13
14
|
|
14
|
-
if development?
|
15
|
-
require 'sinatra/reloader'
|
16
|
-
register Sinatra::Reloader
|
17
|
-
also_reload(File.dirname(File.dirname(__FILE__))+"/*.rb")
|
18
|
-
also_reload(File.dirname(File.dirname(__FILE__))+"/{app,lib}/**/*.rb")
|
19
|
-
end
|
15
|
+
require 'sinatra/reloader' if development?
|
20
16
|
|
21
17
|
##
|
22
18
|
# Development and test environments use local files located in the
|
23
19
|
# development tree: ./test/data.
|
24
|
-
configure :development, :test do
|
20
|
+
configure :development, :test do
|
21
|
+
register Sinatra::Reloader
|
22
|
+
also_reload("#{root}/*.rb")
|
23
|
+
also_reload("#{root}/{config,app,lib}/**/*.rb")
|
25
24
|
|
26
25
|
dir = File.expand_path(File.dirname(__FILE__) + '/../test/data/')
|
27
|
-
|
26
|
+
|
28
27
|
set :nagios_cfg, "#{dir}/nagios.cfg"
|
29
28
|
set :status_cfg, "#{dir}/status.dat"
|
30
29
|
set :objects_cfg, "#{dir}/objects.cache"
|
@@ -32,7 +31,7 @@ class Nagira < Sinatra::Base
|
|
32
31
|
|
33
32
|
set :show_exceptions, false
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
|
37
36
|
# configure :production do
|
38
37
|
# # If your nagios.cfg file is in 'standard' location (in RH and
|