makesure 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/bin/makesure +75 -0
- data/bin/makesure-runner +68 -0
- data/lib/makesure/cmd.rb +14 -0
- data/lib/makesure/cron.rb +48 -0
- data/lib/makesure/runner.rb +50 -0
- data/lib/makesure/summarize.rb +32 -0
- data/lib/makesure/system.rb +46 -0
- data/lib/makesure/verify.rb +38 -0
- data/lib/makesure/version.rb +9 -0
- data/lib/makesure.rb +75 -0
- data/test/helper.rb +18 -0
- data/test/test_makesure.rb +7 -0
- metadata +168 -0
data/.bundle/config
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
gem "pony", ">= 1.0"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
|
+
gem "rcov", ">= 0"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.4)
|
5
|
+
git (1.2.5)
|
6
|
+
i18n (0.5.0)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
mail (2.2.15)
|
12
|
+
activesupport (>= 2.3.6)
|
13
|
+
i18n (>= 0.4.0)
|
14
|
+
mime-types (~> 1.16)
|
15
|
+
treetop (~> 1.4.8)
|
16
|
+
mime-types (1.16)
|
17
|
+
polyglot (0.3.1)
|
18
|
+
pony (1.1)
|
19
|
+
mail (> 2.0)
|
20
|
+
rake (0.8.7)
|
21
|
+
rcov (0.9.9)
|
22
|
+
shoulda (2.11.3)
|
23
|
+
treetop (1.4.9)
|
24
|
+
polyglot (>= 0.3.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.0.0)
|
31
|
+
jeweler (~> 1.5.2)
|
32
|
+
pony (>= 1.0)
|
33
|
+
rcov
|
34
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Eric Waller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= makesure
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to makesure
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Eric Waller. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
require './lib/makesure/version.rb'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "makesure"
|
17
|
+
gem.version = Makesure::Version::STRING
|
18
|
+
gem.homepage = "http://github.com/seatgeek/makesure"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Continuous (Production) Verification: Define and Monitor Systems in Ruby}
|
21
|
+
gem.description = %Q{Makesure is a set of tools to define, verify and monitor systems in a unix environment. It allows you to schedule commands that constitue a system via cron (and monitors the execution of those commands), it gives you a way to verify the state of a system (and alerts you when there are problems), and it provides a simple mechanism for collecting statistics about that system.}
|
22
|
+
gem.email = "eric@seatgeek.com"
|
23
|
+
gem.authors = ["Eric Waller"]
|
24
|
+
gem.add_runtime_dependency 'pony', '>= 1.0'
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "makesure #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/bin/makesure
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'makesure'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
cron_path = '/etc/cron.d/makesure.cron'
|
9
|
+
|
10
|
+
parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: makesure [options] COMMAND"
|
12
|
+
|
13
|
+
opts.separator ""
|
14
|
+
opts.separator "Options:"
|
15
|
+
|
16
|
+
opts.on("-c", "--cron <path to file>", "Where should makesure put its cron entries? Must be a file that will be loaded by cron") do |path|
|
17
|
+
cron_path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-h", "--help", "Show this message") do
|
21
|
+
puts opts
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.separator ""
|
26
|
+
opts.separator "Commands:"
|
27
|
+
opts.separator " init Creates an initial Makesurefile"
|
28
|
+
opts.separator " update Updates cron with commands scheduled by your system definitions"
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.parse!
|
32
|
+
|
33
|
+
case ARGV[0]
|
34
|
+
when 'init'
|
35
|
+
dir = File.expand_path(ARGV[1] || '.')
|
36
|
+
abort "#{dir} is not a directory" unless File.directory?(dir)
|
37
|
+
|
38
|
+
file = "Makesurefile"
|
39
|
+
if File.exists?(file)
|
40
|
+
warn "[skip] '#{file}' already exists"
|
41
|
+
elsif File.exists?(file.downcase)
|
42
|
+
warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
|
43
|
+
else
|
44
|
+
puts "[add] writing '#{file}'"
|
45
|
+
File.open(file, "w") do |f|
|
46
|
+
f.write(<<-FILE)
|
47
|
+
# Tell makesure how to get in touch when things break
|
48
|
+
# (hint: Makesure.alert_options are passed almost directly to Pony.mail)
|
49
|
+
Makesure.alert_options = {
|
50
|
+
:to => 'dev@example.com', # who should hear about it when something's wrong?
|
51
|
+
:via => :smtp, # how should makesure send email (:smtp or :sendmail)
|
52
|
+
:via_options => {
|
53
|
+
:address => 'smtp.gmail.com',
|
54
|
+
:port => '587',
|
55
|
+
:enable_starttls_auto => true,
|
56
|
+
:user_name => 'user',
|
57
|
+
:password => 'password',
|
58
|
+
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
59
|
+
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
Makesure.uid = "nobody" # what user should makesure run its tasks as (this can be set per system as well)
|
64
|
+
|
65
|
+
# Tell makesure about your systems
|
66
|
+
Dir['systems/*.rb', 'lib/systems/*.rb'].each { |sys| load(sys) }
|
67
|
+
FILE
|
68
|
+
end
|
69
|
+
end
|
70
|
+
when 'update'
|
71
|
+
Makesure.load_system_defs
|
72
|
+
Makesure::Cron.new(:cron_path => cron_path)
|
73
|
+
else
|
74
|
+
puts parser.help
|
75
|
+
end
|
data/bin/makesure-runner
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'makesure'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: makesure-runner [options] COMMAND"
|
10
|
+
|
11
|
+
opts.separator ""
|
12
|
+
opts.separator "Options:"
|
13
|
+
|
14
|
+
# opts.on("-c", "--cron <path to file>", "path to the file makesure should write your cron specs") do |path|
|
15
|
+
# cron_path = path
|
16
|
+
# end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Show this message") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.separator ""
|
24
|
+
opts.separator "Commands:"
|
25
|
+
opts.separator " run COMMAND Runs the specified COMMAND and monitors its output"
|
26
|
+
opts.separator " verify SYSTEM Verfies the state of the specified SYSTEM"
|
27
|
+
opts.separator " summarize SYSTEM Collects summary data for the specified SYSTEM"
|
28
|
+
end
|
29
|
+
|
30
|
+
parser.parse!
|
31
|
+
|
32
|
+
case ARGV[0]
|
33
|
+
when 'run'
|
34
|
+
cmd = ARGV[1]
|
35
|
+
|
36
|
+
Makesure.load_system_defs
|
37
|
+
Makesure::Runner.new(cmd).run!
|
38
|
+
|
39
|
+
when 'verify'
|
40
|
+
sys = ARGV[1]
|
41
|
+
vrfy = ARGV[2]
|
42
|
+
|
43
|
+
Makesure.load_system_defs
|
44
|
+
system = Makesure.system_with_name(sys)
|
45
|
+
abort "Couldn't find system: #{sys}" unless system
|
46
|
+
verify = system.verify_with_name(vrfy)
|
47
|
+
abort "Couldn't find verify: #{vrfy}" unless verify
|
48
|
+
|
49
|
+
Makesure.log "Running verify #{sys} #{vrfy}"
|
50
|
+
verify.run!
|
51
|
+
|
52
|
+
when 'summarize'
|
53
|
+
sys = ARGV[1]
|
54
|
+
smrz = ARGV[2]
|
55
|
+
|
56
|
+
Makesure.load_system_defs
|
57
|
+
system = Makesure.system_with_name(sys)
|
58
|
+
abort "Couldn't find system: #{sys}" unless system
|
59
|
+
summarize = system.summarize_with_name(smrz)
|
60
|
+
abort "Couldn't find summarize: #{smrz}" unless summarize
|
61
|
+
|
62
|
+
Makesure.log "Running summarize #{sys} #{smrz}"
|
63
|
+
summarize.run!
|
64
|
+
|
65
|
+
else
|
66
|
+
puts parser.help
|
67
|
+
end
|
68
|
+
|
data/lib/makesure/cmd.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Makesure
|
2
|
+
|
3
|
+
class Cron
|
4
|
+
|
5
|
+
# specify a file (or directory containing files) to load system specifications from
|
6
|
+
def initialize(opts = {})
|
7
|
+
opts = {
|
8
|
+
:cron_path => "/etc/cron.d/makesure.cron"
|
9
|
+
}.merge(opts)
|
10
|
+
|
11
|
+
Makesure.log "updating '#{opts[:cron_path]}'"
|
12
|
+
|
13
|
+
cron_file = File.expand_path(opts[:cron_path])
|
14
|
+
crontab = build_crontab_output
|
15
|
+
Makesure.debug "#{cron_file}:\n#{crontab}"
|
16
|
+
|
17
|
+
File.open(cron_file, "w") do |f|
|
18
|
+
f.write(crontab)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_crontab_output
|
23
|
+
crontab = ""
|
24
|
+
crontab << "# Autogenerated by makesure: you probably don't want to edit this file\n"
|
25
|
+
Makesure.systems.each do |s|
|
26
|
+
uid = s.uid || Makesure.uid
|
27
|
+
crontab << "\n"
|
28
|
+
crontab << "## Tasks for '#{s.name}'\n"
|
29
|
+
crontab << "# Commands\n"
|
30
|
+
s.cmds.each do |c|
|
31
|
+
crontab << "#{c.cron}\t"
|
32
|
+
crontab << "#{uid} " if uid
|
33
|
+
crontab << "makesure-runner run #{c.command.inspect}\n"
|
34
|
+
end
|
35
|
+
crontab << "# Verification\n"
|
36
|
+
s.verifies.each do |v|
|
37
|
+
crontab << "#{v.cron}\t"
|
38
|
+
crontab << "#{uid} " if uid
|
39
|
+
crontab << "makesure-runner verify #{s.name} #{v.name}\n"
|
40
|
+
end
|
41
|
+
# TODO summarizes
|
42
|
+
end
|
43
|
+
crontab
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Makesure
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
attr_accessor :cmd
|
6
|
+
|
7
|
+
def initialize(cmd, opts = {})
|
8
|
+
@cmd = cmd
|
9
|
+
@opts = {
|
10
|
+
:test => "val"
|
11
|
+
}.merge(opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def run!
|
15
|
+
io = IO.popen(cmd)
|
16
|
+
Makesure.log "Running cmd '#{cmd}' with pid #{io.pid}"
|
17
|
+
|
18
|
+
Process.wait # needed to populate $?
|
19
|
+
# seems to grab the exitstatus of the last cmd in a chain, ie:
|
20
|
+
# ls -al | grep -i file-that-exits # exits w/ 0
|
21
|
+
# ls -al | grep -i -file-that-does-not-exist # exits w/ 1
|
22
|
+
# ls -al | grep -i -file-that-does-not-exist | echo "yay" # exits w/ 0
|
23
|
+
exitstatus = $?.exitstatus
|
24
|
+
|
25
|
+
Makesure.log "cmd exited with status #{exitstatus}"
|
26
|
+
|
27
|
+
output = io.read
|
28
|
+
|
29
|
+
unless exitstatus == 0
|
30
|
+
Makesure.warn "oh shitttt something broke, tell everybody!"
|
31
|
+
body = ""
|
32
|
+
body << "[#{Time.now.to_s}] #{cmd.inspect} [pid #{io.pid}] exited with status #{exitstatus}, output follows:\n\n"
|
33
|
+
body << output
|
34
|
+
Makesure.send_alert("ERROR in command alert: #{cmd.inspect}", body)
|
35
|
+
end
|
36
|
+
|
37
|
+
if output.empty?
|
38
|
+
Makesure.log "no output"
|
39
|
+
else
|
40
|
+
Makesure.log ">>> begin output"
|
41
|
+
output.each_line do |l|
|
42
|
+
Makesure.log l
|
43
|
+
end
|
44
|
+
Makesure.log "<<< end output"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Makesure
|
2
|
+
|
3
|
+
class Summarize
|
4
|
+
|
5
|
+
attr_reader :name, :cron, :blk
|
6
|
+
|
7
|
+
def initialize(name, cron, blk)
|
8
|
+
@name = name
|
9
|
+
@cron = cron
|
10
|
+
@blk = blk
|
11
|
+
end
|
12
|
+
|
13
|
+
def run!
|
14
|
+
begin
|
15
|
+
|
16
|
+
blk.call
|
17
|
+
|
18
|
+
rescue Exception => e
|
19
|
+
Makesure.warn "Uh oh, something's up"
|
20
|
+
Makesure.warn "\t" + e.message
|
21
|
+
|
22
|
+
# send an email with the details
|
23
|
+
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Makesure
|
2
|
+
|
3
|
+
class System
|
4
|
+
|
5
|
+
attr_reader :name, :cmds, :verifies, :summarizes
|
6
|
+
|
7
|
+
attr_accessor :uid
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
|
12
|
+
@cmds = []
|
13
|
+
@verifies = []
|
14
|
+
@summarizes = []
|
15
|
+
end
|
16
|
+
|
17
|
+
# DSL stuff
|
18
|
+
|
19
|
+
def schedule(cron_spec, cmd)
|
20
|
+
Makesure.debug("scheduling '#{cmd}' at '#{cron_spec}'")
|
21
|
+
@cmds << Cmd.new(cron_spec, cmd)
|
22
|
+
end
|
23
|
+
|
24
|
+
def verify(name, cron_spec, &blk)
|
25
|
+
Makesure.debug("scheduling verify at '#{cron_spec}'")
|
26
|
+
@verifies << Verify.new(name, cron_spec, blk)
|
27
|
+
end
|
28
|
+
|
29
|
+
def summarize(name, cron_spec, &blk)
|
30
|
+
Makesure.debug("scheduling summarize at '#{cron_spec}'")
|
31
|
+
@summarizes << Summarize.new(name, cron_spec, blk)
|
32
|
+
end
|
33
|
+
|
34
|
+
# internal use
|
35
|
+
|
36
|
+
def verify_with_name(name)
|
37
|
+
verifies.find { |v| v.name.to_s == name.to_s }
|
38
|
+
end
|
39
|
+
|
40
|
+
def summarize_with_name(name)
|
41
|
+
summarizes.find { |s| s.name.to_s == name.to_s }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Makesure
|
2
|
+
|
3
|
+
class Verify
|
4
|
+
|
5
|
+
attr_reader :name, :cron, :blk
|
6
|
+
|
7
|
+
def initialize(name, cron, blk)
|
8
|
+
@name = name
|
9
|
+
@cron = cron
|
10
|
+
@blk = blk
|
11
|
+
end
|
12
|
+
|
13
|
+
def run!
|
14
|
+
begin
|
15
|
+
|
16
|
+
blk.call
|
17
|
+
|
18
|
+
rescue Exception => e
|
19
|
+
Makesure.warn "Uh oh, something's up"
|
20
|
+
Makesure.warn "\t" + e.message
|
21
|
+
|
22
|
+
# send an email with the details
|
23
|
+
body = ""
|
24
|
+
body << "[#{Time.now.to_s}] Verification failure:\n\n"
|
25
|
+
body << e.backtrace.join("\n")
|
26
|
+
Makesure.send_alert("FAILED verification alert: #{e.message}", body)
|
27
|
+
|
28
|
+
return false
|
29
|
+
#else
|
30
|
+
#ensure
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/makesure.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'pony'
|
2
|
+
|
3
|
+
require 'makesure/runner'
|
4
|
+
require 'makesure/cron'
|
5
|
+
require 'makesure/system'
|
6
|
+
require 'makesure/cmd'
|
7
|
+
require 'makesure/verify'
|
8
|
+
require 'makesure/summarize'
|
9
|
+
require 'makesure/version'
|
10
|
+
|
11
|
+
module Makesure
|
12
|
+
|
13
|
+
@alert_options = {}
|
14
|
+
@systems = []
|
15
|
+
|
16
|
+
extend self
|
17
|
+
|
18
|
+
# global options
|
19
|
+
attr_accessor :uid,
|
20
|
+
:alert_options,
|
21
|
+
:log_level
|
22
|
+
|
23
|
+
def load_system_defs
|
24
|
+
file = File.join(Dir.pwd, "Makesurefile")
|
25
|
+
Makesure.log("Loading #{file}")
|
26
|
+
load(file)
|
27
|
+
abort "No system specifications found" unless Makesure.systems.size > 0
|
28
|
+
Makesure.log "Loaded #{Makesure.systems.size} system specifications"
|
29
|
+
true
|
30
|
+
rescue Exception => e
|
31
|
+
if e.instance_of?(SystemExit)
|
32
|
+
raise
|
33
|
+
else
|
34
|
+
Makesure.warn "There was an error loading #{file}"
|
35
|
+
Makesure.warn "\t" + e.message
|
36
|
+
Makesure.warn "\t" + e.backtrace.join("\n\t")
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def system_with_name(name)
|
42
|
+
systems.find { |s| s.name.to_s == name.to_s }
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_alert(title, details = "")
|
46
|
+
opts = { :from => "makesure@unknown" }.merge(Makesure.alert_options)
|
47
|
+
Makesure.log "Sending alert to #{opts[:to]}: #{title}"
|
48
|
+
msg = Pony.mail(opts.merge(:subject => title, :body => details))
|
49
|
+
end
|
50
|
+
|
51
|
+
# DSL stuff
|
52
|
+
|
53
|
+
attr_reader :systems
|
54
|
+
|
55
|
+
def system(name)
|
56
|
+
Makesure.debug "Reading specification for system '#{name}'"
|
57
|
+
s = Makesure::System.new(name)
|
58
|
+
yield s
|
59
|
+
@systems << s
|
60
|
+
end
|
61
|
+
|
62
|
+
# internal utils
|
63
|
+
|
64
|
+
def log(msg, level = :info)
|
65
|
+
puts "[#{Time.now.to_s}] #{level.to_s.upcase}: #{msg}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def warn(msg)
|
69
|
+
log(msg, :warn)
|
70
|
+
end
|
71
|
+
|
72
|
+
def debug(msg)
|
73
|
+
log(msg, :debug) if log_level == :debug
|
74
|
+
end
|
75
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'makesure'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makesure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eric Waller
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-24 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: pony
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
version: "1.0"
|
31
|
+
type: :runtime
|
32
|
+
prerelease: false
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: shoulda
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 1
|
56
|
+
- 0
|
57
|
+
- 0
|
58
|
+
version: 1.0.0
|
59
|
+
type: :development
|
60
|
+
prerelease: false
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 5
|
72
|
+
- 2
|
73
|
+
version: 1.5.2
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rcov
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: *id005
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: pony
|
92
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 0
|
100
|
+
version: "1.0"
|
101
|
+
type: :runtime
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id006
|
104
|
+
description: Makesure is a set of tools to define, verify and monitor systems in a unix environment. It allows you to schedule commands that constitue a system via cron (and monitors the execution of those commands), it gives you a way to verify the state of a system (and alerts you when there are problems), and it provides a simple mechanism for collecting statistics about that system.
|
105
|
+
email: eric@seatgeek.com
|
106
|
+
executables:
|
107
|
+
- makesure
|
108
|
+
- makesure-runner
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
extra_rdoc_files:
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.rdoc
|
114
|
+
files:
|
115
|
+
- .bundle/config
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
- Rakefile
|
121
|
+
- bin/makesure
|
122
|
+
- bin/makesure-runner
|
123
|
+
- lib/makesure.rb
|
124
|
+
- lib/makesure/cmd.rb
|
125
|
+
- lib/makesure/cron.rb
|
126
|
+
- lib/makesure/runner.rb
|
127
|
+
- lib/makesure/summarize.rb
|
128
|
+
- lib/makesure/system.rb
|
129
|
+
- lib/makesure/verify.rb
|
130
|
+
- lib/makesure/version.rb
|
131
|
+
- test/helper.rb
|
132
|
+
- test/test_makesure.rb
|
133
|
+
has_rdoc: true
|
134
|
+
homepage: http://github.com/seatgeek/makesure
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
hash: -344166319
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
version: "0"
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
version: "0"
|
159
|
+
requirements: []
|
160
|
+
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.3.7
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: "Continuous (Production) Verification: Define and Monitor Systems in Ruby"
|
166
|
+
test_files:
|
167
|
+
- test/helper.rb
|
168
|
+
- test/test_makesure.rb
|