Skip to content

Commit

Permalink
add campfire contact [github.com/hellvinz]
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Nov 14, 2008
1 parent f6d64d8 commit adc9ab7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -34,6 +34,7 @@ lib/god/conditions/process_running.rb
lib/god/conditions/tries.rb
lib/god/configurable.rb
lib/god/contact.rb
lib/god/contacts/campfire.rb
lib/god/contacts/email.rb
lib/god/contacts/jabber.rb
lib/god/contacts/twitter.rb
Expand Down
2 changes: 1 addition & 1 deletion god.gemspec
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
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/file_mtime.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/contacts/jabber.rb", "lib/god/contacts/twitter.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.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/file_mtime.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/campfire.rb", "lib/god/contacts/email.rb", "lib/god/contacts/jabber.rb", "lib/god/contacts/twitter.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"]
Expand Down
6 changes: 6 additions & 0 deletions lib/god.rb
Expand Up @@ -65,6 +65,12 @@
puts "You must have the 'xmpp4r' gem installed to use the Jabber contact."
exit 1
end
begin
require 'god/contacts/campfire'
rescue LoadError
puts "You must have the 'tinder' gem installed to use the Campfire contact."
exit 1
end

require 'god/socket'
require 'god/driver'
Expand Down
80 changes: 80 additions & 0 deletions lib/god/contacts/campfire.rb
@@ -0,0 +1,80 @@
# notify campfire using tinder http://tinder.rubyforge.org
#
# Example: set up a new campfire notifier
#
# Credentials
#
# God::Contacts::Campfire.server_settings = {
# :subdomain => "yoursubdomain",
# :user_name => "youruser",
# :room => "yourroom",
# :password => "yourpassword"
# }
#
# Register a new notifier
#
# God.contact(:campfire) do |c|
# c.name = 'campfire'
# end
#
# Define a transition for the process running event
#
# w.transition(:up, :start) do |on|
# on.condition(:process_running) do |c|
# c.running = true
# c.notify = 'campfire'
# end
# end

require 'tinder'

module God
module Contacts

class Campfire < Contact
class << self
attr_accessor :server_settings, :format
def room
unless @room
applog(nil,:debug, "initializing campfire connection using credentials: #{Campfire.server_settings.inspect}")

campfire = Tinder::Campfire.new Campfire.server_settings[:subdomain]
campfire.login Campfire.server_settings[:user_name], Campfire.server_settings[:password]
@room = campfire.find_room_by_name(Campfire.server_settings[:room])
end
@room
end
end

self.server_settings = {:subdomain => '',
:user_name => '',
:password => '',
:room => ''}

self.format = lambda do |message, host|
<<-EOF
#{host} - #{message}
EOF
end

def valid?
true
end

def notify(message, time, priority, category, host)

begin
body = Campfire.format.call(message,host)

Campfire.room.speak body

self.info = "notified campfire: #{Campfire.server_settings[:subdomain]}"
rescue => e
applog(nil, :info, "failed to notify campfire: #{e.message}")
applog(nil, :debug, e.backtrace.join("\n"))
end
end
end

end
end

0 comments on commit adc9ab7

Please sign in to comment.