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
File without changes
|
File without changes
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sqlite3'
|
4
|
+
|
5
|
+
module Flapjack
|
6
|
+
module Persistence
|
7
|
+
class Sqlite3
|
8
|
+
def initialize(options={})
|
9
|
+
@options = options
|
10
|
+
@config = OpenStruct.new(options)
|
11
|
+
@log = @config.log
|
12
|
+
connect
|
13
|
+
end
|
14
|
+
|
15
|
+
def any_parents_failed?(check_id)
|
16
|
+
rows = @db.execute(%(SELECT count(*) FROM "checks" INNER JOIN "related_checks" ON "related_checks".parent_id = "checks".id AND "related_checks".child_id = #{check_id};))
|
17
|
+
rows.flatten.first != "0"
|
18
|
+
end
|
19
|
+
|
20
|
+
def save_check(result)
|
21
|
+
if check = get_check(result[:id])
|
22
|
+
result[:updated_at] = Time.now
|
23
|
+
updates = result.map { |key, value| "#{key} = '#{value}'" }.join(', ')
|
24
|
+
statement = %(UPDATE "checks" SET #{updates} WHERE "id" = #{result[:id]};)
|
25
|
+
@db.execute(statement)
|
26
|
+
else
|
27
|
+
result[:created_at] = Time.now
|
28
|
+
columns, values = columns_and_values_for(result)
|
29
|
+
@db.execute(%(INSERT INTO "checks" #{columns} VALUES #{values}))
|
30
|
+
end
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_check(id)
|
35
|
+
result = @db.execute2(%(SELECT * FROM "checks" WHERE id = "#{id}"))
|
36
|
+
return nil unless result[1]
|
37
|
+
hash = {}
|
38
|
+
result[0].each_with_index do |key, index|
|
39
|
+
hash[key] = result[1][index]
|
40
|
+
end
|
41
|
+
hash
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_check(id)
|
45
|
+
result = @db.execute2(%(DELETE FROM "checks" WHERE id = "#{id}"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def all_checks
|
49
|
+
results = @db.execute2(%(SELECT * FROM "checks";))
|
50
|
+
|
51
|
+
records = results[1..-1].map do |values|
|
52
|
+
hash = {}
|
53
|
+
values.each_with_index do |value, index|
|
54
|
+
hash[results[0][index]] = value
|
55
|
+
end
|
56
|
+
hash
|
57
|
+
end
|
58
|
+
|
59
|
+
records
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_check_relationship(attrs)
|
63
|
+
columns, values = columns_and_values_for(attrs)
|
64
|
+
@db.execute(%(INSERT INTO "related_checks" #{columns} VALUES #{values}))
|
65
|
+
end
|
66
|
+
|
67
|
+
def all_check_relationships
|
68
|
+
results = @db.execute2(%(SELECT * FROM "related_checks";))
|
69
|
+
|
70
|
+
records = results[1..-1].map do |values|
|
71
|
+
hash = {}
|
72
|
+
values.each_with_index do |value, index|
|
73
|
+
hash[results[0][index]] = value
|
74
|
+
end
|
75
|
+
hash
|
76
|
+
end
|
77
|
+
|
78
|
+
records
|
79
|
+
end
|
80
|
+
|
81
|
+
# events
|
82
|
+
def all_events_for(id)
|
83
|
+
results = @db.execute2(%(SELECT * FROM "events" WHERE check_id = #{id}))
|
84
|
+
|
85
|
+
records = results[1..-1].map do |values|
|
86
|
+
hash = {}
|
87
|
+
values.each_with_index do |value, index|
|
88
|
+
hash[results[0][index]] = value
|
89
|
+
end
|
90
|
+
hash
|
91
|
+
end
|
92
|
+
|
93
|
+
records
|
94
|
+
end
|
95
|
+
|
96
|
+
def all_events
|
97
|
+
results = @db.execute2(%(SELECT * FROM "events";))
|
98
|
+
|
99
|
+
records = results[1..-1].map do |values|
|
100
|
+
hash = {}
|
101
|
+
values.each_with_index do |value, index|
|
102
|
+
hash[results[0][index]] = value
|
103
|
+
end
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
|
107
|
+
records
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_event(result)
|
111
|
+
@db.execute(%(INSERT INTO "events" ("check_id", "created_at") VALUES ("#{result.result.check_id}", "#{Time.now}")))
|
112
|
+
true
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
def connect
|
117
|
+
raise ArgumentError, "Database location wasn't specified" unless @config.database
|
118
|
+
@db = ::SQLite3::Database.new(@config.database)
|
119
|
+
|
120
|
+
auto_migrate if @config.auto_migrate
|
121
|
+
end
|
122
|
+
|
123
|
+
def auto_migrate
|
124
|
+
statements = [
|
125
|
+
%(DROP TABLE IF EXISTS "check_templates"),
|
126
|
+
%(DROP TABLE IF EXISTS "events"),
|
127
|
+
%(DROP TABLE IF EXISTS "related_checks"),
|
128
|
+
%(DROP TABLE IF EXISTS "checks"),
|
129
|
+
%(DROP TABLE IF EXISTS "nodes"),
|
130
|
+
%(PRAGMA table_info('nodes')),
|
131
|
+
%(SELECT sqlite_version(*)),
|
132
|
+
%(CREATE TABLE "nodes" ("fqdn" VARCHAR(50) NOT NULL, PRIMARY KEY("fqdn"))),
|
133
|
+
%(PRAGMA table_info('checks')),
|
134
|
+
%(CREATE TABLE "checks" ("created_at" DATETIME, "updated_at" DATETIME, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "command" TEXT NOT NULL, "params" TEXT DEFAULT NULL, "name" VARCHAR(50) NOT NULL, "enabled" BOOLEAN DEFAULT 'f', "status" INTEGER DEFAULT 0, "deleted_at" DATETIME DEFAULT NULL, "node_fqdn" VARCHAR(50), "check_template_id" INTEGER)),
|
135
|
+
%(PRAGMA table_info('related_checks')),
|
136
|
+
%(CREATE TABLE "related_checks" ("parent_id" INTEGER, "child_id" INTEGER, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)),
|
137
|
+
%(PRAGMA table_info('events')),
|
138
|
+
%(CREATE TABLE "events" ("created_at" DATETIME, "updated_at" DATETIME, "check_id" INTEGER NOT NULL, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" DATETIME DEFAULT NULL)),
|
139
|
+
%(PRAGMA table_info('check_templates')),
|
140
|
+
%(CREATE TABLE "check_templates" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "command" TEXT NOT NULL, "name" VARCHAR(50) NOT NULL, "params" TEXT DEFAULT NULL))
|
141
|
+
]
|
142
|
+
|
143
|
+
statements.each do |statement|
|
144
|
+
@db.execute(statement)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def columns_and_values_for(result)
|
149
|
+
@keys = []
|
150
|
+
@values = []
|
151
|
+
|
152
|
+
result.each_pair do |k,v|
|
153
|
+
@keys << k
|
154
|
+
@values << v
|
155
|
+
end
|
156
|
+
|
157
|
+
keys = "(\"" + @keys.join(%(", ")) + "\")"
|
158
|
+
values = "(\"" + @values.join(%(", ")) + "\")"
|
159
|
+
|
160
|
+
return keys, values
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
4
|
+
require 'beanstalk-client'
|
5
|
+
require 'flapjack/transports/result'
|
6
|
+
|
7
|
+
module Flapjack
|
8
|
+
module Transport
|
9
|
+
class Beanstalkd
|
10
|
+
def initialize(options={})
|
11
|
+
@options = options
|
12
|
+
@config = OpenStruct.new(options)
|
13
|
+
|
14
|
+
unless @config.host && @config.port && @config.queue_name
|
15
|
+
raise ArgumentError, "You need to specify a beanstalkd host, port, and queue name to connect to."
|
16
|
+
end
|
17
|
+
|
18
|
+
@queue = Beanstalk::Pool.new(["#{@config.host}:#{@config.port}"], @config.queue_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def next
|
22
|
+
job = @queue.reserve # blocks
|
23
|
+
result = YAML::load(job.body)
|
24
|
+
Flapjack::Transport::Result.new(:job => job, :result => result)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(result)
|
28
|
+
result.job.delete
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Flapjack
|
4
|
+
module Transport
|
5
|
+
class Result
|
6
|
+
|
7
|
+
attr_accessor :job, :result
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@job = options[:job]
|
11
|
+
@result = OpenStruct.new(options[:result])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Whether a check returns an ok status.
|
15
|
+
def ok?
|
16
|
+
@result.retval == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
# Whether a check has a warning status.
|
20
|
+
def warning?
|
21
|
+
@result.retval == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
# Whether a check has a critical status.
|
25
|
+
def critical?
|
26
|
+
@result.retval == 2
|
27
|
+
end
|
28
|
+
|
29
|
+
# Human readable representation of the check's return value.
|
30
|
+
def status
|
31
|
+
case @result.retval
|
32
|
+
when 0 ; "ok"
|
33
|
+
when 1 ; "warning"
|
34
|
+
when 2 ; "critical"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# FIXME: there is a *lot* of duplication here - implement a proxy
|
39
|
+
# object pattern?
|
40
|
+
def id
|
41
|
+
@result.check_id
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_id
|
45
|
+
@result.check_id
|
46
|
+
end
|
47
|
+
|
48
|
+
def command
|
49
|
+
@result.command
|
50
|
+
end
|
51
|
+
|
52
|
+
def frequency
|
53
|
+
@result.frequency
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flapjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lindsay Holmwood
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - "="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.
|
43
|
+
version: 1.1.5
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: xmpp4r
|
@@ -63,68 +63,29 @@ dependencies:
|
|
63
63
|
version: 1.2.3.1
|
64
64
|
version:
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
66
|
+
name: yajl-ruby
|
67
67
|
type: :runtime
|
68
68
|
version_requirement:
|
69
69
|
version_requirements: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - "="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 0.
|
73
|
+
version: 0.6.4
|
74
74
|
version:
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: sqlite3-ruby
|
77
77
|
type: :runtime
|
78
78
|
version_requirement:
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
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
|
83
|
+
version: 1.2.5
|
124
84
|
version:
|
125
85
|
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.
|
126
86
|
email: lindsay@holmwood.id.au
|
127
87
|
executables:
|
88
|
+
- flapjack-benchmark
|
128
89
|
- flapjack-notifier
|
129
90
|
- flapjack-notifier-manager
|
130
91
|
- flapjack-stats
|
@@ -140,6 +101,7 @@ files:
|
|
140
101
|
- README.md
|
141
102
|
- Rakefile
|
142
103
|
- TODO.md
|
104
|
+
- bin/flapjack-benchmark
|
143
105
|
- bin/flapjack-notifier
|
144
106
|
- bin/flapjack-notifier-manager
|
145
107
|
- bin/flapjack-stats
|
@@ -149,30 +111,58 @@ files:
|
|
149
111
|
- doc/CONFIGURING.md
|
150
112
|
- doc/DEVELOPING.md
|
151
113
|
- doc/INSTALL.md
|
114
|
+
- doc/PACKAGING.md
|
152
115
|
- etc/default/flapjack-notifier
|
153
116
|
- etc/default/flapjack-workers
|
154
|
-
- etc/flapjack/flapjack-notifier.
|
155
|
-
- etc/flapjack/recipients.
|
117
|
+
- etc/flapjack/flapjack-notifier.conf.example
|
118
|
+
- etc/flapjack/recipients.conf.example
|
156
119
|
- etc/init.d/flapjack-notifier
|
157
120
|
- etc/init.d/flapjack-workers
|
121
|
+
- features/flapjack-notifier-manager.feature
|
122
|
+
- features/flapjack-worker-manager.feature
|
123
|
+
- features/packaging-lintian.feature
|
124
|
+
- features/persistence/couch.feature
|
125
|
+
- features/persistence/sqlite3.feature
|
126
|
+
- features/persistence/steps/couch_steps.rb
|
127
|
+
- features/persistence/steps/generic_steps.rb
|
128
|
+
- features/persistence/steps/sqlite3_steps.rb
|
129
|
+
- features/steps/flapjack-notifier-manager_steps.rb
|
130
|
+
- features/steps/flapjack-worker-manager_steps.rb
|
131
|
+
- features/steps/packaging-lintian_steps.rb
|
132
|
+
- features/support/env.rb
|
133
|
+
- features/support/silent_system.rb
|
158
134
|
- flapjack.gemspec
|
135
|
+
- lib/flapjack/applications/notifier.rb
|
136
|
+
- lib/flapjack/applications/worker.rb
|
159
137
|
- lib/flapjack/checks/http_content
|
138
|
+
- lib/flapjack/checks/ping
|
160
139
|
- lib/flapjack/cli/notifier.rb
|
161
140
|
- lib/flapjack/cli/notifier_manager.rb
|
162
141
|
- lib/flapjack/cli/worker.rb
|
163
142
|
- lib/flapjack/cli/worker_manager.rb
|
164
|
-
- lib/flapjack/
|
165
|
-
- lib/flapjack/
|
166
|
-
- lib/flapjack/
|
167
|
-
- lib/flapjack/
|
168
|
-
- lib/flapjack/models/related_check.rb
|
169
|
-
- lib/flapjack/notifier.rb
|
143
|
+
- lib/flapjack/filters/any_parents_failed.rb
|
144
|
+
- lib/flapjack/filters/ok.rb
|
145
|
+
- lib/flapjack/inifile.rb
|
146
|
+
- lib/flapjack/notifier_engine.rb
|
170
147
|
- lib/flapjack/notifiers/mailer/init.rb
|
171
148
|
- lib/flapjack/notifiers/mailer/mailer.rb
|
172
149
|
- lib/flapjack/notifiers/xmpp/init.rb
|
173
150
|
- lib/flapjack/notifiers/xmpp/xmpp.rb
|
174
151
|
- lib/flapjack/patches.rb
|
175
|
-
- lib/flapjack/
|
152
|
+
- lib/flapjack/persistence/couch.rb
|
153
|
+
- lib/flapjack/persistence/couch/connection.rb
|
154
|
+
- lib/flapjack/persistence/couch/couch.rb
|
155
|
+
- lib/flapjack/persistence/data_mapper.rb
|
156
|
+
- lib/flapjack/persistence/data_mapper/data_mapper.rb
|
157
|
+
- lib/flapjack/persistence/data_mapper/models/check.rb
|
158
|
+
- lib/flapjack/persistence/data_mapper/models/check_template.rb
|
159
|
+
- lib/flapjack/persistence/data_mapper/models/event.rb
|
160
|
+
- lib/flapjack/persistence/data_mapper/models/node.rb
|
161
|
+
- lib/flapjack/persistence/data_mapper/models/related_check.rb
|
162
|
+
- lib/flapjack/persistence/sqlite3.rb
|
163
|
+
- lib/flapjack/persistence/sqlite3/sqlite3.rb
|
164
|
+
- lib/flapjack/transports/beanstalkd.rb
|
165
|
+
- lib/flapjack/transports/result.rb
|
176
166
|
has_rdoc: true
|
177
167
|
homepage: http://flapjack-project.com
|
178
168
|
licenses: []
|