flapjack 0.9.6 → 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +6 -0
- data/.travis.yml +20 -16
- data/CHANGELOG.md +11 -25
- data/Dockerfile +8 -0
- data/Gemfile +2 -5
- data/bin/flapjack +24 -213
- data/etc/flapjack_config.yaml.example +6 -30
- data/features/cli.feature +16 -14
- data/features/cli_flapjack-feed-events.feature +12 -13
- data/features/cli_flapjack-nagios-receiver.feature +14 -15
- data/features/cli_flapjack-populator.feature +16 -15
- data/features/cli_flapper.feature +12 -12
- data/features/cli_receive-events.feature +6 -5
- data/features/cli_simulate-failed-check.feature +7 -6
- data/features/steps/cli_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/cli/flapper.rb +200 -0
- data/lib/flapjack/cli/import.rb +102 -0
- data/lib/flapjack/cli/receiver.rb +656 -0
- data/lib/flapjack/cli/server.rb +256 -0
- data/lib/flapjack/cli/simulate.rb +180 -0
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/entity_check.rb +5 -22
- data/lib/flapjack/data/event.rb +7 -12
- data/lib/flapjack/gateways/email.rb +4 -1
- data/lib/flapjack/gateways/jabber.rb +12 -36
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
- data/lib/flapjack/gateways/pagerduty.rb +1 -1
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
- data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
- data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
- data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
- data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/layout.erb +10 -10
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
- data/lib/flapjack/gateways/web.rb +36 -7
- data/lib/flapjack/pikelet.rb +0 -2
- data/lib/flapjack/processor.rb +3 -1
- data/lib/flapjack/redis_pool.rb +2 -6
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +3 -3
- data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
- data/spec/lib/flapjack/data/event_spec.rb +0 -31
- data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
- data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
- data/spec/support/profile_all_formatter.rb +44 -0
- data/spec/support/uncolored_doc_formatter.rb +9 -0
- data/tasks/benchmarks.rake +0 -4
- metadata +28 -38
- data/.ruby-version +0 -1
- data/Gemfile-ruby1.9 +0 -28
- data/Gemfile-ruby1.9.lock +0 -227
- data/bin/flapjack-feed-events +0 -124
- data/bin/flapjack-nagios-receiver +0 -246
- data/bin/flapjack-nsca-receiver +0 -246
- data/bin/flapjack-populator +0 -132
- data/bin/flapper +0 -152
- data/bin/receive-events +0 -179
- data/bin/simulate-failed-check +0 -151
- data/lib/flapjack/data/migration.rb +0 -36
- data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
- data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
- data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
- data/lib/flapjack/gateways/api.rb +0 -124
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
- data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
@@ -1,124 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# A HTTP-based API server, which provides queries to determine the status of
|
4
|
-
# entities and the checks that are reported against them.
|
5
|
-
#
|
6
|
-
# There's a matching flapjack-diner gem at https://github.com/flapjack/flapjack-diner
|
7
|
-
# which consumes data from this API.
|
8
|
-
|
9
|
-
require 'time'
|
10
|
-
|
11
|
-
require 'rack/fiber_pool'
|
12
|
-
require 'sinatra/base'
|
13
|
-
|
14
|
-
require 'flapjack/rack_logger'
|
15
|
-
require 'flapjack/redis_pool'
|
16
|
-
|
17
|
-
require 'flapjack/gateways/api/rack/json_params_parser'
|
18
|
-
|
19
|
-
require 'flapjack/gateways/api/contact_methods'
|
20
|
-
require 'flapjack/gateways/api/entity_methods'
|
21
|
-
|
22
|
-
module Flapjack
|
23
|
-
|
24
|
-
module Gateways
|
25
|
-
|
26
|
-
class API < Sinatra::Base
|
27
|
-
|
28
|
-
include Flapjack::Utility
|
29
|
-
|
30
|
-
set :dump_errors, false
|
31
|
-
|
32
|
-
rescue_error = Proc.new {|status, exception, *msg|
|
33
|
-
if !msg || msg.empty?
|
34
|
-
trace = exception.backtrace.join("\n")
|
35
|
-
msg = "#{exception.class} - #{exception.message}"
|
36
|
-
msg_str = "#{msg}\n#{trace}"
|
37
|
-
else
|
38
|
-
msg_str = msg.join(", ")
|
39
|
-
end
|
40
|
-
case
|
41
|
-
when status < 500
|
42
|
-
@logger.warn "Error: #{msg_str}"
|
43
|
-
else
|
44
|
-
@logger.error "Error: #{msg_str}"
|
45
|
-
end
|
46
|
-
[status, {}, {:errors => msg}.to_json]
|
47
|
-
}
|
48
|
-
|
49
|
-
rescue_exception = Proc.new {|env, e|
|
50
|
-
case e
|
51
|
-
when Flapjack::Gateways::API::ContactNotFound
|
52
|
-
rescue_error.call(403, e, "could not find contact '#{e.contact_id}'")
|
53
|
-
when Flapjack::Gateways::API::NotificationRuleNotFound
|
54
|
-
rescue_error.call(403, e, "could not find notification rule '#{e.rule_id}'")
|
55
|
-
when Flapjack::Gateways::API::EntityNotFound
|
56
|
-
rescue_error.call(403, e, "could not find entity '#{e.entity}'")
|
57
|
-
when Flapjack::Gateways::API::EntityCheckNotFound
|
58
|
-
rescue_error.call(403, e, "could not find entity check '#{e.check}'")
|
59
|
-
else
|
60
|
-
rescue_error.call(500, e)
|
61
|
-
end
|
62
|
-
}
|
63
|
-
use Rack::FiberPool, :size => 25, :rescue_exception => rescue_exception
|
64
|
-
|
65
|
-
use Rack::MethodOverride
|
66
|
-
use Rack::JsonParamsParser
|
67
|
-
|
68
|
-
class << self
|
69
|
-
def start
|
70
|
-
@redis = Flapjack::RedisPool.new(:config => @redis_config, :size => 2)
|
71
|
-
|
72
|
-
@logger.info "starting api - class"
|
73
|
-
|
74
|
-
if @config && @config['access_log']
|
75
|
-
access_logger = Flapjack::AsyncLogger.new(@config['access_log'])
|
76
|
-
use Flapjack::CommonLogger, access_logger
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def redis
|
82
|
-
self.class.instance_variable_get('@redis')
|
83
|
-
end
|
84
|
-
|
85
|
-
def logger
|
86
|
-
self.class.instance_variable_get('@logger')
|
87
|
-
end
|
88
|
-
|
89
|
-
before do
|
90
|
-
input = nil
|
91
|
-
if logger.debug?
|
92
|
-
input = env['rack.input'].read
|
93
|
-
logger.debug("#{request.request_method} #{request.path_info}#{request.query_string} #{input}")
|
94
|
-
elsif logger.info?
|
95
|
-
input = env['rack.input'].read
|
96
|
-
input_short = input.gsub(/\n/, '').gsub(/\s+/, ' ')
|
97
|
-
logger.info("#{request.request_method} #{request.path_info}#{request.query_string} #{input_short[0..80]}")
|
98
|
-
end
|
99
|
-
env['rack.input'].rewind unless input.nil?
|
100
|
-
end
|
101
|
-
|
102
|
-
after do
|
103
|
-
logger.debug("Returning #{response.status} for #{request.request_method} #{request.path_info}#{request.query_string}")
|
104
|
-
end
|
105
|
-
|
106
|
-
register Flapjack::Gateways::API::EntityMethods
|
107
|
-
register Flapjack::Gateways::API::ContactMethods
|
108
|
-
|
109
|
-
not_found do
|
110
|
-
err(404, "not routable")
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def err(status, *msg)
|
116
|
-
msg_str = msg.join(", ")
|
117
|
-
logger.info "Error: #{msg_str}"
|
118
|
-
[status, {}, {:errors => msg}.to_json]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|