-
Notifications
You must be signed in to change notification settings - Fork 0
/
nagios_status.rb
46 lines (35 loc) · 972 Bytes
/
nagios_status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$:.unshift File.join File.dirname(__FILE__), 'nagios_status'
%w[yaml json status sinatra/base].each {|l| require l}
module NagiosStatus
class App < Sinatra::Base
set :nagios_status, Status.new
before do
content_type 'application/json'
end
get '/' do
settings.nagios_status.status.to_json
end
get '/hosts' do
settings.nagios_status.hosts.to_json
end
get '/hosts/:key/:value' do
settings.nagios_status.hosts.select do |node|
node[params[:key]].to_s == params[:value]
end.to_json
end
get '/services' do
settings.nagios_status.services.to_json
end
get '/services/:key/:value' do
settings.nagios_status.services.select do |service|
service[params[:key]].to_s == params[:value]
end.to_json
end
get '/programs' do
settings.nagios_status.programs.to_json
end
get '/info' do
settings.nagios_status.info.to_json
end
end
end