Skip to content

Instantly share code, notes, and snippets.

@bhankus
Last active December 24, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhankus/6828496 to your computer and use it in GitHub Desktop.
Save bhankus/6828496 to your computer and use it in GitHub Desktop.
Honeybadger widget for Dashing dashboard

##Preview

Description

Simple Dashing widget (and associated job) to display recent or frequent Honeybadger errors.

Created at Homefinder.com

Check out other widgets we've made at https://github.com/Homefinder/dashing-widgets

##Usage To use this widget, copy honeybadger.html, honeybadger.coffee, and honeybadger.scss into the /widgets/honeybadger directory. Put the honeybadger.rb file in your /jobs folder. Copy hb.png into the /assets/images directory.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="2" data-col="3" data-sizex="2" data-sizey="1">
  <div data-id="most_freq_fault" data-view="Honeybadger" data-title="Most Frequent Errors" ></div>
</li>
<li data-row="2" data-col="5" data-sizex="2" data-sizey="1">
  <div data-id="most_recent_fault" data-view="Honeybadger" data-title="Most Recent Errors"></div>
</li>

##Settings Set your Honeybadger API token, and set the project_id of your Honeybadger project in 'honeybadger.rb'. Project ID can be found in https://api.honeybadger.io/v1/projects?auth_token=API_KEY .

class Dashing.Honeybadger extends Dashing.Widget
onData: (data) ->
<h1>Honeybadger</h1>
<h3 class="title" data-bind="title"></h3>
<ul>
<li data-foreach-item="errors">
<span class="occurrence_count">(<span class="value" data-bind="item.notices_count"></span>)</span>
<span class="label" data-bind="item.klass"></span>
<span class="fault_location"> in <span class="value" data-bind="item.component"></span>#<span class="value" data-bind="item.action"></span></span>
</li>
</ul>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'net/http'
require 'json'
# pass in limit: 5 to get the top 5 errors
def get_honeybadger_errors(options = {})
api_token = "YOUR API TOKEN HERE"
project_id = "YOUR PROJECT ID HERE"
url = "https://api.honeybadger.io/v1/projects/#{project_id}/faults?auth_token=#{api_token}"
if options[:order]
url += "&order=#{options[:order]}"
end
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri, {'Accept' => 'application/json', 'Content-Type' => 'application/json'})
response = http.request(request)
json_response = JSON.parse(response.body)
upper_bound = options[:limit] || 5
json_response['results'][0..(upper_bound - 1)]
end
SCHEDULER.every '10s', :first_in => 0 do |job|
# pass in your own limit, or let it default to 5
top_five_faults = get_honeybadger_errors(order: "frequent")
recent_five_faults = get_honeybadger_errors(order: "recent")
send_event('most_freq_fault', {errors: top_five_faults})
send_event('most_recent_fault', {errors: recent_five_faults})
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #CA4430;
$title-color: rgba(255, 255, 255, 0.8);
$moreinfo-color: rgba(255, 255, 255, 0.8);
// ----------------------------------------------------------------------------
// Widget-text styles
// ----------------------------------------------------------------------------
.widget-honeybadger {
background-color: $background-color;
background-image: url("/assets/hb.png");
background-repeat: no-repeat;
background-position: center center;
h1, .title {
color: $title-color;
}
ul {
margin-left: 50px;
margin-top: 30px;
list-style-type: none;
li {
margin: 5px;
text-align: left;
}
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
.fault_location {
font-size: 12px;
}
.occurrence_count {
color: #FA89A4;
}
}
The MIT License (MIT)
Copyright (c) 2013 Brock Hankus
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment