forked from mojombo/god
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add campfire contact [github.com/hellvinz]
- Loading branch information
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |