flapjack 0.6.39 → 0.6.40
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.
- data/.gitignore +2 -2
- data/Gemfile +5 -1
- data/README.md +3 -2
- data/Rakefile +2 -1
- data/bin/flapjack +2 -2
- data/bin/flapjack-nagios-receiver +2 -8
- data/bin/flapjack-populator +11 -11
- data/etc/flapjack_config.yaml.example +28 -0
- data/features/steps/events_steps.rb +1 -1
- data/features/steps/notifications_steps.rb +7 -4
- data/features/support/env.rb +17 -6
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/api.rb +72 -28
- data/lib/flapjack/configuration.rb +9 -1
- data/lib/flapjack/coordinator.rb +138 -162
- data/lib/flapjack/data/contact.rb +3 -1
- data/lib/flapjack/data/entity.rb +10 -1
- data/lib/flapjack/data/entity_check.rb +19 -21
- data/lib/flapjack/data/event.rb +26 -27
- data/lib/flapjack/data/message.rb +45 -0
- data/lib/flapjack/data/notification.rb +49 -0
- data/lib/flapjack/executive.rb +53 -74
- data/lib/flapjack/filters/acknowledgement.rb +14 -11
- data/lib/flapjack/jabber.rb +84 -18
- data/lib/flapjack/notification/email.rb +67 -37
- data/lib/flapjack/notification/sms.rb +40 -28
- data/lib/flapjack/oobetet.rb +1 -1
- data/lib/flapjack/pagerduty.rb +24 -15
- data/lib/flapjack/patches.rb +3 -1
- data/lib/flapjack/pikelet.rb +51 -20
- data/lib/flapjack/rack_logger.rb +8 -0
- data/lib/flapjack/version.rb +1 -1
- data/lib/flapjack/web.rb +51 -27
- data/spec/lib/flapjack/api_spec.rb +28 -3
- data/spec/lib/flapjack/coordinator_spec.rb +69 -43
- data/spec/lib/flapjack/data/contact_spec.rb +17 -9
- data/spec/lib/flapjack/data/entity_check_spec.rb +0 -25
- data/spec/lib/flapjack/data/entity_spec.rb +4 -0
- data/spec/lib/flapjack/data/global_spec.rb +6 -0
- data/spec/lib/flapjack/data/message_spec.rb +6 -0
- data/spec/lib/flapjack/data/notification_spec.rb +6 -0
- data/spec/lib/flapjack/executive_spec.rb +2 -2
- data/spec/lib/flapjack/jabber_spec.rb +8 -9
- data/spec/lib/flapjack/pagerduty_spec.rb +53 -45
- data/spec/lib/flapjack/utility_spec.rb +55 -0
- data/spec/lib/flapjack/web_spec.rb +7 -5
- data/tasks/events.rake +26 -59
- data/tasks/profile.rake +366 -0
- metadata +30 -19
- data/lib/flapjack/notification/common.rb +0 -23
- data/lib/flapjack/persistence/couch.rb +0 -5
- data/lib/flapjack/persistence/couch/connection.rb +0 -66
- data/lib/flapjack/persistence/couch/couch.rb +0 -63
- data/lib/flapjack/persistence/data_mapper.rb +0 -3
- data/lib/flapjack/persistence/data_mapper/data_mapper.rb +0 -67
- data/lib/flapjack/persistence/data_mapper/models/check.rb +0 -90
- data/lib/flapjack/persistence/data_mapper/models/check_template.rb +0 -20
- data/lib/flapjack/persistence/data_mapper/models/event.rb +0 -19
- data/lib/flapjack/persistence/data_mapper/models/node.rb +0 -18
- data/lib/flapjack/persistence/data_mapper/models/related_check.rb +0 -15
- data/lib/flapjack/persistence/sqlite3.rb +0 -3
- data/lib/flapjack/persistence/sqlite3/sqlite3.rb +0 -166
- data/lib/flapjack/transports/beanstalkd.rb +0 -50
- data/lib/flapjack/transports/result.rb +0 -58
- data/lib/flapjack/worker/application.rb +0 -121
- data/lib/flapjack/worker/cli.rb +0 -49
data/.gitignore
CHANGED
|
@@ -9,7 +9,6 @@ gems/gems/*
|
|
|
9
9
|
gems/bin/*
|
|
10
10
|
recipients.yaml
|
|
11
11
|
.yardoc
|
|
12
|
-
#doc/*
|
|
13
12
|
pkg/*
|
|
14
13
|
!etc/flapjack/recipients.yaml
|
|
15
14
|
spec/test.db
|
|
@@ -18,9 +17,10 @@ features/support/etc/netsaint/*
|
|
|
18
17
|
log/*
|
|
19
18
|
vendor
|
|
20
19
|
.bundle
|
|
21
|
-
etc
|
|
20
|
+
etc/*.yaml
|
|
22
21
|
coverage
|
|
23
22
|
tmp/pids/*
|
|
24
23
|
tmp/spec*
|
|
24
|
+
tmp/profiles
|
|
25
25
|
flapjack-*.gem
|
|
26
26
|
|
data/Gemfile
CHANGED
|
@@ -2,11 +2,15 @@ source :rubygems
|
|
|
2
2
|
|
|
3
3
|
gemspec :name => 'flapjack'
|
|
4
4
|
|
|
5
|
+
group :development do
|
|
6
|
+
gem 'ruby-prof'
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
group :test do
|
|
6
10
|
gem 'rspec'
|
|
7
11
|
gem 'cucumber'
|
|
8
12
|
gem 'delorean'
|
|
9
|
-
gem 'rack-test'
|
|
13
|
+
gem 'rack-test'
|
|
10
14
|
gem 'resque_spec'
|
|
11
15
|
gem 'webmock'
|
|
12
16
|
gem 'guard'
|
data/README.md
CHANGED
|
@@ -18,11 +18,11 @@ At its core, flapjack process events received from external check execution engi
|
|
|
18
18
|
|
|
19
19
|
TODO numbered list for simplest possible Flapjack run
|
|
20
20
|
|
|
21
|
-
For more information, including full specification of the configuration file and the data import formats, please refer to the [Flapjack Wiki](https://github.com/
|
|
21
|
+
For more information, including full specification of the configuration file and the data import formats, please refer to the [Flapjack Wiki](https://github.com/flpjck/flapjack/wiki/USING).
|
|
22
22
|
|
|
23
23
|
## Developing Flapjack
|
|
24
24
|
|
|
25
|
-
Information on developing more Flapjack components or contributing to core Flapjack development can be found in the [Flapjack Wiki](https://github.com/
|
|
25
|
+
Information on developing more Flapjack components or contributing to core Flapjack development can be found in the [Flapjack Wiki](https://github.com/flpjck/flapjack/wiki/DEVELOPING).
|
|
26
26
|
|
|
27
27
|
## Documentation Submodule
|
|
28
28
|
|
|
@@ -35,6 +35,7 @@ git submodule update
|
|
|
35
35
|
|
|
36
36
|
If you make changes to the documentation locally, here's how to publish them:
|
|
37
37
|
|
|
38
|
+
* first up, checkout master within the doc subdir, otherwise you'll be commiting to no branch, aka no man's land
|
|
38
39
|
* git add, commit and push from inside the doc subdir
|
|
39
40
|
* add, commit and push the doc dir from the root (this updates the pointer in the main git repo to the correct ref in the doc repo, we think...)
|
|
40
41
|
|
data/Rakefile
CHANGED
|
@@ -20,7 +20,8 @@ Bundler::GemHelper.install_tasks
|
|
|
20
20
|
Cucumber::Rake::Task.new(:features) do |t|
|
|
21
21
|
#t.cucumber_opts = 'features --format pretty'
|
|
22
22
|
#t.cucumber_opts = '--format progress'
|
|
23
|
-
t.cucumber_opts = '--format fuubar'
|
|
23
|
+
#t.cucumber_opts = '--format fuubar'
|
|
24
|
+
t.cucumber_opts = '--format Cucumber::Formatter::Fuubar'
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
require 'rspec/core/rake_task'
|
data/bin/flapjack
CHANGED
|
@@ -33,7 +33,7 @@ end.parse!(ARGV)
|
|
|
33
33
|
|
|
34
34
|
FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
|
|
35
35
|
|
|
36
|
-
config_env = Flapjack::Configuration.new.load(options.config)
|
|
36
|
+
config_env, redis_options = Flapjack::Configuration.new.load(options.config)
|
|
37
37
|
|
|
38
38
|
if config_env.nil? || config_env.empty?
|
|
39
39
|
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
|
|
@@ -50,7 +50,7 @@ end
|
|
|
50
50
|
|
|
51
51
|
require 'flapjack/coordinator'
|
|
52
52
|
|
|
53
|
-
coordinator = Flapjack::Coordinator.new(config_env)
|
|
53
|
+
coordinator = Flapjack::Coordinator.new(config_env, redis_options)
|
|
54
54
|
coordinator.log_file = (config_env['log_file'] || 'log/flapjack.log')
|
|
55
55
|
coordinator.pid_file = pid_file
|
|
56
56
|
|
|
@@ -31,7 +31,7 @@ end.parse!(ARGV)
|
|
|
31
31
|
|
|
32
32
|
FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
|
|
33
33
|
|
|
34
|
-
@config_env = Flapjack::Configuration.new.load(options.config)
|
|
34
|
+
@config_env, @redis_options = Flapjack::Configuration.new.load(options.config)
|
|
35
35
|
|
|
36
36
|
if @config_env.nil? || @config_env.empty?
|
|
37
37
|
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
|
|
@@ -51,12 +51,6 @@ end
|
|
|
51
51
|
# host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
|
|
52
52
|
# service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
|
|
53
53
|
|
|
54
|
-
def get_redis_connection(cfg)
|
|
55
|
-
opts = cfg['path'] ? {:path => cfg['path']} :
|
|
56
|
-
{:host => cfg['host'], :port => cfg['port']}
|
|
57
|
-
Redis.new(opts.merge(:db => cfg['db']))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
54
|
def process_input(redis)
|
|
61
55
|
begin
|
|
62
56
|
while line = @fifo.gets
|
|
@@ -97,7 +91,7 @@ def process_input(redis)
|
|
|
97
91
|
end
|
|
98
92
|
|
|
99
93
|
def main
|
|
100
|
-
redis =
|
|
94
|
+
redis = Redis.new(@redis_options)
|
|
101
95
|
|
|
102
96
|
while true
|
|
103
97
|
process_input(redis)
|
data/bin/flapjack-populator
CHANGED
|
@@ -43,7 +43,7 @@ end.parse!(ARGV)
|
|
|
43
43
|
|
|
44
44
|
FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
|
|
45
45
|
|
|
46
|
-
config_env = Flapjack::Configuration.new.load(options.config)
|
|
46
|
+
config_env, redis_options = Flapjack::Configuration.new.load(options.config)
|
|
47
47
|
|
|
48
48
|
if config_env.nil? || config_env.empty?
|
|
49
49
|
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
|
|
@@ -55,18 +55,12 @@ if options.from
|
|
|
55
55
|
file = File.new(filename)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
def get_redis_connection(cfg)
|
|
59
|
-
opts = cfg['path'] ? {:path => cfg['path']} :
|
|
60
|
-
{:host => cfg['host'], :port => cfg['port']}
|
|
61
|
-
Redis.new(opts.merge(:db => cfg['db']))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
58
|
case command
|
|
65
59
|
when "import-contacts"
|
|
66
60
|
contacts = JSON.parse(file)
|
|
67
61
|
|
|
68
62
|
if contacts && contacts.is_a?(Enumerable) && contacts.any? {|e| !e['id'].nil?}
|
|
69
|
-
@persistence =
|
|
63
|
+
@persistence = Redis.new(redis_options)
|
|
70
64
|
@persistence.multi do
|
|
71
65
|
contacts.each do |contact|
|
|
72
66
|
unless contact['id']
|
|
@@ -83,7 +77,7 @@ when "import-entities"
|
|
|
83
77
|
entities = JSON.parse(file)
|
|
84
78
|
|
|
85
79
|
if entities && entities.is_a?(Enumerable) && entities.any? {|e| !e['id'].nil?}
|
|
86
|
-
@persistence =
|
|
80
|
+
@persistence = Redis.new(redis_options)
|
|
87
81
|
@persistence.multi
|
|
88
82
|
entities.each do |entity|
|
|
89
83
|
unless entity['id']
|
|
@@ -97,8 +91,14 @@ when "import-entities"
|
|
|
97
91
|
end
|
|
98
92
|
|
|
99
93
|
when "purge-events"
|
|
100
|
-
@persistence =
|
|
101
|
-
|
|
94
|
+
@persistence = Redis.new(redis_options)
|
|
95
|
+
events_size = @persistence.llen('events')
|
|
96
|
+
puts "purging #{events_size} events..."
|
|
97
|
+
etq = "events.#{Time.now.to_i}"
|
|
98
|
+
puts "renaming 'events' to '#{etq}'"
|
|
99
|
+
@persistence.rename('events', etq)
|
|
100
|
+
puts "setting expiry of '#{etq}' to 8 hours"
|
|
101
|
+
@persistence.expire(etq, (60 * 60 * 8))
|
|
102
102
|
@persistence.quit
|
|
103
103
|
|
|
104
104
|
else
|
|
@@ -83,9 +83,11 @@ development:
|
|
|
83
83
|
web:
|
|
84
84
|
enabled: yes
|
|
85
85
|
port: 5080
|
|
86
|
+
access_log: "log/web_access.log"
|
|
86
87
|
api:
|
|
87
88
|
enabled: yes
|
|
88
89
|
port: 5081
|
|
90
|
+
access_log: "log/api_access.log"
|
|
89
91
|
|
|
90
92
|
test:
|
|
91
93
|
redis:
|
|
@@ -123,3 +125,29 @@ production:
|
|
|
123
125
|
password: "xxxx"
|
|
124
126
|
web:
|
|
125
127
|
instances: 1
|
|
128
|
+
|
|
129
|
+
profile:
|
|
130
|
+
redis:
|
|
131
|
+
host: 127.0.0.1
|
|
132
|
+
port: 6379
|
|
133
|
+
db: 14
|
|
134
|
+
executive:
|
|
135
|
+
enabled: yes
|
|
136
|
+
notification_log_file: log/flapjack-notification.log
|
|
137
|
+
email_notifier:
|
|
138
|
+
enabled: no
|
|
139
|
+
queue: email_notifications
|
|
140
|
+
jabber_gateway:
|
|
141
|
+
enabled: yes
|
|
142
|
+
queue: jabber_notifications
|
|
143
|
+
server: "jabber.domain.tld"
|
|
144
|
+
port: 5222
|
|
145
|
+
jabberid: "flapjack@jabber.domain.tld"
|
|
146
|
+
password: "good-password"
|
|
147
|
+
alias: "flapjack"
|
|
148
|
+
rooms:
|
|
149
|
+
- "gimp@conference.jabber.domain.tld"
|
|
150
|
+
- "log@conference.jabber.domain.tld"
|
|
151
|
+
web:
|
|
152
|
+
enabled: no
|
|
153
|
+
port: 5080
|
|
@@ -5,7 +5,7 @@ require 'flapjack/data/event'
|
|
|
5
5
|
|
|
6
6
|
def drain_events
|
|
7
7
|
loop do
|
|
8
|
-
event = Flapjack::Data::Event.next(:block => false, :
|
|
8
|
+
event = Flapjack::Data::Event.next(:block => false, :redis => @redis)
|
|
9
9
|
break unless event
|
|
10
10
|
@app.send(:process_event, event)
|
|
11
11
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
include Mail::Matchers
|
|
3
3
|
|
|
4
4
|
# copied from flapjack-populator
|
|
5
|
+
# TODO use Flapjack::Data::Contact.add
|
|
5
6
|
def add_contact(contact = {})
|
|
6
7
|
@redis.multi
|
|
7
8
|
@redis.del("contact:#{contact['id']}")
|
|
@@ -67,7 +68,7 @@ When /^an event notification is generated for entity '([\w\.\-]+)'$/ do |entity|
|
|
|
67
68
|
'entity' => entity,
|
|
68
69
|
'check' => 'ping')
|
|
69
70
|
entity_check = Flapjack::Data::EntityCheck.for_entity_name(entity, 'ping', :redis => @redis)
|
|
70
|
-
@app.send(:
|
|
71
|
+
@app.send(:send_notification_messages, event, entity_check)
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
Then /^an SMS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity|
|
|
@@ -127,7 +128,7 @@ When /^the SMS notification handler runs successfully$/ do
|
|
|
127
128
|
# returns success by default - currently matches all addresses, maybe load from config?
|
|
128
129
|
stub_request(:get, /.*/)
|
|
129
130
|
# TODO load config from cfg file instead?
|
|
130
|
-
Flapjack::Notification::Sms.
|
|
131
|
+
Flapjack::Notification::Sms.instance_variable_set('@config', {'username' => 'abcd', 'password' => 'efgh'})
|
|
131
132
|
|
|
132
133
|
lambda {
|
|
133
134
|
Flapjack::Notification::Sms.dispatch(@sms_notification, :logger => @logger, :redis => @redis)
|
|
@@ -145,8 +146,10 @@ When /^the SMS notification handler fails to send an SMS$/ do
|
|
|
145
146
|
end
|
|
146
147
|
|
|
147
148
|
When /^the email notification handler runs successfully$/ do
|
|
149
|
+
Resque.redis = @redis
|
|
150
|
+
Flapjack::Notification::Email.bootstrap(:config => {})
|
|
148
151
|
lambda {
|
|
149
|
-
Flapjack::Notification::Email.
|
|
152
|
+
Flapjack::Notification::Email.perform(@email_notification)
|
|
150
153
|
}.should_not raise_error
|
|
151
154
|
end
|
|
152
155
|
|
|
@@ -157,7 +160,7 @@ When /^the email notification handler fails to send an email$/ do
|
|
|
157
160
|
pending
|
|
158
161
|
lambda {
|
|
159
162
|
@email_notification['address'] = nil
|
|
160
|
-
Flapjack::Notification::Email.
|
|
163
|
+
Flapjack::Notification::Email.perform(@email_notification)
|
|
161
164
|
}.should_not raise_error
|
|
162
165
|
end
|
|
163
166
|
|
data/features/support/env.rb
CHANGED
|
@@ -8,8 +8,7 @@ if ENV['COVERAGE']
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
ENV["FLAPJACK_ENV"] = 'test'
|
|
11
|
-
|
|
12
|
-
Bundler.require(:default, :test)
|
|
11
|
+
FLAPJACK_ENV = 'test'
|
|
13
12
|
|
|
14
13
|
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
|
15
14
|
|
|
@@ -21,6 +20,8 @@ WebMock.disable_net_connect!
|
|
|
21
20
|
require 'flapjack/executive'
|
|
22
21
|
require 'flapjack/patches'
|
|
23
22
|
|
|
23
|
+
require 'resque_spec'
|
|
24
|
+
|
|
24
25
|
class MockLogger
|
|
25
26
|
attr_accessor :messages
|
|
26
27
|
|
|
@@ -46,15 +47,25 @@ redis = ::Redis.new(redis_opts)
|
|
|
46
47
|
redis.flushdb
|
|
47
48
|
redis.quit
|
|
48
49
|
|
|
50
|
+
# NB: this seems to execute outside the Before/After hooks
|
|
51
|
+
# regardless of placement -- this is what we want, as the
|
|
52
|
+
# @redis driver should be initialised in the sync block.
|
|
53
|
+
Around do |scenario, blk|
|
|
54
|
+
EM.synchrony do
|
|
55
|
+
blk.call
|
|
56
|
+
EM.stop
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
49
60
|
Before do
|
|
50
61
|
@logger = MockLogger.new
|
|
51
62
|
# Use a separate database whilst testing
|
|
52
63
|
@app = Flapjack::Executive.new
|
|
53
|
-
@app.bootstrap(:logger => @logger,
|
|
64
|
+
@app.bootstrap(:logger => @logger,
|
|
54
65
|
:config => {'email_queue' => 'email_notifications',
|
|
55
|
-
'sms_queue' => 'sms_notifications'}
|
|
56
|
-
|
|
57
|
-
@redis = @app.redis
|
|
66
|
+
'sms_queue' => 'sms_notifications'},
|
|
67
|
+
:redis_config => redis_opts)
|
|
68
|
+
@redis = @app.instance_variable_get('@redis')
|
|
58
69
|
end
|
|
59
70
|
|
|
60
71
|
After do
|
data/flapjack.gemspec
CHANGED
data/lib/flapjack/api.rb
CHANGED
|
@@ -12,9 +12,13 @@ require 'rack/fiber_pool'
|
|
|
12
12
|
require 'sinatra/base'
|
|
13
13
|
|
|
14
14
|
require 'flapjack/pikelet'
|
|
15
|
+
require 'flapjack/redis_pool'
|
|
15
16
|
|
|
16
17
|
require 'flapjack/api/entity_presenter'
|
|
17
18
|
|
|
19
|
+
require 'async-rack'
|
|
20
|
+
require 'flapjack/rack_logger'
|
|
21
|
+
|
|
18
22
|
require 'flapjack/data/contact'
|
|
19
23
|
require 'flapjack/data/entity'
|
|
20
24
|
require 'flapjack/data/entity_check'
|
|
@@ -49,7 +53,7 @@ module Flapjack
|
|
|
49
53
|
|
|
50
54
|
set :show_exceptions, false
|
|
51
55
|
|
|
52
|
-
if 'test'.eql?(FLAPJACK_ENV)
|
|
56
|
+
if defined?(FLAPJACK_ENV) && 'test'.eql?(FLAPJACK_ENV)
|
|
53
57
|
# expose test errors properly
|
|
54
58
|
set :raise_errors, true
|
|
55
59
|
else
|
|
@@ -65,16 +69,40 @@ module Flapjack
|
|
|
65
69
|
use Rack::MethodOverride
|
|
66
70
|
use Rack::JsonParamsParser
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
api_logger = Flapjack::RackLogger.new('log/api_access.log')
|
|
73
|
+
use Rack::CommonLogger, api_logger
|
|
74
|
+
|
|
75
|
+
class << self
|
|
76
|
+
include Flapjack::ThinPikelet
|
|
77
|
+
|
|
78
|
+
attr_accessor :redis
|
|
79
|
+
|
|
80
|
+
alias_method :thin_bootstrap, :bootstrap
|
|
81
|
+
alias_method :thin_cleanup, :cleanup
|
|
82
|
+
|
|
83
|
+
def bootstrap(opts = {})
|
|
84
|
+
thin_bootstrap(opts)
|
|
85
|
+
@redis = Flapjack::RedisPool.new(:config => opts[:redis_config], :size => 1)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def cleanup
|
|
89
|
+
@redis.empty! if @redis
|
|
90
|
+
thin_cleanup
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def redis
|
|
96
|
+
self.class.instance_variable_get('@redis')
|
|
97
|
+
end
|
|
69
98
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Flapjack::API.bootstrap
|
|
99
|
+
def logger
|
|
100
|
+
self.class.instance_variable_get('@logger')
|
|
73
101
|
end
|
|
74
102
|
|
|
75
103
|
get '/entities' do
|
|
76
104
|
content_type :json
|
|
77
|
-
ret = Flapjack::Data::Entity.all(:redis =>
|
|
105
|
+
ret = Flapjack::Data::Entity.all(:redis => redis).sort_by(&:name).collect {|e|
|
|
78
106
|
{'id' => e.id, 'name' => e.name,
|
|
79
107
|
'checks' => e.check_list.sort.collect {|c|
|
|
80
108
|
entity_check_status(e, c)
|
|
@@ -86,7 +114,7 @@ module Flapjack
|
|
|
86
114
|
|
|
87
115
|
get '/checks/:entity' do
|
|
88
116
|
content_type :json
|
|
89
|
-
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis =>
|
|
117
|
+
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis => redis)
|
|
90
118
|
if entity.nil?
|
|
91
119
|
status 404
|
|
92
120
|
return
|
|
@@ -100,7 +128,7 @@ module Flapjack
|
|
|
100
128
|
entity_name = params[:captures][0]
|
|
101
129
|
check = params[:captures][1]
|
|
102
130
|
|
|
103
|
-
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis =>
|
|
131
|
+
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis)
|
|
104
132
|
if entity.nil?
|
|
105
133
|
status 404
|
|
106
134
|
return
|
|
@@ -125,7 +153,7 @@ module Flapjack
|
|
|
125
153
|
entity_name = params[:captures][0]
|
|
126
154
|
check = params[:captures][1]
|
|
127
155
|
|
|
128
|
-
entity = entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis =>
|
|
156
|
+
entity = entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis)
|
|
129
157
|
if entity.nil?
|
|
130
158
|
status 404
|
|
131
159
|
return
|
|
@@ -136,10 +164,10 @@ module Flapjack
|
|
|
136
164
|
|
|
137
165
|
presenter = if check
|
|
138
166
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
139
|
-
check, :redis =>
|
|
167
|
+
check, :redis => redis)
|
|
140
168
|
Flapjack::API::EntityCheckPresenter.new(entity_check)
|
|
141
169
|
else
|
|
142
|
-
Flapjack::API::EntityPresenter.new(entity, :redis =>
|
|
170
|
+
Flapjack::API::EntityPresenter.new(entity, :redis => redis)
|
|
143
171
|
end
|
|
144
172
|
|
|
145
173
|
presenter.outages(start_time, end_time).to_json
|
|
@@ -151,7 +179,7 @@ module Flapjack
|
|
|
151
179
|
entity_name = params[:captures][0]
|
|
152
180
|
check = params[:captures][1]
|
|
153
181
|
|
|
154
|
-
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis =>
|
|
182
|
+
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis)
|
|
155
183
|
if entity.nil?
|
|
156
184
|
status 404
|
|
157
185
|
return
|
|
@@ -162,10 +190,10 @@ module Flapjack
|
|
|
162
190
|
|
|
163
191
|
presenter = if check
|
|
164
192
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
165
|
-
check, :redis =>
|
|
193
|
+
check, :redis => redis)
|
|
166
194
|
Flapjack::API::EntityCheckPresenter.new(entity_check)
|
|
167
195
|
else
|
|
168
|
-
Flapjack::API::EntityPresenter.new(entity, :redis =>
|
|
196
|
+
Flapjack::API::EntityPresenter.new(entity, :redis => redis)
|
|
169
197
|
end
|
|
170
198
|
|
|
171
199
|
presenter.unscheduled_maintenance(start_time, end_time).to_json
|
|
@@ -177,7 +205,7 @@ module Flapjack
|
|
|
177
205
|
entity_name = params[:captures][0]
|
|
178
206
|
check = params[:captures][1]
|
|
179
207
|
|
|
180
|
-
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis =>
|
|
208
|
+
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis)
|
|
181
209
|
if entity.nil?
|
|
182
210
|
status 404
|
|
183
211
|
return
|
|
@@ -188,10 +216,10 @@ module Flapjack
|
|
|
188
216
|
|
|
189
217
|
presenter = if check
|
|
190
218
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
191
|
-
check, :redis =>
|
|
219
|
+
check, :redis => redis)
|
|
192
220
|
Flapjack::API::EntityCheckPresenter.new(entity_check)
|
|
193
221
|
else
|
|
194
|
-
Flapjack::API::EntityPresenter.new(entity, :redis =>
|
|
222
|
+
Flapjack::API::EntityPresenter.new(entity, :redis => redis)
|
|
195
223
|
end
|
|
196
224
|
presenter.scheduled_maintenance(start_time, end_time).to_json
|
|
197
225
|
end
|
|
@@ -202,7 +230,7 @@ module Flapjack
|
|
|
202
230
|
entity_name = params[:captures][0]
|
|
203
231
|
check = params[:captures][1]
|
|
204
232
|
|
|
205
|
-
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis =>
|
|
233
|
+
entity = Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis)
|
|
206
234
|
if entity.nil?
|
|
207
235
|
status 404
|
|
208
236
|
return
|
|
@@ -213,10 +241,10 @@ module Flapjack
|
|
|
213
241
|
|
|
214
242
|
presenter = if check
|
|
215
243
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
216
|
-
check, :redis =>
|
|
244
|
+
check, :redis => redis)
|
|
217
245
|
Flapjack::API::EntityCheckPresenter.new(entity_check)
|
|
218
246
|
else
|
|
219
|
-
Flapjack::API::EntityPresenter.new(entity, :redis =>
|
|
247
|
+
Flapjack::API::EntityPresenter.new(entity, :redis => redis)
|
|
220
248
|
end
|
|
221
249
|
|
|
222
250
|
presenter.downtime(start_time, end_time).to_json
|
|
@@ -225,13 +253,13 @@ module Flapjack
|
|
|
225
253
|
# create a scheduled maintenance period for a service on an entity
|
|
226
254
|
post '/scheduled_maintenances/:entity/:check' do
|
|
227
255
|
content_type :json
|
|
228
|
-
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis =>
|
|
256
|
+
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis => redis)
|
|
229
257
|
if entity.nil?
|
|
230
258
|
status 404
|
|
231
259
|
return
|
|
232
260
|
end
|
|
233
261
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
234
|
-
params[:check], :redis =>
|
|
262
|
+
params[:check], :redis => redis)
|
|
235
263
|
entity_check.create_scheduled_maintenance(:start_time => params[:start_time],
|
|
236
264
|
:duration => params[:duration], :summary => params[:summary])
|
|
237
265
|
status 204
|
|
@@ -242,7 +270,7 @@ module Flapjack
|
|
|
242
270
|
# the entity-check as a whole
|
|
243
271
|
post '/acknowledgements/:entity/:check' do
|
|
244
272
|
content_type :json
|
|
245
|
-
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis =>
|
|
273
|
+
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis => redis)
|
|
246
274
|
if entity.nil?
|
|
247
275
|
status 404
|
|
248
276
|
return
|
|
@@ -252,12 +280,28 @@ module Flapjack
|
|
|
252
280
|
duration = (dur.nil? || (dur <= 0)) ? (4 * 60 * 60) : dur
|
|
253
281
|
|
|
254
282
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
255
|
-
params[:check], :redis =>
|
|
283
|
+
params[:check], :redis => redis)
|
|
256
284
|
entity_check.create_acknowledgement('summary' => params[:summary],
|
|
257
285
|
'duration' => duration)
|
|
258
286
|
status 204
|
|
259
287
|
end
|
|
260
288
|
|
|
289
|
+
post '/test_notifications/:entity/:check' do
|
|
290
|
+
content_type :json
|
|
291
|
+
entity = Flapjack::Data::Entity.find_by_name(params[:entity], :redis => redis)
|
|
292
|
+
if entity.nil?
|
|
293
|
+
status 404
|
|
294
|
+
return
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
summary = params[:summary] || "Testing notifications to all contacts interested in entity #{entity.name}"
|
|
298
|
+
|
|
299
|
+
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
300
|
+
params[:check], :redis => redis)
|
|
301
|
+
entity_check.test_notifications('summary' => summary)
|
|
302
|
+
status 204
|
|
303
|
+
end
|
|
304
|
+
|
|
261
305
|
post '/entities' do
|
|
262
306
|
pass unless 'application/json'.eql?(request.content_type)
|
|
263
307
|
content_type :json
|
|
@@ -272,7 +316,7 @@ module Flapjack
|
|
|
272
316
|
errors << "Entity not imported as it has no id: #{entity.inspect}"
|
|
273
317
|
next
|
|
274
318
|
end
|
|
275
|
-
Flapjack::Data::Entity.add(entity, :redis =>
|
|
319
|
+
Flapjack::Data::Entity.add(entity, :redis => redis)
|
|
276
320
|
end
|
|
277
321
|
ret = 200
|
|
278
322
|
else
|
|
@@ -291,13 +335,13 @@ module Flapjack
|
|
|
291
335
|
|
|
292
336
|
contacts = params[:contacts]
|
|
293
337
|
if contacts && contacts.is_a?(Enumerable) && contacts.any? {|c| !c['id'].nil?}
|
|
294
|
-
Flapjack::Data::Contact.delete_all(:redis =>
|
|
338
|
+
Flapjack::Data::Contact.delete_all(:redis => redis)
|
|
295
339
|
contacts.each do |contact|
|
|
296
340
|
unless contact['id']
|
|
297
341
|
logger.warn "Contact not imported as it has no id: #{contact.inspect}"
|
|
298
342
|
next
|
|
299
343
|
end
|
|
300
|
-
Flapjack::Data::Contact.add(contact, :redis =>
|
|
344
|
+
Flapjack::Data::Contact.add(contact, :redis => redis)
|
|
301
345
|
end
|
|
302
346
|
ret = 200
|
|
303
347
|
else
|
|
@@ -315,7 +359,7 @@ module Flapjack
|
|
|
315
359
|
|
|
316
360
|
def entity_check_status(entity, check)
|
|
317
361
|
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
|
318
|
-
check, :redis =>
|
|
362
|
+
check, :redis => redis)
|
|
319
363
|
return if entity_check.nil?
|
|
320
364
|
{ 'name' => check,
|
|
321
365
|
'state' => entity_check.state,
|