flapjack 0.7.18 → 0.7.19
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/bin/flapjack +3 -0
- data/bin/flapjack-nagios-receiver +4 -1
- data/bin/flapjack-netsaint-parser +2 -1
- data/bin/flapjack-populator +6 -3
- data/bin/receive-events +3 -1
- data/bin/simulate-failed-check +2 -1
- data/etc/flapjack_config.yaml.example +20 -0
- data/features/events.feature +1 -1
- data/features/events_check_names.feature +1 -1
- data/features/notification_rules.feature +1 -1
- data/features/notifications.feature +1 -1
- data/features/steps/events_steps.rb +18 -17
- data/features/steps/flapjack-netsaint-parser_steps.rb +1 -2
- data/features/steps/notifications_steps.rb +14 -1
- data/features/support/env.rb +27 -10
- data/flapjack.gemspec +1 -3
- data/lib/flapjack/coordinator.rb +30 -20
- data/lib/flapjack/data/contact.rb +3 -2
- data/lib/flapjack/data/entity.rb +3 -3
- data/lib/flapjack/data/entity_check.rb +116 -43
- data/lib/flapjack/data/event.rb +10 -10
- data/lib/flapjack/data/message.rb +3 -6
- data/lib/flapjack/data/notification.rb +122 -57
- data/lib/flapjack/data/notification_rule.rb +11 -11
- data/lib/flapjack/filters/acknowledgement.rb +2 -2
- data/lib/flapjack/filters/ok.rb +1 -1
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +1 -0
- data/lib/flapjack/gateways/api/entity_methods.rb +4 -6
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +1 -1
- data/lib/flapjack/gateways/email.rb +3 -5
- data/lib/flapjack/gateways/email/{alert.html.haml → alert.html.erb} +0 -0
- data/lib/flapjack/gateways/jabber.rb +66 -35
- data/lib/flapjack/gateways/oobetet.rb +5 -7
- data/lib/flapjack/gateways/pagerduty.rb +7 -7
- data/lib/flapjack/gateways/web.rb +101 -41
- data/lib/flapjack/gateways/web/public/css/flapjack.css +1 -1
- data/lib/flapjack/gateways/web/views/{_css.haml → _css.html.erb} +2 -1
- data/lib/flapjack/gateways/web/views/_foot.html.erb +3 -0
- data/lib/flapjack/gateways/web/views/_head.html.erb +4 -0
- data/lib/flapjack/gateways/web/views/_nav.html.erb +9 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +204 -0
- data/lib/flapjack/gateways/web/views/checks.html.erb +77 -0
- data/lib/flapjack/gateways/web/views/contact.html.erb +114 -0
- data/lib/flapjack/gateways/web/views/contacts.html.erb +42 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +39 -0
- data/lib/flapjack/gateways/web/views/entity.html.erb +67 -0
- data/lib/flapjack/gateways/web/views/index.html.erb +27 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +97 -0
- data/lib/flapjack/logger.rb +71 -23
- data/lib/flapjack/notifier.rb +157 -0
- data/lib/flapjack/patches.rb +1 -41
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/{executive.rb → processor.rb} +32 -145
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +134 -71
- data/spec/lib/flapjack/data/contact_spec.rb +1 -0
- data/spec/lib/flapjack/data/entity_check_spec.rb +146 -30
- data/spec/lib/flapjack/data/entity_spec.rb +4 -4
- data/spec/lib/flapjack/data/event_spec.rb +4 -4
- data/spec/lib/flapjack/data/message_spec.rb +2 -3
- data/spec/lib/flapjack/data/notification_spec.rb +13 -19
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/jabber_spec.rb +34 -0
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +0 -2
- data/spec/lib/flapjack/gateways/web/views/{check.haml_spec.rb → check.html.erb_spec.rb} +2 -2
- data/spec/lib/flapjack/gateways/web/views/{contact.haml_spec.rb → contact.html.erb_spec.rb} +3 -3
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +14 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +20 -8
- data/spec/lib/flapjack/logger_spec.rb +30 -28
- data/spec/lib/flapjack/notifier_spec.rb +6 -0
- data/spec/lib/flapjack/pikelet_spec.rb +8 -8
- data/spec/lib/flapjack/{executive_spec.rb → processor_spec.rb} +4 -4
- data/spec/spec_helper.rb +1 -13
- data/spec/support/erb_view_helper.rb +23 -0
- data/tasks/profile.rake +1 -1
- data/tmp/acknowledge.rb +3 -1
- data/tmp/create_event_ok.rb +3 -1
- data/tmp/create_event_unknown.rb +3 -1
- data/tmp/create_events_failure.rb +3 -1
- data/tmp/create_events_ok.rb +3 -1
- data/tmp/create_events_ok_fail_ack_ok.rb +3 -1
- data/tmp/create_events_ok_failure.rb +3 -1
- data/tmp/create_events_ok_failure_ack.rb +3 -1
- data/tmp/test_json_post.rb +5 -3
- data/tmp/test_notification_rules_api.rb +5 -3
- metadata +32 -61
- data/lib/flapjack/gateways/web/views/_foot.haml +0 -8
- data/lib/flapjack/gateways/web/views/_head.haml +0 -10
- data/lib/flapjack/gateways/web/views/_nav.haml +0 -14
- data/lib/flapjack/gateways/web/views/check.haml +0 -191
- data/lib/flapjack/gateways/web/views/checks.haml +0 -49
- data/lib/flapjack/gateways/web/views/contact.haml +0 -85
- data/lib/flapjack/gateways/web/views/contacts.haml +0 -30
- data/lib/flapjack/gateways/web/views/entities.haml +0 -28
- data/lib/flapjack/gateways/web/views/entity.haml +0 -50
- data/lib/flapjack/gateways/web/views/index.haml +0 -32
- data/lib/flapjack/gateways/web/views/self_stats.haml +0 -70
- data/spec/lib/flapjack/gateways/web/views/index.haml_spec.rb +0 -13
- data/spec/support/haml_view_helper.rb +0 -15
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'web/views/check.
|
3
|
+
describe 'web/views/check.html.erb', :erb_view => true do
|
4
4
|
|
5
5
|
it "should escape unsafe check characters in URIs" do
|
6
6
|
@entity = 'abc-xyz-01'
|
7
7
|
@check = 'Disk / Utilisation'
|
8
8
|
@last_notifications = {}
|
9
9
|
|
10
|
-
page =
|
10
|
+
page = render_erb('check.html.erb', binding)
|
11
11
|
page.should match(%r{/abc-xyz-01/Disk%20%2F%20Utilisation})
|
12
12
|
end
|
13
13
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'web/views/contact.
|
3
|
+
describe 'web/views/contact.html.erb', :erb_view => true do
|
4
4
|
|
5
5
|
it "should escape unsafe check characters in URI parameters" do
|
6
6
|
@contact = mock('contact')
|
@@ -15,8 +15,8 @@ describe 'web/views/contact.haml', :haml_view => true do
|
|
15
15
|
|
16
16
|
@entities_and_checks = [{:entity => entity, :checks => checks}]
|
17
17
|
|
18
|
-
page =
|
19
|
-
page.should match(%r{\?entity=abc-xyz-01&check=Disk
|
18
|
+
page = render_erb('contact.html.erb', binding)
|
19
|
+
page.should match(%r{\?entity=abc-xyz-01&check=Disk%20%2F%20Utilisation})
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'web/views/checks.html.erb', :erb_view => true do
|
4
|
+
|
5
|
+
it "should escape unsafe check characters in URI parameters" do
|
6
|
+
@states = {'abc-xyz-01' => [['Disk / Utilisation', 'OK', 'Looking good', '-', '-', false, false, nil, nil]]}
|
7
|
+
@entities_sorted = ['abc-xyz-01']
|
8
|
+
@adjective = "all"
|
9
|
+
|
10
|
+
page = render_erb('checks.html.erb', binding)
|
11
|
+
page.should match(%r{\?entity=abc-xyz-01&check=Disk%20%2F%20Utilisation})
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -43,17 +43,24 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def expect_check_stats
|
46
|
-
|
47
|
-
|
46
|
+
Flapjack::Data::EntityCheck.should_receive(:count_all).
|
47
|
+
with(:redis => redis).and_return(1)
|
48
|
+
Flapjack::Data::EntityCheck.should_receive(:count_all_failing).
|
49
|
+
with(:redis => redis).and_return(1)
|
48
50
|
end
|
49
51
|
|
50
52
|
def expect_entity_stats
|
53
|
+
Flapjack::Data::Entity.should_receive(:find_all_with_checks).
|
54
|
+
with(:redis => redis).and_return([entity_name])
|
55
|
+
Flapjack::Data::Entity.should_receive(:find_all_with_failing_checks).
|
56
|
+
with(:redis => redis).and_return([entity_name])
|
51
57
|
end
|
52
58
|
|
53
59
|
def expect_entity_check_status(ec)
|
54
60
|
time = Time.now.to_i
|
55
61
|
|
56
62
|
ec.should_receive(:state).and_return('ok')
|
63
|
+
ec.should_receive(:summary).and_return('happy results are returned')
|
57
64
|
ec.should_receive(:last_update).and_return(time - (3 * 60 * 60))
|
58
65
|
ec.should_receive(:last_change).and_return(time - (3 * 60 * 60))
|
59
66
|
ec.should_receive(:last_notification_for_state).with(:problem).and_return({:timestamp => time - ((3 * 60 * 60) + (5 * 60))})
|
@@ -67,8 +74,9 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
67
74
|
# (for the methods that access redis directly)
|
68
75
|
|
69
76
|
it "shows a page listing all checks" do
|
70
|
-
redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}"])
|
71
|
-
|
77
|
+
#redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}"])
|
78
|
+
Flapjack::Data::EntityCheck.should_receive(:find_all_by_entity).
|
79
|
+
with(:redis => redis).and_return({entity_name => [check]})
|
72
80
|
expect_check_stats
|
73
81
|
|
74
82
|
expect_entity_check_status(entity_check)
|
@@ -84,7 +92,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
84
92
|
end
|
85
93
|
|
86
94
|
it "shows a page listing failing checks" do
|
87
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}"])
|
95
|
+
#redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}"])
|
88
96
|
|
89
97
|
expect_check_stats
|
90
98
|
|
@@ -93,6 +101,9 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
93
101
|
Flapjack::Data::Entity.should_receive(:find_by_name).
|
94
102
|
with(entity_name, :redis => redis).and_return(entity)
|
95
103
|
|
104
|
+
Flapjack::Data::EntityCheck.should_receive(:find_all_failing_by_entity).
|
105
|
+
with(:redis => redis).and_return({entity_name => [check]})
|
106
|
+
|
96
107
|
Flapjack::Data::EntityCheck.should_receive(:for_entity).
|
97
108
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
98
109
|
get '/checks_failing'
|
@@ -100,8 +111,8 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
100
111
|
end
|
101
112
|
|
102
113
|
it "shows a page listing flapjack statistics" do
|
103
|
-
redis.should_receive(:keys).with('check:*').and_return([])
|
104
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}"])
|
114
|
+
#redis.should_receive(:keys).with('check:*').and_return([])
|
115
|
+
#redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}"])
|
105
116
|
expect_stats
|
106
117
|
expect_check_stats
|
107
118
|
expect_entity_stats
|
@@ -130,9 +141,10 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
130
141
|
entity_check.should_receive(:current_maintenance).with(:scheduled => true).and_return(false)
|
131
142
|
entity_check.should_receive(:current_maintenance).with(:scheduled => false).and_return(false)
|
132
143
|
entity_check.should_receive(:contacts).and_return([])
|
133
|
-
|
134
144
|
entity_check.should_receive(:historical_states).
|
135
145
|
with(nil, time.to_i, :order => 'desc', :limit => 20).and_return([])
|
146
|
+
entity_check.should_receive(:enabled?).with().
|
147
|
+
and_return(true)
|
136
148
|
|
137
149
|
Flapjack::Data::Entity.should_receive(:find_by_name).
|
138
150
|
with(entity_name, :redis => redis).and_return(entity)
|
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'flapjack/pikelet'
|
3
2
|
|
4
3
|
describe Flapjack::Logger do
|
5
4
|
|
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
|
-
|
5
|
+
let(:logger) { mock(::Logger) }
|
6
|
+
|
7
|
+
let(:sys_logger) { mock(::Logger) }
|
8
|
+
let(:syslog) { mock(Syslog) }
|
9
|
+
|
10
|
+
it "creates a logger logging to STDOUT and syslog" do
|
11
|
+
logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
12
|
+
logger.should_receive(:level=).and_return(Logger::DEBUG)
|
13
|
+
logger.should_receive(:warn).with("Yowza!")
|
14
|
+
::Logger.should_receive(:new).with(STDOUT).and_return(logger)
|
15
|
+
|
16
|
+
if Syslog.const_defined?('Logger', false)
|
17
|
+
sys_logger.should_receive(:formatter=).with(an_instance_of(Proc))
|
18
|
+
sys_logger.should_receive(:level=).with(Logger::DEBUG)
|
19
|
+
sys_logger.should_receive(:warn).with("Yowza!")
|
20
|
+
Syslog.const_get('Logger', false).should_receive(:new).with('flapjack').and_return(sys_logger)
|
21
|
+
else
|
22
|
+
syslog.should_receive(:log).with(Syslog::Constants::LOG_WARNING, /\[WARN\] :: spec :: %s/, "Yowza!")
|
23
|
+
Syslog.should_receive(:"opened?").and_return(false)
|
24
|
+
Syslog.should_receive(:open).with('flapjack',
|
25
|
+
(Syslog::Constants::LOG_PID | Syslog::Constants::LOG_CONS),
|
26
|
+
Syslog::Constants::LOG_USER).and_return(syslog)
|
27
|
+
Syslog.should_receive(:mask=).with(Syslog::LOG_UPTO(Syslog::Constants::LOG_DEBUG))
|
28
|
+
end
|
29
|
+
|
30
|
+
flogger = Flapjack::Logger.new('spec', 'level' => 'debug')
|
31
|
+
flogger.warn "Yowza!"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -3,10 +3,10 @@ require 'flapjack/pikelet'
|
|
3
3
|
|
4
4
|
describe Flapjack::Pikelet do
|
5
5
|
|
6
|
-
let(:config)
|
6
|
+
let(:config) { mock('config') }
|
7
7
|
let(:redis_config) { mock('redis_config') }
|
8
8
|
|
9
|
-
let(:logger)
|
9
|
+
let(:logger) { mock(Flapjack::Logger) }
|
10
10
|
|
11
11
|
let(:fiber) { mock(Fiber) }
|
12
12
|
|
@@ -16,21 +16,21 @@ describe Flapjack::Pikelet do
|
|
16
16
|
Flapjack::Pikelet::Resque.class_variable_set(:@@resque_pool, nil)
|
17
17
|
end
|
18
18
|
|
19
|
-
it "creates and starts
|
19
|
+
it "creates and starts a processor pikelet" do
|
20
20
|
Flapjack::Logger.should_receive(:new).and_return(logger)
|
21
21
|
|
22
22
|
config.should_receive(:[]).with('logger').and_return(nil)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
Flapjack::
|
24
|
+
processor = mock('processor')
|
25
|
+
processor.should_receive(:start)
|
26
|
+
Flapjack::Processor.should_receive(:new).with(:config => config,
|
27
27
|
:redis_config => redis_config, :boot_time => time, :logger => logger).
|
28
|
-
and_return(
|
28
|
+
and_return(processor)
|
29
29
|
|
30
30
|
fiber.should_receive(:resume)
|
31
31
|
Fiber.should_receive(:new).and_yield.and_return(fiber)
|
32
32
|
|
33
|
-
pik = Flapjack::Pikelet.create('
|
33
|
+
pik = Flapjack::Pikelet.create('processor', :config => config,
|
34
34
|
:redis_config => redis_config, :boot_time => time)
|
35
35
|
pik.should be_a(Flapjack::Pikelet::Generic)
|
36
36
|
pik.start
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'flapjack/
|
2
|
+
require 'flapjack/processor'
|
3
3
|
|
4
|
-
describe Flapjack::
|
4
|
+
describe Flapjack::Processor, :logger => true do
|
5
5
|
|
6
|
-
# NB: this is only testing the public API of the
|
6
|
+
# NB: this is only testing the public API of the Processor class, which is pretty limited.
|
7
7
|
# (initialize, main, stop). Most test coverage for this class comes from the cucumber features.
|
8
8
|
|
9
9
|
# TODO this does too much -- split it up
|
@@ -40,7 +40,7 @@ describe Flapjack::Executive, :logger => true do
|
|
40
40
|
Flapjack::Data::Event.should_receive(:pending_count).with(:redis => redis).and_return(0)
|
41
41
|
|
42
42
|
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
43
|
-
executive = Flapjack::
|
43
|
+
executive = Flapjack::Processor.new(:config => {}, :logger => @logger)
|
44
44
|
|
45
45
|
shutdown_evt = mock(Flapjack::Data::Event)
|
46
46
|
shutdown_evt.should_receive(:inspect)
|
data/spec/spec_helper.rb
CHANGED
@@ -61,18 +61,6 @@ RSpec.configure do |config|
|
|
61
61
|
# --seed 1234
|
62
62
|
config.order = 'random'
|
63
63
|
|
64
|
-
config.before(:each, :logger => true) do
|
65
|
-
def test_logger(class_name)
|
66
|
-
logger = Log4r::Logger.new(class_name)
|
67
|
-
outp = Log4r::FileOutputter.new(class_name,
|
68
|
-
:filename => File.join(File.dirname(__FILE__), '..', 'log', 'test.log'))
|
69
|
-
outp.formatter = Log4r::PatternFormatter.new(:pattern => "[%l] %d :: #{class_name} :: %m",
|
70
|
-
:date_pattern => "%Y-%m-%dT%H:%M:%S%z")
|
71
|
-
logger.add(outp)
|
72
|
-
logger
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
64
|
config.around(:each, :redis => true) do |example|
|
77
65
|
@redis = ::Redis.new(:db => 14, :driver => :ruby)
|
78
66
|
@redis.flushdb
|
@@ -92,7 +80,7 @@ RSpec.configure do |config|
|
|
92
80
|
Delorean.back_to_the_present
|
93
81
|
end
|
94
82
|
|
95
|
-
config.include
|
83
|
+
config.include ErbViewHelper, :erb_view => true
|
96
84
|
config.include Rack::Test::Methods, :sinatra => true
|
97
85
|
config.include JsonSpec::Helpers, :json => true
|
98
86
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'flapjack/utility'
|
2
|
+
|
3
|
+
module ErbViewHelper
|
4
|
+
|
5
|
+
TEMPLATE_PATH = File.dirname(__FILE__) +
|
6
|
+
'/../../lib/flapjack/gateways/web/views/'
|
7
|
+
|
8
|
+
include Flapjack::Utility
|
9
|
+
|
10
|
+
def render_erb(file, bind)
|
11
|
+
erb = ERB.new(File.read(TEMPLATE_PATH + file))
|
12
|
+
erb.result(bind)
|
13
|
+
end
|
14
|
+
|
15
|
+
def h(text)
|
16
|
+
ERB::Util.h(text)
|
17
|
+
end
|
18
|
+
|
19
|
+
def u(text)
|
20
|
+
ERB::Util.u(text)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/tasks/profile.rake
CHANGED
data/tmp/acknowledge.rb
CHANGED
data/tmp/create_event_ok.rb
CHANGED
data/tmp/create_event_unknown.rb
CHANGED
data/tmp/create_events_ok.rb
CHANGED
data/tmp/test_json_post.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
require 'oj'
|
6
|
+
Oj.default_options = { :indent => 0, :mode => :strict }
|
5
7
|
|
6
8
|
@payload ={
|
7
9
|
"email" => "phil@gmail.com",
|
@@ -12,5 +14,5 @@ require 'json'
|
|
12
14
|
"auto_action" => "true"
|
13
15
|
}
|
14
16
|
|
15
|
-
HTTParty.post( 'http://localhost:4091/notification_rules', :body =>
|
17
|
+
HTTParty.post( 'http://localhost:4091/notification_rules', :body => Oj.dump(@payload), :options => { :headers => { 'ContentType' => 'application/json' } })
|
16
18
|
|