Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

added Airbrake support for notifications #134

Merged
merged 1 commit into from

2 participants

@pietervisser

Hi,

I just added notification support for Airbrake (http://airbrake.io). Tests and new documentation are also added.

@eric
Collaborator

looks good.

Thanks.

@eric eric merged commit 6789f62 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2013
  1. @pietervisser
This page is out of date. Refresh to see the latest.
View
19 doc/god.asciidoc
@@ -1188,6 +1188,25 @@ format - The Symbol format [ :form | :json ] (default: :form).
```
+Airbrake
+~~~~~~~
+
+Send a notice to airbrake (http://airbrake.io/).
+
+```ruby
+God::Contacts::Airbrake.defaults do |d|
+ ...
+end
+
+God.contact(:airbrake) do |c|
+ ...
+end
+```
+
+```
+apikey - The String API key.
+```
+
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
View
2  god.gemspec
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('daemons', '~> 1.1')
s.add_development_dependency('mocha', '~> 0.10')
s.add_development_dependency('gollum', '~> 1.3.1')
+ s.add_development_dependency('airbrake', '~> 3.1.7')
# = MANIFEST =
s.files = %w[
@@ -137,6 +138,7 @@ Gem::Specification.new do |s|
test/configs/test.rb
test/helper.rb
test/suite.rb
+ test/test_airbrake.rb
test/test_behavior.rb
test/test_campfire.rb
test/test_condition.rb
View
1  lib/god.rb
@@ -91,6 +91,7 @@ def load_contact(name)
load_contact(:scout)
load_contact(:twitter)
load_contact(:webhook)
+load_contact(:airbrake)
$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])
View
44 lib/god/contacts/airbrake.rb
@@ -0,0 +1,44 @@
+# Send a notice to Airbrake (http://airbrake.io/).
+#
+# apikey - The String API key.
+
+CONTACT_DEPS[:airbrake] = ['airbrake']
+CONTACT_DEPS[:airbrake].each do |d|
+ require d
+end
+
+module God
+ module Contacts
+ class Airbrake < Contact
+
+ class << self
+ attr_accessor :apikey
+ end
+
+ def valid?
+ valid = true
+ valid &= complain("Attribute 'apikey' must be specified", self) if self.apikey.nil?
+ valid
+ end
+
+ attr_accessor :apikey
+
+ def notify(message, time, priority, category, host)
+ ::Airbrake.configure {}
+
+ message = "God: #{message.to_s} at #{host}"
+ message << " | #{[category, priority].join(" ")}" unless category.to_s.empty? or priority.to_s.empty?
+
+ if ::Airbrake.notify nil, :error_message => message, :api_key => arg(:apikey)
+ self.info = "sent airbrake notification to #{self.name}"
+ else
+ self.info = "failed to send airbrake notification to #{self.name}"
+ end
+ rescue Object => e
+ applog(nil, :info, "failed to send airbrake notification: #{e.message}")
+ applog(nil, :debug, e.backtrace.join("\n"))
+ end
+
+ end
+ end
+end
View
14 test/test_airbrake.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + '/helper'
+
+class TestAirbrake < Test::Unit::TestCase
+ def test_notify
+ airbrake = God::Contacts::Airbrake.new
+ airbrake.apikey = "put_your_apikey_here"
+ airbrake.name = "Airbrake"
+
+ Airbrake.expects(:notify).returns "123"
+
+ airbrake.notify("Test message for airbrake", Time.now, "airbrake priority", "airbrake category", "")
+ end
+end
Something went wrong with that request. Please try again.