Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mojombo/god into mojombo/ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
monde committed Jul 1, 2008
2 parents 93ed20c + 42cf121 commit d66ec78
Show file tree
Hide file tree
Showing 24 changed files with 443 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pkg
*.log
logs
*.rbc
*~
.*.sw?
28 changes: 28 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
== _._._ / TBD
* Bug Fixes
* Catch all Exceptions from HttpResponseCode condition [github.com/rliebling]
* Don't error out if the process went away in SlashProcPoller [Kevin Clark]
* Correction of Task#handle_poll to prevent crash under event registration failure conditions. [github.com/raggi]
* Cleaned up logging of failed e-mail sends. [github.com/raggi]
* New Behaviors
* clean_unix_socket [github.com/gma]
* New Contacts
* jabber [github.com/jwulff]
* Minor Enhancements
* chroot support [github.com/eric]
* Added God.log_file for the main god log, overridden by command line option. [github.com/raggi]
* Print groups from `god status` command if present [github.com/pdlug]
* Allow headers to be specified for http_response_code condition [github.com/pdlug]

== 0.7.7 / 2008-06-17
* Bug Fixes
* Fix detection of proc file system [raggi]

== 0.7.6 / 2008-05-13
* Major Enhancements
* Implement System::Process methods for Linux based on /proc [Kevin Clark]
* Minor Enhancements
* Allowing directories to be loaded at start [Bert Goethals]
* Bug Fixes
* Don't leak events on error in the kqueue handler [Kevin Clark]

== 0.7.5 / 2008-02-21
* Bug Fixes
* Remove Ruby's Logger and replace with custom SimpleLogger to stop threaded leak
Expand Down
4 changes: 4 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ init/god
lib/god.rb
lib/god/behavior.rb
lib/god/behaviors/clean_pid_file.rb
lib/god/behaviors/clean_unix_socket.rb
lib/god/behaviors/notify_when_flapping.rb
lib/god/cli/command.rb
lib/god/cli/run.rb
Expand Down Expand Up @@ -48,7 +49,9 @@ lib/god/registry.rb
lib/god/simple_logger.rb
lib/god/socket.rb
lib/god/sugar.rb
lib/god/system/portable_poller.rb
lib/god/system/process.rb
lib/god/system/slash_proc_poller.rb
lib/god/task.rb
lib/god/timeline.rb
lib/god/trigger.rb
Expand Down Expand Up @@ -96,6 +99,7 @@ test/test_process.rb
test/test_registry.rb
test/test_socket.rb
test/test_sugar.rb
test/test_system_portable_poller.rb
test/test_system_process.rb
test/test_task.rb
test/test_timeline.rb
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'hoe'

Hoe.new('god', '0.7.5') do |p|
Hoe.new('god', '0.7.7') do |p|
p.rubyforge_name = 'god'
p.author = 'Tom Preston-Werner'
p.email = 'tom@rubyisawesome.com'
Expand Down
1 change: 1 addition & 0 deletions ext/god/kqueue_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ kqh_handle_events()
nevents = kevent(kq, NULL, 0, events, num_to_fetch, NULL);

if (-1 == nevents) {
free(events);
rb_raise(rb_eStandardError, strerror(errno));
} else {
for (i = 0; i < nevents; i++) {
Expand Down
23 changes: 23 additions & 0 deletions god.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Gem::Specification.new do |s|
s.name = %q{god}
s.version = "0.7.7"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Tom Preston-Werner"]
s.date = %q{2008-06-23}
s.default_executable = %q{god}
s.description = %q{God is an easy to configure, easy to extend monitoring framework written in Ruby.}
s.email = %q{tom@rubyisawesome.com}
s.executables = ["god"]
s.extensions = ["ext/god/extconf.rb"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/god", "examples/events.god", "examples/gravatar.god", "examples/single.god", "ext/god/extconf.rb", "ext/god/kqueue_handler.c", "ext/god/netlink_handler.c", "init/god", "lib/god.rb", "lib/god/behavior.rb", "lib/god/behaviors/clean_pid_file.rb", "lib/god/behaviors/clean_unix_socket.rb", "lib/god/behaviors/notify_when_flapping.rb", "lib/god/cli/command.rb", "lib/god/cli/run.rb", "lib/god/cli/version.rb", "lib/god/condition.rb", "lib/god/conditions/always.rb", "lib/god/conditions/complex.rb", "lib/god/conditions/cpu_usage.rb", "lib/god/conditions/degrading_lambda.rb", "lib/god/conditions/disk_usage.rb", "lib/god/conditions/flapping.rb", "lib/god/conditions/http_response_code.rb", "lib/god/conditions/lambda.rb", "lib/god/conditions/memory_usage.rb", "lib/god/conditions/process_exits.rb", "lib/god/conditions/process_running.rb", "lib/god/conditions/tries.rb", "lib/god/configurable.rb", "lib/god/contact.rb", "lib/god/contacts/email.rb", "lib/god/dependency_graph.rb", "lib/god/diagnostics.rb", "lib/god/driver.rb", "lib/god/errors.rb", "lib/god/event_handler.rb", "lib/god/event_handlers/dummy_handler.rb", "lib/god/event_handlers/kqueue_handler.rb", "lib/god/event_handlers/netlink_handler.rb", "lib/god/logger.rb", "lib/god/metric.rb", "lib/god/process.rb", "lib/god/registry.rb", "lib/god/simple_logger.rb", "lib/god/socket.rb", "lib/god/sugar.rb", "lib/god/system/portable_poller.rb", "lib/god/system/process.rb", "lib/god/system/slash_proc_poller.rb", "lib/god/task.rb", "lib/god/timeline.rb", "lib/god/trigger.rb", "lib/god/watch.rb", "test/configs/child_events/child_events.god", "test/configs/child_events/simple_server.rb", "test/configs/child_polls/child_polls.god", "test/configs/child_polls/simple_server.rb", "test/configs/complex/complex.god", "test/configs/complex/simple_server.rb", "test/configs/contact/contact.god", "test/configs/contact/simple_server.rb", "test/configs/daemon_events/daemon_events.god", "test/configs/daemon_events/simple_server.rb", "test/configs/daemon_events/simple_server_stop.rb", "test/configs/daemon_polls/daemon_polls.god", "test/configs/daemon_polls/simple_server.rb", "test/configs/degrading_lambda/degrading_lambda.god", "test/configs/degrading_lambda/tcp_server.rb", "test/configs/matias/matias.god", "test/configs/real.rb", "test/configs/running_load/running_load.god", "test/configs/stress/simple_server.rb", "test/configs/stress/stress.god", "test/configs/task/logs/.placeholder", "test/configs/task/task.god", "test/configs/test.rb", "test/helper.rb", "test/suite.rb", "test/test_behavior.rb", "test/test_condition.rb", "test/test_conditions_disk_usage.rb", "test/test_conditions_http_response_code.rb", "test/test_conditions_process_running.rb", "test/test_conditions_tries.rb", "test/test_contact.rb", "test/test_dependency_graph.rb", "test/test_driver.rb", "test/test_event_handler.rb", "test/test_god.rb", "test/test_handlers_kqueue_handler.rb", "test/test_logger.rb", "test/test_metric.rb", "test/test_process.rb", "test/test_registry.rb", "test/test_socket.rb", "test/test_sugar.rb", "test/test_system_portable_poller.rb", "test/test_system_process.rb", "test/test_task.rb", "test/test_timeline.rb", "test/test_trigger.rb", "test/test_watch.rb"]
s.has_rdoc = true
s.homepage = %q{http://god.rubyforge.org/}
s.rdoc_options = ["--main", "README.txt"]
s.require_paths = ["lib", "ext"]
s.rubyforge_project = %q{god}
s.rubygems_version = %q{1.2.0}
s.summary = %q{Like monit, only awesome}
s.test_files = ["test/test_process.rb", "test/test_watch.rb", "test/test_system_portable_poller.rb", "test/test_conditions_tries.rb", "test/test_task.rb", "test/test_condition.rb", "test/test_timeline.rb", "test/test_logger.rb", "test/test_conditions_process_running.rb", "test/test_handlers_kqueue_handler.rb", "test/test_conditions_disk_usage.rb", "test/test_event_handler.rb", "test/test_driver.rb", "test/test_dependency_graph.rb", "test/test_metric.rb", "test/test_registry.rb", "test/test_behavior.rb", "test/test_socket.rb", "test/test_sugar.rb", "test/test_trigger.rb", "test/test_conditions_http_response_code.rb", "test/test_god.rb", "test/test_system_process.rb", "test/test_contact.rb"]
end
16 changes: 13 additions & 3 deletions lib/god.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
require 'god/errors'
require 'god/simple_logger'
require 'god/logger'

require 'god/system/process'
require 'god/system/portable_poller'
require 'god/system/slash_proc_poller'

require 'god/dependency_graph'
require 'god/timeline'
require 'god/configurable'
Expand All @@ -29,6 +33,7 @@

require 'god/behavior'
require 'god/behaviors/clean_pid_file'
require 'god/behaviors/clean_unix_socket'
require 'god/behaviors/notify_when_flapping'

require 'god/condition'
Expand All @@ -47,6 +52,10 @@

require 'god/contact'
require 'god/contacts/email'
begin
require 'god/contacts/jabber'
rescue LoadError
end

require 'god/socket'
require 'god/driver'
Expand Down Expand Up @@ -129,7 +138,7 @@ def safe_attr_accessor(*args)
end

module God
VERSION = '0.7.5'
VERSION = '0.7.7'

LOG_BUFFER_SIZE_DEFAULT = 100
PID_FILE_DIRECTORY_DEFAULTS = ['/var/run/god', '~/.god/pids']
Expand All @@ -145,6 +154,7 @@ class << self
:allow,
:log_buffer_size,
:pid_file_directory,
:log_file,
:log_level,
:use_events

Expand Down Expand Up @@ -456,7 +466,7 @@ def self.terminate
def self.status
info = {}
self.watches.map do |name, w|
info[name] = {:state => w.state}
info[name] = {:state => w.state, :group => w.group}
end
info
end
Expand Down Expand Up @@ -631,4 +641,4 @@ def self.pattern_match(pattern, list)
# Returns nothing
at_exit do
God.at_exit if $run
end
end
21 changes: 21 additions & 0 deletions lib/god/behaviors/clean_unix_socket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module God
module Behaviors

class CleanUnixSocket < Behavior
def valid?
valid = true
valid &= complain("Attribute 'unix_socket' must be specified", self) if self.watch.unix_socket.nil?
valid
end

def before_start
File.delete(self.watch.unix_socket)

"deleted unix socket"
rescue
"no unix socket to delete"
end
end

end
end
21 changes: 16 additions & 5 deletions lib/god/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ def load_command
end

def status_command
watches = @server.status
watches.keys.sort.each do |name|
state = watches[name][:state]
puts "#{name}: #{state}"
watches = {}
@server.status.each do |name, status|
g = status[:group] || ''
unless watches.has_key?(g)
watches[g] = {}
end
watches[g][name] = status
end
watches.keys.sort.each do |group|
puts "#{group}:" unless group.empty?
watches[group].keys.sort.each do |name|
state = watches[group][name][:state]
print " " unless group.empty?
puts "#{name}: #{state}"
end
end
end

Expand Down Expand Up @@ -192,4 +203,4 @@ def lifecycle_command
end # Command

end
end
end
7 changes: 4 additions & 3 deletions lib/god/cli/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def run_in_front

default_run

if @options[:log]
log_file = File.expand_path(@options[:log])
log_file = God.log_file
log_file = File.expand_path(@options[:log]) if @options[:log]
if log_file
puts "Sending output to log file: #{log_file}"

# reset file descriptors
Expand All @@ -95,7 +96,7 @@ def run_daemonized
begin
require 'god'

log_file = @options[:log] || "/dev/null"
log_file = @options[:log] || God.log_file || "/dev/null"

# reset file descriptors
STDIN.reopen "/dev/null"
Expand Down
11 changes: 9 additions & 2 deletions lib/god/conditions/http_response_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Conditions
# Optional
# +port+ is the port to connect (default 80)
# +path+ is the path to connect (default '/')
# +headers+ is the hash of HTTP headers to send (default none)
# +times+ is the number of times after which to trigger (default 1)
# e.g. 3 (times in a row) or [3, 5] (three out of fives times)
# +timeout+ is the time to wait for a connection (default 60.seconds)
Expand Down Expand Up @@ -68,12 +69,14 @@ class HttpResponseCode < PollCondition
:host, # e.g. www.example.com
:port, # e.g. 8080
:timeout, # e.g. 60.seconds
:path # e.g. '/'
:path, # e.g. '/'
:headers # e.g. {'Host' => 'myvirtual.mydomain.com'}

def initialize
super
self.port = 80
self.path = '/'
self.headers = {}
self.times = [1, 1]
self.timeout = 60.seconds
end
Expand Down Expand Up @@ -108,7 +111,7 @@ def test

Net::HTTP.start(self.host, self.port) do |http|
http.read_timeout = self.timeout
response = http.get(self.path)
response = http.get(self.path, self.headers)
end

actual_response_code = response.code.to_i
Expand All @@ -127,6 +130,10 @@ def test
self.code_is ? fail('EOF') : pass('EOF')
rescue Timeout::Error
self.code_is ? fail('Timeout') : pass('Timeout')
rescue Errno::ETIMEDOUT
self.code_is ? fail('Timedout') : pass('Timedout')
rescue Exception => failure
self.code_is ? fail(failure.class.name) : pass(failure.class.name)
end

private
Expand Down
6 changes: 2 additions & 4 deletions lib/god/contacts/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ def notify(message, time, priority, category, host)

self.info = "sent email to #{self.email}"
rescue => e
puts e.message
puts e.backtrace.join("\n")

self.info = "failed to send email to #{self.email}: #{e.message}"
applog(nil, :info, "failed to send email to #{self.email}: #{e.message}")
applog(nil, :debug, e.backtrace.join("\n"))
end
end

Expand Down
65 changes: 65 additions & 0 deletions lib/god/contacts/jabber.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# To add Jabber notifications you must have xmpp4r gem installed.
# Configure your watches like this:
#
# God::Contacts::Jabber.settings = { :jabber_id => 'sender@example.com',
# :password => 'secret' }
# God.contact(:jabber) do |c|
# c.name = 'Tester'
# c.jabber_id = 'receiver@example.com'
# c.group = 'developers'
# end

module XMPP4R
require 'rubygems'
require 'xmpp4r'
include Jabber
end

module God
module Contacts
class Jabber < Contact
class << self
attr_accessor :settings, :format
end

self.format = lambda do |message, priority, category, host|
text = "Message: #{message}\n"
text += "Host: #{host}\n" if host
text += "Priority: #{priority}\n" if priority
text += "Category: #{category}\n" if category
return text
end

attr_accessor :jabber_id

def valid?
valid = true
end

def notify(message, time, priority, category, host)
begin
jabber_id = XMPP4R::JID::new "#{Jabber.settings[:jabber_id]}/God"
jabber_client = XMPP4R::Client::new jabber_id
jabber_client.connect
jabber_client.auth Jabber.settings[:password]

body = Jabber.format.call message, priority, category, host

message = XMPP4R::Message::new self.jabber_id, body
message.set_type :normal
message.set_id '1'
message.set_subject 'God'
jabber_client.send message

self.info = "sent jabber message to #{self.jabber_id}"
rescue => e
puts e.message
puts e.backtrace.join("\n")

self.info = "failed to send jabber message to #{self.jabber_id}: #{e.message}"
end
end
end

end
end
Loading

0 comments on commit d66ec78

Please sign in to comment.