flapjack 0.4.12 → 0.5.1
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/README.md +77 -50
- data/Rakefile +78 -26
- data/TODO.md +15 -32
- data/bin/flapjack-benchmark +50 -0
- data/bin/flapjack-notifier +11 -36
- data/bin/flapjack-notifier-manager +1 -3
- data/bin/flapjack-worker +5 -19
- data/doc/PACKAGING.md +25 -0
- data/etc/flapjack/flapjack-notifier.conf.example +34 -0
- data/etc/flapjack/recipients.conf.example +14 -0
- data/features/flapjack-notifier-manager.feature +19 -0
- data/features/flapjack-worker-manager.feature +25 -0
- data/features/packaging-lintian.feature +15 -0
- data/features/persistence/couch.feature +105 -0
- data/features/persistence/sqlite3.feature +105 -0
- data/features/persistence/steps/couch_steps.rb +25 -0
- data/features/persistence/steps/generic_steps.rb +102 -0
- data/features/persistence/steps/sqlite3_steps.rb +13 -0
- data/features/steps/flapjack-notifier-manager_steps.rb +24 -0
- data/features/steps/flapjack-worker-manager_steps.rb +50 -0
- data/features/steps/packaging-lintian_steps.rb +13 -0
- data/features/support/env.rb +22 -0
- data/features/support/silent_system.rb +4 -0
- data/flapjack.gemspec +7 -11
- data/lib/flapjack/applications/notifier.rb +222 -0
- data/lib/flapjack/applications/worker.rb +99 -0
- data/lib/flapjack/checks/ping +10 -0
- data/lib/flapjack/cli/notifier.rb +80 -218
- data/lib/flapjack/cli/worker.rb +1 -86
- data/lib/flapjack/filters/any_parents_failed.rb +14 -0
- data/lib/flapjack/filters/ok.rb +13 -0
- data/lib/flapjack/inifile.rb +44 -0
- data/lib/flapjack/{notifier.rb → notifier_engine.rb} +13 -9
- data/lib/flapjack/notifiers/mailer/mailer.rb +12 -13
- data/lib/flapjack/notifiers/xmpp/xmpp.rb +2 -2
- data/lib/flapjack/patches.rb +25 -0
- data/lib/flapjack/persistence/couch.rb +5 -0
- data/lib/flapjack/persistence/couch/connection.rb +66 -0
- data/lib/flapjack/persistence/couch/couch.rb +63 -0
- data/lib/flapjack/persistence/data_mapper.rb +3 -0
- data/lib/flapjack/persistence/data_mapper/data_mapper.rb +67 -0
- data/lib/flapjack/{models → persistence/data_mapper/models}/check.rb +3 -7
- data/lib/flapjack/{models → persistence/data_mapper/models}/check_template.rb +0 -0
- data/lib/flapjack/persistence/data_mapper/models/event.rb +17 -0
- data/lib/flapjack/{models → persistence/data_mapper/models}/node.rb +0 -0
- data/lib/flapjack/{models → persistence/data_mapper/models}/related_check.rb +0 -0
- data/lib/flapjack/persistence/sqlite3.rb +3 -0
- data/lib/flapjack/persistence/sqlite3/sqlite3.rb +166 -0
- data/lib/flapjack/transports/beanstalkd.rb +33 -0
- data/lib/flapjack/transports/result.rb +58 -0
- metadata +46 -56
- data/etc/flapjack/flapjack-notifier.yaml.example +0 -8
- data/etc/flapjack/recipients.yaml.example +0 -10
- data/lib/flapjack/database.rb +0 -10
- data/lib/flapjack/result.rb +0 -47
@@ -0,0 +1,13 @@
|
|
1
|
+
Given /^I set up the Sqlite3 backend with the following options:$/ do |table|
|
2
|
+
@backend_options = table.hashes.first
|
3
|
+
@backend = Flapjack::Persistence::Sqlite3.new(@backend_options)
|
4
|
+
end
|
5
|
+
|
6
|
+
Then /^the check with id "([^\"]*)" on the Sqlite3 backend should have an event created$/ do |id|
|
7
|
+
@backend.all_events_for(id).size.should > 0
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^the check with id "([^\"]*)" on the Sqlite3 backend should have a status of "([^\"]*)"$/ do |id, status|
|
11
|
+
@backend.get_check(id)["status"].should == status
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
__DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
2
|
+
bin_path = File.join(__DIR__, 'bin')
|
3
|
+
|
4
|
+
Given /^there are no instances of flapjack\-notifier running$/ do
|
5
|
+
command = "#{bin_path}/flapjack-notifier-manager stop"
|
6
|
+
silent_system(command)
|
7
|
+
|
8
|
+
sleep 0.5 # wait for the notifier manager
|
9
|
+
|
10
|
+
output = `ps -eo cmd |grep ^flapjack-notifier`
|
11
|
+
output.split.size.should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
Given /^there is an instance of the flapjack\-notifier running$/ do
|
15
|
+
command = "#{bin_path}/flapjack-notifier-manager start"
|
16
|
+
command += " --recipients spec/fixtures/recipients.yaml --config spec/fixtures/flapjack-notifier.yaml"
|
17
|
+
silent_system(command).should be_true
|
18
|
+
|
19
|
+
sleep 0.5 # again, waiting for the notifier manager
|
20
|
+
|
21
|
+
output = `ps -eo cmd |grep ^flapjack-notifier`
|
22
|
+
output.split.size.should == 1
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
__DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
2
|
+
|
3
|
+
Given /^the (.+) is on my path$/ do |command|
|
4
|
+
@bin_path = File.join(__DIR__, 'bin')
|
5
|
+
# (and is executable)
|
6
|
+
silent_system("test -x #{@bin_path}/#{command}").should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /^the "([^\"]*)" directory exists and is writable$/ do |directory|
|
10
|
+
File.exists?(directory).should be_true
|
11
|
+
File.writable?(directory).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^I run "([^\"]*)"$/ do |cmd|
|
15
|
+
parts = [cmd]
|
16
|
+
parts.unshift(@bin_path) if @bin_path
|
17
|
+
command = parts.join('/')
|
18
|
+
# this might be dodgy
|
19
|
+
@output = `#{command}`
|
20
|
+
#@output.size.should > 0
|
21
|
+
#p command
|
22
|
+
#p @output
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^(\d+) instances of "([^\"]*)" should be running$/ do |number, command|
|
26
|
+
sleep 0.5 # this truly is a dodgy hack.
|
27
|
+
# sometimes the the worker manager can take a while to fork
|
28
|
+
output = `ps -eo cmd |grep ^#{command} |grep -v grep`
|
29
|
+
output.split.size.should >= number.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
Given /^there are (\d+) instances of the flapjack\-worker running$/ do |number|
|
33
|
+
command = "#{@bin_path}/flapjack-worker-manager start --workers=5"
|
34
|
+
silent_system(command).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
Given /^there are no instances of flapjack\-worker running$/ do
|
38
|
+
command = "#{@bin_path}/flapjack-worker-manager stop"
|
39
|
+
silent_system(command)
|
40
|
+
|
41
|
+
sleep 0.5 # again, waiting for the worker manager
|
42
|
+
|
43
|
+
output = `ps -eo cmd |grep ^flapjack-worker |grep -v grep`
|
44
|
+
output.split("\n").size.should == 0
|
45
|
+
end
|
46
|
+
|
47
|
+
Given /^beanstalkd is running on localhost$/ do
|
48
|
+
output = `ps -eo cmd |grep beanstalkd |grep -v grep`
|
49
|
+
output.split("\n").size.should == 1
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Given /^I am at the project root$/ do
|
2
|
+
Dir.pwd.split('/').last.should == "flapjack"
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should see (\d+) lines of output$/ do |number|
|
6
|
+
@output.split.size.should == number.to_i
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^every file in the output should start with "([^\"]*)"$/ do |string|
|
10
|
+
@output.split.each do |file|
|
11
|
+
`head -n 1 #{file}`.should =~ /^#{string}\s*$/
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
|
+
|
5
|
+
require 'flapjack/inifile'
|
6
|
+
require 'flapjack/filters/ok'
|
7
|
+
require 'flapjack/filters/any_parents_failed'
|
8
|
+
require 'flapjack/notifier_engine'
|
9
|
+
require 'flapjack/transports/result'
|
10
|
+
require 'flapjack/transports/beanstalkd'
|
11
|
+
require 'flapjack/patches'
|
12
|
+
require 'flapjack/inifile'
|
13
|
+
require 'flapjack/cli/worker_manager'
|
14
|
+
require 'flapjack/cli/notifier_manager'
|
15
|
+
require 'flapjack/cli/notifier'
|
16
|
+
require 'flapjack/cli/worker'
|
17
|
+
require 'flapjack/persistence/couch'
|
18
|
+
require 'flapjack/persistence/sqlite3'
|
19
|
+
require 'flapjack/applications/notifier'
|
20
|
+
require 'flapjack/applications/worker'
|
21
|
+
require 'flapjack/notifiers/mailer/init'
|
22
|
+
require 'flapjack/notifiers/xmpp/init'
|
data/flapjack.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'flapjack'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '
|
3
|
+
s.version = '0.5.1'
|
4
|
+
s.date = '2010-02-28'
|
5
5
|
|
6
6
|
s.summary = "a scalable and distributed monitoring system"
|
7
7
|
s.description = "Flapjack is highly scalable and distributed monitoring system. It understands the Nagios plugin format, and can easily be scaled from 1 server to 1000."
|
@@ -13,19 +13,15 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.add_dependency('daemons', '= 1.0.10')
|
15
15
|
s.add_dependency('beanstalk-client', '= 1.0.2')
|
16
|
-
s.add_dependency('log4r', '= 1.
|
16
|
+
s.add_dependency('log4r', '= 1.1.5')
|
17
17
|
s.add_dependency('xmpp4r', '= 0.5')
|
18
18
|
s.add_dependency('tmail', '= 1.2.3.1')
|
19
|
-
s.add_dependency('
|
20
|
-
s.add_dependency('
|
21
|
-
s.add_dependency('dm-types', '= 0.9.11')
|
22
|
-
s.add_dependency('dm-validations', '= 0.9.11')
|
23
|
-
s.add_dependency('data_objects', '= 0.9.12')
|
24
|
-
s.add_dependency('do_sqlite3', '= 0.9.12')
|
19
|
+
s.add_dependency('yajl-ruby', '= 0.6.4')
|
20
|
+
s.add_dependency('sqlite3-ruby', '= 1.2.5')
|
25
21
|
|
26
22
|
s.bindir = "bin"
|
27
|
-
s.executables = ["flapjack-notifier", "flapjack-notifier-manager", "flapjack-stats", "flapjack-worker", "flapjack-worker-manager", "install-flapjack-systemwide"]
|
28
|
-
s.files = ["LICENCE", "README.md", "Rakefile", "TODO.md", "bin/flapjack-notifier", "bin/flapjack-notifier-manager", "bin/flapjack-stats", "bin/flapjack-worker", "bin/flapjack-worker-manager", "bin/install-flapjack-systemwide", "doc/CONFIGURING.md", "doc/DEVELOPING.md", "doc/INSTALL.md", "etc/default/flapjack-notifier", "etc/default/flapjack-workers", "etc/flapjack/flapjack-notifier.
|
23
|
+
s.executables = ["flapjack-benchmark", "flapjack-notifier", "flapjack-notifier-manager", "flapjack-stats", "flapjack-worker", "flapjack-worker-manager", "install-flapjack-systemwide" ]
|
24
|
+
s.files = ["LICENCE", "README.md", "Rakefile", "TODO.md", "bin/flapjack-benchmark", "bin/flapjack-notifier", "bin/flapjack-notifier-manager", "bin/flapjack-stats", "bin/flapjack-worker", "bin/flapjack-worker-manager", "bin/install-flapjack-systemwide", "doc/CONFIGURING.md", "doc/DEVELOPING.md", "doc/INSTALL.md", "doc/PACKAGING.md", "etc/default/flapjack-notifier", "etc/default/flapjack-workers", "etc/flapjack/flapjack-notifier.conf.example", "etc/flapjack/recipients.conf.example", "etc/init.d/flapjack-notifier", "etc/init.d/flapjack-workers", "features/flapjack-notifier-manager.feature", "features/flapjack-worker-manager.feature", "features/packaging-lintian.feature", "features/persistence/couch.feature", "features/persistence/sqlite3.feature", "features/persistence/steps/couch_steps.rb", "features/persistence/steps/generic_steps.rb", "features/persistence/steps/sqlite3_steps.rb", "features/steps/flapjack-notifier-manager_steps.rb", "features/steps/flapjack-worker-manager_steps.rb", "features/steps/packaging-lintian_steps.rb", "features/support/env.rb", "features/support/silent_system.rb", "flapjack.gemspec", "lib/flapjack/applications/notifier.rb", "lib/flapjack/applications/worker.rb", "lib/flapjack/checks/http_content", "lib/flapjack/checks/ping", "lib/flapjack/cli/notifier.rb", "lib/flapjack/cli/notifier_manager.rb", "lib/flapjack/cli/worker.rb", "lib/flapjack/cli/worker_manager.rb", "lib/flapjack/filters/any_parents_failed.rb", "lib/flapjack/filters/ok.rb", "lib/flapjack/inifile.rb", "lib/flapjack/notifier_engine.rb", "lib/flapjack/notifiers/mailer/init.rb", "lib/flapjack/notifiers/mailer/mailer.rb", "lib/flapjack/notifiers/xmpp/init.rb", "lib/flapjack/notifiers/xmpp/xmpp.rb", "lib/flapjack/patches.rb", "lib/flapjack/persistence/couch.rb", "lib/flapjack/persistence/couch/connection.rb", "lib/flapjack/persistence/couch/couch.rb", "lib/flapjack/persistence/data_mapper.rb", "lib/flapjack/persistence/data_mapper/data_mapper.rb", "lib/flapjack/persistence/data_mapper/models/check.rb", "lib/flapjack/persistence/data_mapper/models/check_template.rb", "lib/flapjack/persistence/data_mapper/models/event.rb", "lib/flapjack/persistence/data_mapper/models/node.rb", "lib/flapjack/persistence/data_mapper/models/related_check.rb", "lib/flapjack/persistence/sqlite3.rb", "lib/flapjack/persistence/sqlite3/sqlite3.rb", "lib/flapjack/transports/beanstalkd.rb", "lib/flapjack/transports/result.rb"]
|
29
25
|
end
|
30
26
|
|
31
27
|
|
@@ -0,0 +1,222 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
4
|
+
require 'log4r'
|
5
|
+
require 'log4r/outputter/syslogoutputter'
|
6
|
+
require 'flapjack/patches'
|
7
|
+
require 'flapjack/notifier_engine'
|
8
|
+
|
9
|
+
module Flapjack
|
10
|
+
module Notifier
|
11
|
+
class Application
|
12
|
+
|
13
|
+
# boots the notifier
|
14
|
+
def self.run(options={})
|
15
|
+
app = self.new(options)
|
16
|
+
app.setup_config
|
17
|
+
app.setup_loggers
|
18
|
+
app.setup_notifiers
|
19
|
+
app.setup_notifier_engine
|
20
|
+
app.setup_recipients
|
21
|
+
app.setup_persistence
|
22
|
+
app.setup_queues
|
23
|
+
app.setup_filters
|
24
|
+
|
25
|
+
app
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_accessor :log, :recipients
|
29
|
+
|
30
|
+
def initialize(options={})
|
31
|
+
@log = options[:log]
|
32
|
+
@notifier_directories = options[:notifier_directories]
|
33
|
+
@filter_directories = options[:filter_directories]
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_loggers
|
38
|
+
unless @log
|
39
|
+
@log = Log4r::Logger.new("notifier")
|
40
|
+
@log.add(Log4r::StdoutOutputter.new("notifier"))
|
41
|
+
@log.add(Log4r::SyslogOutputter.new("notifier"))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_config
|
46
|
+
@config = OpenStruct.new(@options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup_notifiers
|
50
|
+
@notifier_directories ||= []
|
51
|
+
|
52
|
+
default_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'notifiers'))
|
53
|
+
# the default directory should be the last in the list
|
54
|
+
if @notifier_directories.include?(default_directory)
|
55
|
+
@notifier_directories << @notifier_directories.delete(default_directory)
|
56
|
+
else
|
57
|
+
@notifier_directories << default_directory
|
58
|
+
end
|
59
|
+
|
60
|
+
# filter to the directories that actually exist
|
61
|
+
@notifier_directories = @notifier_directories.find_all do |dir|
|
62
|
+
if File.exists?(dir)
|
63
|
+
true
|
64
|
+
else
|
65
|
+
@log.warning("Notifiers directory #{dir} doesn't exist. Skipping.")
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
@notifiers = []
|
71
|
+
|
72
|
+
# load up the notifiers and pass a config
|
73
|
+
@config.notifiers.each_pair do |notifier, config|
|
74
|
+
filenames = @notifier_directories.map {|dir| File.join(dir, notifier.to_s, 'init' + '.rb')}
|
75
|
+
filename = filenames.find {|filename| File.exists?(filename)}
|
76
|
+
|
77
|
+
if filename
|
78
|
+
@log.info("Loading the #{notifier.to_s.capitalize} notifier (from #{filename})")
|
79
|
+
require filename
|
80
|
+
config.merge!(:log => @log)
|
81
|
+
notifier = Flapjack::Notifiers.const_get("#{notifier.to_s.capitalize}").new(config)
|
82
|
+
@notifiers << notifier
|
83
|
+
else
|
84
|
+
@log.warning("Flapjack::Notifiers::#{notifier.to_s.capitalize} doesn't exist!")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def setup_notifier_engine
|
91
|
+
options = { :log => @log, :notifiers => @notifiers }
|
92
|
+
@notifier_engine = Flapjack::NotifierEngine.new(options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def setup_recipients
|
96
|
+
@recipients ||= []
|
97
|
+
|
98
|
+
@recipients += (@config.recipients || [])
|
99
|
+
# so poking at a recipient within notifiers is easier
|
100
|
+
@recipients.map! do |recipient|
|
101
|
+
OpenStruct.new(recipient)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def setup_persistence
|
106
|
+
defaults = { :backend => :data_mapper,
|
107
|
+
:log => @log }
|
108
|
+
config = defaults.merge(@config.persistence || {})
|
109
|
+
basedir = config.delete(:basedir) || File.join(File.dirname(__FILE__), '..', 'persistence')
|
110
|
+
|
111
|
+
filename = File.join(basedir, "#{config[:backend]}.rb")
|
112
|
+
class_name = config[:backend].to_s.camel_case
|
113
|
+
|
114
|
+
@log.info("Loading the #{class_name} persistence backend")
|
115
|
+
|
116
|
+
begin
|
117
|
+
require filename
|
118
|
+
@persistence = Flapjack::Persistence.const_get(class_name).new(config)
|
119
|
+
rescue LoadError => e
|
120
|
+
@log.warning("Attempted to load #{class_name} persistence backend, but it doesn't exist!")
|
121
|
+
@log.warning("Exiting.")
|
122
|
+
raise # preserves original exception
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
def setup_queues
|
128
|
+
defaults = { :backend => :beanstalkd,
|
129
|
+
:host => 'localhost',
|
130
|
+
:port => '11300',
|
131
|
+
:queue_name => 'results',
|
132
|
+
:log => @log }
|
133
|
+
config = defaults.merge(@config.transport || {})
|
134
|
+
basedir = config.delete(:basedir) || File.join(File.dirname(__FILE__), '..', 'transports')
|
135
|
+
|
136
|
+
class_name = config[:backend].to_s.camel_case
|
137
|
+
filename = File.join(basedir, "#{config[:backend]}.rb")
|
138
|
+
|
139
|
+
@log.info("Loading the #{class_name} transport")
|
140
|
+
|
141
|
+
begin
|
142
|
+
require filename
|
143
|
+
@results_queue = Flapjack::Transport.const_get(class_name).new(config)
|
144
|
+
rescue LoadError => e
|
145
|
+
@log.warning("Attempted to load #{class_name} transport, but it doesn't exist!")
|
146
|
+
@log.warning("Exiting.")
|
147
|
+
raise # preserves original exception
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def setup_filters
|
152
|
+
@filter_directories ||= []
|
153
|
+
|
154
|
+
default_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'filters'))
|
155
|
+
# the default directory should be the last in the list
|
156
|
+
if @filter_directories.include?(default_directory)
|
157
|
+
@filter_directories << @filter_directories.delete(default_directory)
|
158
|
+
else
|
159
|
+
@filter_directories << default_directory
|
160
|
+
end
|
161
|
+
|
162
|
+
# filter to the directories that actually exist
|
163
|
+
@filter_directories = @filter_directories.find_all do |dir|
|
164
|
+
if File.exists?(dir)
|
165
|
+
true
|
166
|
+
else
|
167
|
+
@log.warning("Filters directory #{dir} doesn't exist. Skipping.")
|
168
|
+
false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
@filters = []
|
173
|
+
|
174
|
+
@config.filters.each do |filter|
|
175
|
+
filenames = @filter_directories.map {|dir| File.join(dir, filter.to_s + '.rb')}
|
176
|
+
filename = filenames.find {|filename| File.exists?(filename)}
|
177
|
+
|
178
|
+
if filename
|
179
|
+
@log.info("Loading the #{filter.camel_case} filter (from #{filename})")
|
180
|
+
require filename
|
181
|
+
filter = Flapjack::Filters.const_get(filter.camel_case).new(:log => @log, :persistence => @persistence)
|
182
|
+
@filters << filter
|
183
|
+
else
|
184
|
+
@log.warning("Flapjack::Filters::#{filter.camel_case} doesn't exist!")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
def process_result
|
191
|
+
@log.debug("Waiting for new result...")
|
192
|
+
result = @results_queue.next # this blocks until a result is popped
|
193
|
+
|
194
|
+
@log.info("Processing result for check #{result.check_id}.")
|
195
|
+
event = @persistence.create_event(result)
|
196
|
+
|
197
|
+
|
198
|
+
block = @filters.find {|filter| filter.block?(result) }
|
199
|
+
unless block
|
200
|
+
# do munging
|
201
|
+
@notifier_engine.notify!(:result => result,
|
202
|
+
:event => event,
|
203
|
+
:recipients => recipients)
|
204
|
+
end
|
205
|
+
|
206
|
+
@log.info("Storing status of check.")
|
207
|
+
@persistence.save(result)
|
208
|
+
|
209
|
+
@log.info("Deleting result for check #{result.check_id}.")
|
210
|
+
@results_queue.delete(result)
|
211
|
+
end
|
212
|
+
|
213
|
+
def main
|
214
|
+
@log.info("Booting main loop.")
|
215
|
+
loop do
|
216
|
+
process_result
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'log4r/outputter/syslogoutputter'
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'patches'))
|
6
|
+
|
7
|
+
module Flapjack
|
8
|
+
module Worker
|
9
|
+
class Application
|
10
|
+
|
11
|
+
# boots the notifier
|
12
|
+
def self.run(options={})
|
13
|
+
app = self.new(options)
|
14
|
+
app.setup_loggers
|
15
|
+
app.setup_config
|
16
|
+
app.setup_queues
|
17
|
+
|
18
|
+
app
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :log
|
22
|
+
|
23
|
+
def initialize(options={})
|
24
|
+
@log = options[:log]
|
25
|
+
@notifier_directories = options[:notifier_directories]
|
26
|
+
@options = options
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_loggers
|
30
|
+
unless @log
|
31
|
+
@log = Log4r::Logger.new("notifier")
|
32
|
+
@log.add(Log4r::StdoutOutputter.new("notifier"))
|
33
|
+
@log.add(Log4r::SyslogOutputter.new("notifier"))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_config
|
38
|
+
@config = OpenStruct.new(@options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_queues
|
42
|
+
defaults = { :backend => :beanstalkd,
|
43
|
+
:host => 'localhost',
|
44
|
+
:port => '11300',
|
45
|
+
:log => @log }
|
46
|
+
config = defaults.merge(@config.transport || {})
|
47
|
+
basedir = config.delete(:basedir) || File.join(File.dirname(__FILE__), '..', 'transports')
|
48
|
+
|
49
|
+
%w(results checks).each do |queue_name|
|
50
|
+
|
51
|
+
queue_config = config.merge(:queue_name => queue_name)
|
52
|
+
|
53
|
+
class_name = config[:backend].to_s.camel_case
|
54
|
+
filename = File.join(basedir, "#{config[:backend]}.rb")
|
55
|
+
|
56
|
+
@log.info("Loading the #{class_name} transport for queue: #{queue_name}.")
|
57
|
+
|
58
|
+
begin
|
59
|
+
require filename
|
60
|
+
queue = Flapjack::Transport.const_get("#{class_name}").new(queue_config)
|
61
|
+
instance_variable_set("@#{queue_name}_queue", queue)
|
62
|
+
rescue LoadError => e
|
63
|
+
@log.warning("Attempted to load #{class_name} transport, but it doesn't exist!")
|
64
|
+
@log.warning("Exiting.")
|
65
|
+
raise # preserves original exception
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_check
|
71
|
+
@log.info("Waiting for check...")
|
72
|
+
check = @checks_queue.next
|
73
|
+
@log.info("Processing check with id #{check.check_id}")
|
74
|
+
|
75
|
+
command = "sh -c '#{check.command}'"
|
76
|
+
@log.info("Executing check: #{command}")
|
77
|
+
|
78
|
+
output = `#{command}`
|
79
|
+
return_value = $?.exitstatus
|
80
|
+
|
81
|
+
@log.info("Sending result.")
|
82
|
+
@results_queue.put({:check_id => check.check_id, :output => output, :retval => return_value})
|
83
|
+
@log.info("Returning check to transport.")
|
84
|
+
@checks_queue.put({:check_id => check.check_id, :command => check.command, :frequency => check.frequency})
|
85
|
+
|
86
|
+
@log.info("Cleaning up check.")
|
87
|
+
@checks_queue.delete(check)
|
88
|
+
end
|
89
|
+
|
90
|
+
def main
|
91
|
+
@log.info("Booting main loop.")
|
92
|
+
loop do
|
93
|
+
process_check
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|