flapjack 0.9.6 → 1.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +6 -0
  4. data/.travis.yml +20 -16
  5. data/CHANGELOG.md +11 -25
  6. data/Dockerfile +8 -0
  7. data/Gemfile +2 -5
  8. data/bin/flapjack +24 -213
  9. data/etc/flapjack_config.yaml.example +6 -30
  10. data/features/cli.feature +16 -14
  11. data/features/cli_flapjack-feed-events.feature +12 -13
  12. data/features/cli_flapjack-nagios-receiver.feature +14 -15
  13. data/features/cli_flapjack-populator.feature +16 -15
  14. data/features/cli_flapper.feature +12 -12
  15. data/features/cli_receive-events.feature +6 -5
  16. data/features/cli_simulate-failed-check.feature +7 -6
  17. data/features/steps/cli_steps.rb +2 -2
  18. data/features/support/env.rb +1 -0
  19. data/flapjack.gemspec +1 -0
  20. data/lib/flapjack/cli/flapper.rb +200 -0
  21. data/lib/flapjack/cli/import.rb +102 -0
  22. data/lib/flapjack/cli/receiver.rb +656 -0
  23. data/lib/flapjack/cli/server.rb +256 -0
  24. data/lib/flapjack/cli/simulate.rb +180 -0
  25. data/lib/flapjack/configuration.rb +2 -0
  26. data/lib/flapjack/data/entity_check.rb +5 -22
  27. data/lib/flapjack/data/event.rb +7 -12
  28. data/lib/flapjack/gateways/email.rb +4 -1
  29. data/lib/flapjack/gateways/jabber.rb +12 -36
  30. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
  31. data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
  32. data/lib/flapjack/gateways/pagerduty.rb +1 -1
  33. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
  34. data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
  35. data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
  36. data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
  37. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  38. data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
  39. data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
  40. data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
  41. data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
  42. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
  43. data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
  44. data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
  45. data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
  46. data/lib/flapjack/gateways/web/views/layout.erb +10 -10
  47. data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
  48. data/lib/flapjack/gateways/web.rb +36 -7
  49. data/lib/flapjack/pikelet.rb +0 -2
  50. data/lib/flapjack/processor.rb +3 -1
  51. data/lib/flapjack/redis_pool.rb +2 -6
  52. data/lib/flapjack/version.rb +1 -1
  53. data/spec/lib/flapjack/coordinator_spec.rb +3 -3
  54. data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
  55. data/spec/lib/flapjack/data/event_spec.rb +0 -31
  56. data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
  57. data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
  58. data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
  59. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
  60. data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
  61. data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
  62. data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
  63. data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
  64. data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
  65. data/spec/support/profile_all_formatter.rb +44 -0
  66. data/spec/support/uncolored_doc_formatter.rb +9 -0
  67. data/tasks/benchmarks.rake +0 -4
  68. metadata +28 -38
  69. data/.ruby-version +0 -1
  70. data/Gemfile-ruby1.9 +0 -28
  71. data/Gemfile-ruby1.9.lock +0 -227
  72. data/bin/flapjack-feed-events +0 -124
  73. data/bin/flapjack-nagios-receiver +0 -246
  74. data/bin/flapjack-nsca-receiver +0 -246
  75. data/bin/flapjack-populator +0 -132
  76. data/bin/flapper +0 -152
  77. data/bin/receive-events +0 -179
  78. data/bin/simulate-failed-check +0 -151
  79. data/lib/flapjack/data/migration.rb +0 -36
  80. data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
  81. data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
  82. data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
  83. data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
  84. data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
  85. data/lib/flapjack/gateways/api.rb +0 -124
  86. data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
  87. data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
  88. data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
  89. data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
  90. 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