auxesis-flapjack 0.3.8 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -3
- data/Rakefile +10 -0
- data/TODO.md +16 -6
- data/bin/flapjack-notifier +3 -11
- data/flapjack.gemspec +8 -2
- data/lib/flapjack/cli/notifier.rb +131 -11
- data/lib/flapjack/cli/worker.rb +2 -1
- data/lib/flapjack/database.rb +10 -0
- data/lib/flapjack/models/check.rb +91 -0
- data/lib/flapjack/models/check_template.rb +18 -0
- data/lib/flapjack/models/node.rb +16 -0
- data/lib/flapjack/models/related_check.rb +13 -0
- data/lib/flapjack/notifier.rb +26 -25
- data/lib/flapjack/notifiers/mailer/init.rb +3 -0
- data/lib/flapjack/notifiers/{mailer.rb → mailer/mailer.rb} +6 -2
- data/lib/flapjack/notifiers/xmpp/init.rb +3 -0
- data/lib/flapjack/notifiers/{xmpp.rb → xmpp/xmpp.rb} +0 -0
- data/lib/flapjack/result.rb +0 -2
- metadata +70 -3
data/README.md
CHANGED
@@ -47,10 +47,13 @@ Install the following software through your package manager or from source:
|
|
47
47
|
Installation
|
48
48
|
------------
|
49
49
|
|
50
|
-
|
50
|
+
Add GitHub's RubyGems server to your Gem sources:
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
sudo gem sources -a http://gems.github.com
|
53
|
+
|
54
|
+
Install the Flapjack gem:
|
55
|
+
|
56
|
+
sudo gem install auxesis-flapjack
|
54
57
|
|
55
58
|
Then run the magic configuration script to set up init scripts:
|
56
59
|
|
data/Rakefile
CHANGED
@@ -63,3 +63,13 @@ if require 'yard'
|
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
66
|
+
|
67
|
+
desc "display FIXMEs in the codebase"
|
68
|
+
task :fixmes do
|
69
|
+
output = `grep -nR FIXME lib/* spec/* bin/`
|
70
|
+
output.split("\n").each do |line|
|
71
|
+
parts = line.split(':')
|
72
|
+
puts "#{parts[0].strip} +#{parts[1].strip}"
|
73
|
+
puts " - #{parts[3].strip}"
|
74
|
+
end
|
75
|
+
end
|
data/TODO.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
* daemonise notifier
|
1
|
+
* daemonise notifier - DONE
|
2
2
|
* provide config file for notifier
|
3
|
-
* specify which notifier plugins to load
|
4
|
-
* specify configuration for plugins (from address/xmmp login)
|
5
|
-
* write init scripts for notifier/worker-manager
|
3
|
+
* specify which notifier plugins to load - DONE
|
4
|
+
* specify configuration for plugins (from address/xmmp login) - DONE
|
5
|
+
* write init scripts for notifier/worker-manager - DONE
|
6
6
|
* hook notifier into web interface
|
7
|
-
* update status of checks
|
8
|
-
* relationships + cascading notifications
|
7
|
+
* update status of checks - DONE
|
8
|
+
* relationships + cascading notifications - DONE
|
9
|
+
* simple graphs
|
9
10
|
* package with pallet
|
10
11
|
* generate .deb/.rpms
|
12
|
+
* build packages for gem dependencies
|
13
|
+
* provide common interface for loading checks into beanstalk
|
14
|
+
* write check generator
|
15
|
+
* include a collection of common functions
|
16
|
+
(logging to rrd, retreiving values, executing check)
|
17
|
+
* write zeroconf/avahi notifier
|
18
|
+
* write growl notifier
|
19
|
+
* write way to customise notifier messages (email body, xmpp format)
|
20
|
+
* write sms notifier
|
data/bin/flapjack-notifier
CHANGED
@@ -10,8 +10,6 @@ require 'log4r'
|
|
10
10
|
require 'log4r/outputter/syslogoutputter'
|
11
11
|
require 'flapjack/result'
|
12
12
|
require 'flapjack/notifier'
|
13
|
-
require 'flapjack/notifiers/mailer'
|
14
|
-
require 'flapjack/notifiers/xmpp'
|
15
13
|
require 'daemons'
|
16
14
|
require 'flapjack/patches'
|
17
15
|
|
@@ -24,15 +22,9 @@ require 'flapjack/cli/notifier'
|
|
24
22
|
ncli = Flapjack::NotifierCLI.new
|
25
23
|
ncli.setup_loggers
|
26
24
|
ncli.setup_recipients(:filename => @options.recipients)
|
27
|
-
|
28
|
-
ncli.
|
29
|
-
|
30
|
-
ncli.log.debug("Loading XMPP notifier")
|
31
|
-
xmpp = Flapjack::Notifiers::Xmpp.new(:jid => "flapjack-test@jabber.org", :password => "test")
|
32
|
-
ncli.log.debug("Bringing up notifier subsystem")
|
33
|
-
ncli.notifier = Notifier.new(:logger => ncli.log,
|
34
|
-
:notifiers => [mailer], #, xmpp],
|
35
|
-
:recipients => ncli.recipients)
|
25
|
+
ncli.setup_config(:filename => @options.config_filename)
|
26
|
+
ncli.setup_notifier
|
27
|
+
ncli.setup_database(:database_uri => @options.database_uri)
|
36
28
|
|
37
29
|
begin
|
38
30
|
|
data/flapjack.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'flapjack'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.4.1'
|
4
4
|
s.date = '2009-05-26'
|
5
5
|
|
6
6
|
s.summary = "a scalable and distributed monitoring system"
|
@@ -16,10 +16,16 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency('log4r', '>= 1.0.5')
|
17
17
|
s.add_dependency('xmpp4r-simple', '>= 0.8.8')
|
18
18
|
s.add_dependency('mailfactory', '>= 1.4.0')
|
19
|
+
s.add_dependency('dm-core', '>= 0.9.11')
|
20
|
+
s.add_dependency('dm-timestamps', '>= 0.9.11')
|
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
25
|
|
20
26
|
s.bindir = "bin"
|
21
27
|
s.executables = ["flapjack-notifier", "flapjack-notifier-manager", "flapjack-stats", "flapjack-worker", "flapjack-worker-manager", "install-flapjack-systemwide"]
|
22
|
-
s.files = ["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", "etc/default/flapjack-notifier", "etc/default/flapjack-workers", "etc/flapjack/recipients.yaml", "etc/init.d/flapjack-notifier", "etc/init.d/flapjack-workers", "flapjack.gemspec", "lib/flapjack/cli/notifier.rb", "lib/flapjack/cli/notifier_manager.rb", "lib/flapjack/cli/worker.rb", "lib/flapjack/cli/worker_manager.rb", "lib/flapjack/notifier.rb", "lib/flapjack/notifiers/mailer.rb", "lib/flapjack/notifiers/xmpp.rb", "lib/flapjack/patches.rb", "lib/flapjack/result.rb"]
|
28
|
+
s.files = ["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", "etc/default/flapjack-notifier", "etc/default/flapjack-workers", "etc/flapjack/recipients.yaml", "etc/init.d/flapjack-notifier", "etc/init.d/flapjack-workers", "flapjack.gemspec", "lib/flapjack/cli/notifier.rb", "lib/flapjack/cli/notifier_manager.rb", "lib/flapjack/cli/worker.rb", "lib/flapjack/cli/worker_manager.rb", "lib/flapjack/database.rb", "lib/flapjack/models/check.rb", "lib/flapjack/models/check_template.rb", "lib/flapjack/models/node.rb", "lib/flapjack/models/related_check.rb", "lib/flapjack/notifier.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/result.rb"]
|
23
29
|
end
|
24
30
|
|
25
31
|
|
@@ -5,6 +5,7 @@ require 'ostruct'
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'log4r'
|
7
7
|
require 'log4r/outputter/syslogoutputter'
|
8
|
+
require File.join(File.dirname(__FILE__), '..', 'database')
|
8
9
|
|
9
10
|
module Flapjack
|
10
11
|
class NotifierOptions
|
@@ -21,6 +22,12 @@ module Flapjack
|
|
21
22
|
opts.on('-r', '--recipients FILE', 'recipients file') do |recipients|
|
22
23
|
options.recipients = recipients.to_s
|
23
24
|
end
|
25
|
+
opts.on('-c', '--config FILE', 'config file') do |config|
|
26
|
+
options.config_filename = config.to_s
|
27
|
+
end
|
28
|
+
opts.on('-d', '--database-uri URI', 'location of the checks database') do |db|
|
29
|
+
options.database_uri = db.to_s
|
30
|
+
end
|
24
31
|
opts.on_tail("-h", "--help", "Show this message") do
|
25
32
|
puts opts
|
26
33
|
exit
|
@@ -43,10 +50,27 @@ module Flapjack
|
|
43
50
|
|
44
51
|
@errors = []
|
45
52
|
# check that recipients file exists
|
46
|
-
|
47
|
-
|
53
|
+
if options.recipients
|
54
|
+
unless File.exists?(options.recipients.to_s)
|
55
|
+
@errors << "The specified recipients file doesn't exist!"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@errors << "You need to specify a recipients file with [-r|--recipients]."
|
48
59
|
end
|
49
|
-
|
60
|
+
|
61
|
+
# check that config file exists
|
62
|
+
if options.config_filename
|
63
|
+
unless File.exists?(options.config_filename.to_s)
|
64
|
+
@errors << "The specified config file doesn't exist!"
|
65
|
+
end
|
66
|
+
else
|
67
|
+
options.config_filename ||= "/etc/flapjack/flapjack-notifier.yaml"
|
68
|
+
unless File.exists?(options.config_filename.to_s)
|
69
|
+
@errors << "The default config file (#{options.config_filename}) doesn't exist!"
|
70
|
+
@errors << "Set one up, or specify one with [-c|--config]."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
50
74
|
# if there are errors, print them out and exit
|
51
75
|
if @errors.size > 0
|
52
76
|
puts "Errors:"
|
@@ -63,11 +87,13 @@ module Flapjack
|
|
63
87
|
end
|
64
88
|
|
65
89
|
class NotifierCLI
|
66
|
-
attr_accessor :log, :recipients, :
|
90
|
+
attr_accessor :log, :recipients, :results_queue, :config
|
91
|
+
attr_accessor :notifier, :notifiers
|
67
92
|
attr_accessor :condition
|
68
93
|
|
69
|
-
def initialize
|
70
|
-
@log =
|
94
|
+
def initialize(opts={})
|
95
|
+
@log = opts[:logger]
|
96
|
+
@log ||= Log4r::Logger.new("notifier")
|
71
97
|
end
|
72
98
|
|
73
99
|
def setup_loggers
|
@@ -83,11 +109,81 @@ module Flapjack
|
|
83
109
|
opts[:filename] ||= File.join(Dir.pwd, "recipients.yaml")
|
84
110
|
yaml = YAML::load(File.read(opts[:filename]))
|
85
111
|
end
|
86
|
-
|
112
|
+
|
113
|
+
# FIXME: add error detection for passing in dumb things
|
114
|
+
|
87
115
|
@recipients = yaml.map do |r|
|
88
116
|
OpenStruct.new(r)
|
89
117
|
end
|
90
118
|
end
|
119
|
+
|
120
|
+
def setup_config(opts={})
|
121
|
+
if opts[:yaml]
|
122
|
+
yaml = opts[:yaml]
|
123
|
+
else
|
124
|
+
opts[:filename] ||= File.join(Dir.pwd, "flapjack-notifier.yaml")
|
125
|
+
yaml = YAML::load(File.read(opts[:filename]))
|
126
|
+
end
|
127
|
+
|
128
|
+
@config = OpenStruct.new(yaml)
|
129
|
+
end
|
130
|
+
|
131
|
+
def setup_database(opts={})
|
132
|
+
uri = (opts[:database_uri] || @config.database_uri)
|
133
|
+
raise ArgumentError, "database URI wasn't specified!" unless uri
|
134
|
+
DataMapper.setup(:default, uri)
|
135
|
+
validate_database
|
136
|
+
end
|
137
|
+
|
138
|
+
def validate_database
|
139
|
+
begin
|
140
|
+
DataMapper.repository(:default).adapter.execute("SELECT 'id' FROM 'checks';")
|
141
|
+
rescue Sqlite3Error
|
142
|
+
@log.warning("The specified database doesn't appear to have any structure!")
|
143
|
+
@log.warning("You need to investigate this.")
|
144
|
+
end
|
145
|
+
# FIXME: add more rescues in here!
|
146
|
+
end
|
147
|
+
|
148
|
+
def initialize_notifiers(opts={})
|
149
|
+
notifiers_directory = opts[:notifiers_directory]
|
150
|
+
notifiers_directory ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'notifiers'))
|
151
|
+
|
152
|
+
raise ArgumentError, "notifiers directory doesn't exist!" unless File.exists?(notifiers_directory)
|
153
|
+
|
154
|
+
@notifiers = []
|
155
|
+
|
156
|
+
@config.notifiers.each_pair do |notifier, config|
|
157
|
+
filename = File.join(notifiers_directory, notifier.to_s, 'init')
|
158
|
+
if File.exists?(filename + '.rb')
|
159
|
+
@log.debug("Loading the #{notifier.to_s.capitalize} notifier")
|
160
|
+
require filename
|
161
|
+
@notifiers << Flapjack::Notifiers.const_get("#{notifier.to_s.capitalize}").new(config)
|
162
|
+
else
|
163
|
+
@log.warning("Flapjack::Notifiers::#{notifier.to_s.capitalize} doesn't exist!")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
@notifiers
|
168
|
+
end
|
169
|
+
|
170
|
+
# Sets up notifier to do the grunt work of notifying people when checks
|
171
|
+
# return badly.
|
172
|
+
#
|
173
|
+
# Accepts a list of recipients (:recipients) and a logger (:logger) as
|
174
|
+
# arguments. If neither of these are specified, it will default to an
|
175
|
+
# existing list of recipients and the current logger.
|
176
|
+
#
|
177
|
+
# Sets up and returns @notifier, an instance of Flapjack::Notifier
|
178
|
+
def setup_notifier(opts={})
|
179
|
+
recipients = (opts[:recipients] || @recipients)
|
180
|
+
log = (opts[:logger] || @log)
|
181
|
+
initialize_notifiers
|
182
|
+
notifiers = @notifiers # should we accept a list of notifiers?
|
183
|
+
@notifier = Flapjack::Notifier.new(:logger => log,
|
184
|
+
:notifiers => notifiers,
|
185
|
+
:recipients => recipients)
|
186
|
+
end
|
91
187
|
|
92
188
|
def process_loop
|
93
189
|
@log.info("Processing results...")
|
@@ -95,18 +191,42 @@ module Flapjack
|
|
95
191
|
process_result
|
96
192
|
end
|
97
193
|
end
|
98
|
-
|
194
|
+
|
195
|
+
def save_result(result)
|
196
|
+
if check = Check.get(result.id)
|
197
|
+
check.status = result.retval
|
198
|
+
check.save
|
199
|
+
else
|
200
|
+
@log.error("Got result for check #{result.id}, but it doesn't exist!")
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def any_parents_warning_or_critical?(result)
|
205
|
+
if check = Check.get(result.id)
|
206
|
+
check.worst_parent_status > 0 ? true : false
|
207
|
+
else
|
208
|
+
@log.error("Got result for check #{result.id}, but it doesn't exist!")
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
99
212
|
def process_result
|
100
213
|
@log.debug("Waiting for new result...")
|
101
|
-
result_job = @results_queue.reserve
|
214
|
+
result_job = @results_queue.reserve # blocks until a job is reserved
|
102
215
|
result = Result.new(YAML::load(result_job.body))
|
103
216
|
|
104
217
|
@log.info("Processing result for check '#{result.id}'")
|
105
218
|
if result.warning? || result.critical?
|
106
|
-
|
107
|
-
|
219
|
+
if any_parents_warning_or_critical?(result)
|
220
|
+
@log.info("Not notifying on check '#{result.id}' as parent is failing.")
|
221
|
+
else
|
222
|
+
@log.info("Notifying on check '#{result.id}'")
|
223
|
+
@notifier.notify!(result)
|
224
|
+
end
|
108
225
|
end
|
109
226
|
|
227
|
+
@log.info("Storing status of check in database")
|
228
|
+
save_result(result)
|
229
|
+
|
110
230
|
@log.debug("Deleting result for check '#{result.id}' from queue")
|
111
231
|
result_job.delete
|
112
232
|
end
|
data/lib/flapjack/cli/worker.rb
CHANGED
@@ -116,7 +116,8 @@ module Flapjack
|
|
116
116
|
def get_check
|
117
117
|
@log.debug("Waiting for check...")
|
118
118
|
job = @jobs.reserve
|
119
|
-
|
119
|
+
# FIXME: maybe wrap Result as Job now that Check is reserved?
|
120
|
+
check = Result.new(YAML::load(job.body))
|
120
121
|
@log.info("Got check with id #{check.id}")
|
121
122
|
|
122
123
|
return job, check
|
@@ -0,0 +1,91 @@
|
|
1
|
+
class Check
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
timestamps :at
|
5
|
+
|
6
|
+
has n, :related_checks, :child_key => [:child_id, :parent_id]
|
7
|
+
|
8
|
+
#has n, :parent_checks, :through => :related_checks,
|
9
|
+
# :child_key => :child_id, :class_name => "Check"
|
10
|
+
#has n, :child_checks, :through => :related_checks,
|
11
|
+
# :child_key => :parent_id, :class_name => "Check"
|
12
|
+
|
13
|
+
belongs_to :node
|
14
|
+
belongs_to :check_template
|
15
|
+
|
16
|
+
property :id, Serial, :key => true
|
17
|
+
property :command, Text, :nullable => false
|
18
|
+
property :params, Yaml
|
19
|
+
property :name, String, :nullable => false
|
20
|
+
property :enabled, Boolean, :default => false
|
21
|
+
property :status, Integer, :default => 0
|
22
|
+
|
23
|
+
# dm-timestamps
|
24
|
+
property :created_at, DateTime
|
25
|
+
property :updated_at, DateTime
|
26
|
+
property :deleted_at, ParanoidDateTime
|
27
|
+
|
28
|
+
# copy command onto check
|
29
|
+
before :valid? do
|
30
|
+
if self.check_template && self.command.blank?
|
31
|
+
self.command = self.check_template.command
|
32
|
+
self.name = self.check_template.name
|
33
|
+
self.params = (self.check_template.params || {})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def parameters_and_values
|
38
|
+
names = parameter_names_from_command
|
39
|
+
hash = {}
|
40
|
+
names.each { |name| hash[name] = params ? params[name] : "" }
|
41
|
+
hash["$FQDN"] = self.node_fqdn # pkey of node check belongs to
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def parameter_names_from_command
|
46
|
+
self.command.split.grep(/\$\w/)
|
47
|
+
end
|
48
|
+
|
49
|
+
def executed_command
|
50
|
+
c = self.command
|
51
|
+
parameters_and_values.each_pair do |param, value|
|
52
|
+
value = value.to_s
|
53
|
+
c.gsub!(param, value)
|
54
|
+
end
|
55
|
+
return c
|
56
|
+
end
|
57
|
+
|
58
|
+
# FIXME: this should work through related checks association, but doesn't
|
59
|
+
def parent_checks
|
60
|
+
RelatedCheck.all(:child_id => self.id).map {|rc| rc.parent_check}
|
61
|
+
end
|
62
|
+
|
63
|
+
def child_checks
|
64
|
+
RelatedCheck.all(:parent_id => self.id).map {|rc| rc.child_check}
|
65
|
+
end
|
66
|
+
|
67
|
+
def worst_parent_status
|
68
|
+
if parent_checks.size > 0
|
69
|
+
self.parent_checks.map { |parent| parent.status }.sort.pop
|
70
|
+
else
|
71
|
+
0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
GOOD = 0
|
77
|
+
BAD = 1
|
78
|
+
UGLY = 2
|
79
|
+
|
80
|
+
def pretty_print_status
|
81
|
+
case self.status
|
82
|
+
when GOOD
|
83
|
+
"good"
|
84
|
+
when BAD
|
85
|
+
"bad"
|
86
|
+
when UGLY
|
87
|
+
"ugly"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CheckTemplate
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
has n, :checks
|
5
|
+
|
6
|
+
property :id, Serial
|
7
|
+
property :command, Text, :nullable => false
|
8
|
+
property :name, String, :nullable => false
|
9
|
+
property :params, Yaml
|
10
|
+
|
11
|
+
validates_is_unique :command, :name
|
12
|
+
|
13
|
+
def name_for_select
|
14
|
+
cmd = (self.command.size > 30 ? "#{self.command[0..50]}..." : self.command)
|
15
|
+
"#{self.name} (#{cmd})"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Node
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
has n, :checks
|
5
|
+
|
6
|
+
property :fqdn, String, :key => true
|
7
|
+
|
8
|
+
validates_is_unique :fqdn
|
9
|
+
validates_format :fqdn, :with => /^[0-9|a-z|A-Z|\-|\.]*$/,
|
10
|
+
:message => "not a RFC1035-formatted FQDN (see section 2.3.1)"
|
11
|
+
|
12
|
+
def hostname
|
13
|
+
self.fqdn.split('.').first
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RelatedCheck
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
belongs_to :parent_check, :class_name => "Check", :child_key => [:parent_id]
|
5
|
+
belongs_to :child_check, :class_name => "Check", :child_key => [:child_id]
|
6
|
+
|
7
|
+
property :id, Serial, :key => true
|
8
|
+
#property :parent_check_id, Integer, :nullable => false
|
9
|
+
#property :child_check_id, Integer, :nullable => false
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
end
|
data/lib/flapjack/notifier.rb
CHANGED
@@ -2,33 +2,34 @@
|
|
2
2
|
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(opts={})
|
10
|
-
@log = opts[:logger]
|
11
|
-
raise "you have to specify a logger" unless @log
|
12
|
-
@recipients = (opts[:recipients] || [])
|
13
|
-
|
14
|
-
@notifiers = []
|
15
|
-
if opts[:notifiers]
|
16
|
-
opts[:notifiers].each do |n|
|
17
|
-
@notifiers << n
|
18
|
-
@log.info("using the #{n.class.to_s.split("::").last} notifier")
|
19
|
-
end
|
20
|
-
else
|
21
|
-
@log.warning("there are no notifiers")
|
22
|
-
end
|
23
|
-
end
|
5
|
+
module Flapjack
|
6
|
+
class Notifier
|
7
|
+
|
8
|
+
attr_reader :recipients, :log
|
24
9
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
10
|
+
def initialize(opts={})
|
11
|
+
@log = opts[:logger]
|
12
|
+
raise "you have to specify a logger" unless @log
|
13
|
+
@recipients = (opts[:recipients] || [])
|
14
|
+
|
15
|
+
@notifiers = []
|
16
|
+
if opts[:notifiers]
|
17
|
+
opts[:notifiers].each do |n|
|
18
|
+
@notifiers << n
|
19
|
+
@log.info("using the #{n.class.to_s.split("::").last} notifier")
|
20
|
+
end
|
21
|
+
else
|
22
|
+
@log.warning("there are no notifiers")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def notify!(result)
|
27
|
+
@notifiers.each do |n|
|
28
|
+
@recipients.each do |recipient|
|
29
|
+
@log.info("Notifying #{recipient.name} via #{n.class} about check #{result.id}")
|
30
|
+
n.notify(:result => result, :who => recipient)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
@@ -8,13 +8,17 @@ module Flapjack
|
|
8
8
|
module Notifiers
|
9
9
|
|
10
10
|
class Mailer
|
11
|
-
|
11
|
+
|
12
|
+
def initialize(opts={})
|
13
|
+
@from_address = opts[:from_address]
|
14
|
+
end
|
15
|
+
|
12
16
|
def notify(opts={})
|
13
17
|
raise unless (opts[:who] && opts[:result])
|
14
18
|
|
15
19
|
mail = MailFactory.new
|
16
20
|
mail.to = opts[:who].email
|
17
|
-
mail.from =
|
21
|
+
mail.from = @from_address
|
18
22
|
mail.subject = "Check: #{opts[:result].id}, Status: #{opts[:result].status}"
|
19
23
|
mail.text = <<-DESC
|
20
24
|
Check #{opts[:result].id} returned the status "#{opts[:result].status}".
|
File without changes
|
data/lib/flapjack/result.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auxesis-flapjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lindsay Holmwood
|
@@ -62,6 +62,66 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 1.4.0
|
64
64
|
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: dm-core
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.9.11
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: dm-timestamps
|
77
|
+
type: :runtime
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.9.11
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: dm-types
|
87
|
+
type: :runtime
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.11
|
94
|
+
version:
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: dm-validations
|
97
|
+
type: :runtime
|
98
|
+
version_requirement:
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.11
|
104
|
+
version:
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: data_objects
|
107
|
+
type: :runtime
|
108
|
+
version_requirement:
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 0.9.12
|
114
|
+
version:
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: do_sqlite3
|
117
|
+
type: :runtime
|
118
|
+
version_requirement:
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.9.12
|
124
|
+
version:
|
65
125
|
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.
|
66
126
|
email: lindsay@holmwood.id.au
|
67
127
|
executables:
|
@@ -95,9 +155,16 @@ files:
|
|
95
155
|
- lib/flapjack/cli/notifier_manager.rb
|
96
156
|
- lib/flapjack/cli/worker.rb
|
97
157
|
- lib/flapjack/cli/worker_manager.rb
|
158
|
+
- lib/flapjack/database.rb
|
159
|
+
- lib/flapjack/models/check.rb
|
160
|
+
- lib/flapjack/models/check_template.rb
|
161
|
+
- lib/flapjack/models/node.rb
|
162
|
+
- lib/flapjack/models/related_check.rb
|
98
163
|
- lib/flapjack/notifier.rb
|
99
|
-
- lib/flapjack/notifiers/mailer.rb
|
100
|
-
- lib/flapjack/notifiers/
|
164
|
+
- lib/flapjack/notifiers/mailer/init.rb
|
165
|
+
- lib/flapjack/notifiers/mailer/mailer.rb
|
166
|
+
- lib/flapjack/notifiers/xmpp/init.rb
|
167
|
+
- lib/flapjack/notifiers/xmpp/xmpp.rb
|
101
168
|
- lib/flapjack/patches.rb
|
102
169
|
- lib/flapjack/result.rb
|
103
170
|
has_rdoc: false
|