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/app/get/status.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
require_relative 'status/hostgroups'
|
2
|
-
require_relative 'status/servicegroups'
|
3
|
-
|
4
|
-
class Nagira < Sinatra::Base
|
5
|
-
# @!macro [attach] sinatra.get
|
6
|
-
#
|
7
|
-
# @overload get "$1"
|
8
|
-
#
|
9
|
-
# @return HTTP response. Hash formatted in the format defined by
|
10
|
-
# requested output type(XML, YAML or JSON).
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @!macro [new] type
|
15
|
-
# @param [String] :type Type is one of Nagios objects like hosts, hostgroupsroups, etc.
|
16
|
-
#
|
17
|
-
# @!macro [new] name
|
18
|
-
# @param [String] :name
|
19
|
-
#
|
20
|
-
# @!macro [new] hostname
|
21
|
-
# @param [String] :hostname Configured Nagios hostname
|
22
|
-
#
|
23
|
-
# @!macro [new] service_name
|
24
|
-
# @param [String] :service_name Configured Nagios service for the host
|
25
|
-
#
|
26
|
-
# @!macro [new] accepted
|
27
|
-
#
|
28
|
-
# <b>Accepted output type modifiers:</b>
|
29
|
-
#
|
30
|
-
# @!macro [new] list
|
31
|
-
#
|
32
|
-
# - +/_list+ : Short list of available objects, depending on the
|
33
|
-
# current request context: hosts, services, etc.
|
34
|
-
#
|
35
|
-
# @!macro [new] state
|
36
|
-
#
|
37
|
-
# - +/_state+ - Instead of full status information send only
|
38
|
-
# current state. For hosts up/down, for services OK, Warn,
|
39
|
-
# Critical, Unknown (0,1,2-1)
|
40
|
-
#
|
41
|
-
# @!macro [new] full
|
42
|
-
#
|
43
|
-
# - +/_full+ - Show full status information. When used in
|
44
|
-
# /_status/_full call will display full hoststaus and
|
45
|
-
# servicestatus information for each host.
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
# Status routes
|
50
|
-
# ============================================================
|
51
|
-
|
52
|
-
##
|
53
|
-
# @method get_status_hostname_services_service_name
|
54
|
-
# @overload get("/_status/:hostname/_services/:service_name")
|
55
|
-
#
|
56
|
-
# @!macro hostname
|
57
|
-
# @!macro service_name
|
58
|
-
#
|
59
|
-
# Full or short status information for single service on single
|
60
|
-
# host.
|
61
|
-
#
|
62
|
-
# @!macro accepted
|
63
|
-
# @!macro state
|
64
|
-
#
|
65
|
-
get "/_status/:hostname/_services/:service_name" do |hostname,service|
|
66
|
-
|
67
|
-
hostname = hostname.to_i if hostname =~ /^\d+$/
|
68
|
-
if @status && @status[hostname]
|
69
|
-
if @output == :state
|
70
|
-
@data = @status[hostname]['servicestatus'][service].slice("hostname", "service_description", "current_state")
|
71
|
-
else
|
72
|
-
@data = @status[hostname]['servicestatus'][service]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
nil
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# @method get_status_hostname_services
|
80
|
-
# @!macro hostname
|
81
|
-
#
|
82
|
-
# Endpoints:
|
83
|
-
# - GET /_status/:hostname/_services
|
84
|
-
# - GET /_status/:hostname/_hostcomments
|
85
|
-
# - GET /_status/:hostname/_servicecomments
|
86
|
-
#
|
87
|
-
# Read +services+, +hostcomments+ or +servicecomments+ for single
|
88
|
-
# host.
|
89
|
-
#
|
90
|
-
# @!macro accepted
|
91
|
-
# @!macro state
|
92
|
-
# @!macro list
|
93
|
-
# @!macro full
|
94
|
-
get %r{^/_status/(?<hostname>#{hostname_regex})/_(?<service>(services|hostcomments|servicecomments))$} do |hostname,service|
|
95
|
-
|
96
|
-
hostname = hostname.to_i if hostname =~ /^\d+$/
|
97
|
-
key = case service
|
98
|
-
when 'services'
|
99
|
-
'servicestatus'
|
100
|
-
else
|
101
|
-
service
|
102
|
-
end
|
103
|
-
|
104
|
-
if @status && @status[hostname]
|
105
|
-
case @output
|
106
|
-
when :list
|
107
|
-
@data = @status[hostname][key].keys
|
108
|
-
when :state
|
109
|
-
@data = @status.each { |k,v| @data[k] = v.slice("host_name", "service_description", "current_state") }
|
110
|
-
else
|
111
|
-
@data = @status[hostname][key]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
nil
|
116
|
-
end
|
117
|
-
|
118
|
-
##
|
119
|
-
# @method get_status
|
120
|
-
#
|
121
|
-
# Return all hosts status.
|
122
|
-
#
|
123
|
-
# If no output modifier provided, outputs full hosttatus information
|
124
|
-
# for each host. Not including services information. When +_full+
|
125
|
-
# modifier is provided data include hoststatus, servicestatus and
|
126
|
-
# all comments (servicecomments and hostcomments) for hosts.
|
127
|
-
#
|
128
|
-
# Alias: get /_status is the same thing as get /_status/_hosts with
|
129
|
-
# ActiveResource compatibility, i.e. for */_hosts request Nagira
|
130
|
-
# returns array instead of hash.
|
131
|
-
#
|
132
|
-
# @!macro accepted
|
133
|
-
# @!macro state
|
134
|
-
# @!macro list
|
135
|
-
# @!macro full
|
136
|
-
#
|
137
|
-
# Support for (see API):
|
138
|
-
# - plural resources: N/A
|
139
|
-
# - object access by ID: N/A
|
140
|
-
|
141
|
-
get /^\/_status(\/_hosts)?$/ do
|
142
|
-
|
143
|
-
@data = @status.dup
|
144
|
-
|
145
|
-
case @output
|
146
|
-
when :state
|
147
|
-
@data.each { |k,v| @data[k] = v['hoststatus'].slice("host_name", "current_state") }
|
148
|
-
when :list
|
149
|
-
@data = @data.keys
|
150
|
-
when :full
|
151
|
-
@data
|
152
|
-
else
|
153
|
-
@data.each { |k,v| @data[k] = v['hoststatus'] }
|
154
|
-
end
|
155
|
-
|
156
|
-
nil
|
157
|
-
end
|
158
|
-
|
159
|
-
# Hoststatus for single host
|
160
|
-
#
|
161
|
-
# @method get_status_hostname
|
162
|
-
#
|
163
|
-
# Endpoint
|
164
|
-
#
|
165
|
-
# - get "/_status/:hostname"
|
166
|
-
#
|
167
|
-
# @!macro hostname
|
168
|
-
#
|
169
|
-
# @!macro accepted
|
170
|
-
# @!macro state
|
171
|
-
#
|
172
|
-
# Support for:
|
173
|
-
# - plural resources: N/A
|
174
|
-
# - object access by ID: NO (TODO)
|
175
|
-
|
176
|
-
get %r{^/_status/(?<hostname>#{hostname_regex})$} do |hostname|
|
177
|
-
|
178
|
-
|
179
|
-
hostname = hostname.to_i if hostname =~ /^\d+$/
|
180
|
-
@data = @status[hostname]['hoststatus'].dup if @status.has_key? hostname
|
181
|
-
|
182
|
-
if @output == :state
|
183
|
-
@data = @data.slice("host_name", "current_state")
|
184
|
-
end
|
185
|
-
|
186
|
-
nil
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
@@ -1,28 +0,0 @@
|
|
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
|
-
##
|
12
|
-
# @method get_status_servicegroup
|
13
|
-
#
|
14
|
-
# Endpoint:
|
15
|
-
# - GET /_status/_servicegroup/:servicegroup
|
16
|
-
#
|
17
|
-
# Supported extensions: _state, _list
|
18
|
-
#
|
19
|
-
|
20
|
-
get "/_status/_servicegroup/:servicegroup" do |group_name|
|
21
|
-
|
22
|
-
servicegroup = Servicegroup.new(group_name)
|
23
|
-
|
24
|
-
@data = servicegroup.send(@output)
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/app/put.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
class Nagira < Sinatra::Base
|
2
|
-
|
3
|
-
# @method parse_input_data
|
4
|
-
# @overload before("Parse PUT request body")
|
5
|
-
#
|
6
|
-
# Process the data before on each HTTP request.
|
7
|
-
#
|
8
|
-
# @return [Array] @input Sets @input instance variable.
|
9
|
-
#
|
10
|
-
before do
|
11
|
-
if request.put?
|
12
|
-
data = request.body.read
|
13
|
-
@input = case @format
|
14
|
-
when :json then JSON.parse data
|
15
|
-
when :xml then Hash.from_xml data
|
16
|
-
when :yaml then YAML.load data
|
17
|
-
end
|
18
|
-
# Make sure we always return an Array
|
19
|
-
@input = [@input] if @input.is_a? Hash
|
20
|
-
end
|
21
|
-
@input
|
22
|
-
end
|
23
|
-
|
24
|
-
# Define helpers for put methods
|
25
|
-
helpers do
|
26
|
-
|
27
|
-
# Helper to send PUT update to Nagios::ExternalCommands
|
28
|
-
#
|
29
|
-
# @param [Hash] params
|
30
|
-
# @param [Symbol] action Nagios external command name
|
31
|
-
#
|
32
|
-
# FIXME: This only accepts single service. Modify to use Arrays too
|
33
|
-
def put_update action, params
|
34
|
-
res = Parser.commands.write(params.merge({ :action => action }))
|
35
|
-
{ :result => res[:result], :object => res[:data]}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Small helper to submit data to ::Nagios::ExternalCommands
|
40
|
-
# object. For status updates sends external coond via
|
41
|
-
# ::Nagios::ExternalCommands.send method.
|
42
|
-
def update_service_status params
|
43
|
-
put_update :PROCESS_SERVICE_CHECK_RESULT, params
|
44
|
-
end
|
45
|
-
|
46
|
-
# Small helper to submit data to ::Nagios::ExternalCommands
|
47
|
-
# object. For host status updates sends external command via
|
48
|
-
# ::Nagios::ExternalCommands.write method.
|
49
|
-
def update_host_status params
|
50
|
-
put_update :PROCESS_HOST_CHECK_RESULT, params
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/lib/nagira.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'active_model/serialization'
|
2
|
-
require 'active_model/serializers/xml' # for Hash.to_xml
|
3
|
-
|
4
|
-
require 'active_support/inflector'
|
5
|
-
require 'active_support/inflector/inflections'
|
6
|
-
require 'active_support/core_ext/hash/slice' # for Hash.slice
|
7
|
-
|
8
|
-
require 'json'
|
9
|
-
require 'yaml'
|
10
|
-
require 'sinatra'
|
11
|
-
require 'sinatra/reloader'
|
12
|
-
require 'singleton'
|
13
|
-
|
14
|
-
$: << File.dirname(__FILE__) << File.dirname(File.dirname(__FILE__))
|
15
|
-
|
16
|
-
require 'config/defaults'
|
17
|
-
|
18
|
-
require "app/get/config"
|
19
|
-
require "app/get/objects"
|
20
|
-
require "app/get/status"
|
21
|
-
|
22
|
-
require "nagira/hostgroup"
|
23
|
-
require "nagira/servicegroup"
|
24
|
-
require "nagira/hostservice"
|
25
|
-
|
26
|
-
require "nagira/background_parse"
|
27
|
-
require "nagira/parser"
|
28
|
-
require "nagira/simple_logger"
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
# environment file must go after default, some settings override
|
33
|
-
# defaults.
|
34
|
-
#
|
35
|
-
require 'config/environment'
|
36
|
-
require 'nagira/nagios'
|
37
|
-
|
38
|
-
class Nagira < Sinatra::Base
|
39
|
-
|
40
|
-
VERSION = File.read(File.expand_path(File.dirname(__FILE__)) + '/../version.txt').strip
|
41
|
-
GITHUB = "http://dmytro.github.com/nagira/"
|
42
|
-
|
43
|
-
##
|
44
|
-
# When this prefix added to routes convert output to ActiveResource
|
45
|
-
# compatible format (basically Array instead of Hash).
|
46
|
-
#
|
47
|
-
AR_PREFIX = "/ar"
|
48
|
-
|
49
|
-
# Get all routes that Nagira provides.
|
50
|
-
def api
|
51
|
-
api = { }
|
52
|
-
|
53
|
-
param_regex = Regexp.new '\(\[\^\\\\\/\?\#\]\+\)'
|
54
|
-
Nagira.routes.keys.each do |method|
|
55
|
-
api[method] ||= []
|
56
|
-
Nagira.routes[method].each do |r|
|
57
|
-
path = r[0].inspect[3..-3]
|
58
|
-
r[1].each do |parm|
|
59
|
-
path.sub!(param_regex,":#{parm}")
|
60
|
-
end
|
61
|
-
path.gsub!('\\','')
|
62
|
-
api[method] << path unless path.empty?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
api
|
66
|
-
end
|
67
|
-
end
|