Skip to content

Instantly share code, notes, and snippets.

@mickey
Created Sep 4, 2013
Embed
What would you like to do?
Bugsnag unresolved issues widget for Dashing

##Description

Simple Dashing job to display total number of unresolved issues from BugSnag.

##Preview

##Dependencies

link_header

Add it to dashing's gemfile:

gem 'link_header'

and run bundle install.

##Usage

  1. Add the widget HTML to your dashboard
    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="bugsnag" data-view="Number" data-title="Bugsnag unresolved issues">
      </div>
    </li>
  1. Add bugsnag.rb in your jobs directory.

  2. Enjoy!

# get the number of unresolved issues for your bugsnag project
# TODO: more exceptions/errors handling
require "net/https"
require "uri"
require 'json'
require "link_header"
require 'pry'
PROJECT_NAME = "api"
BUGSNAG_AUTH_TOKEN = "XXXXXX"
def my_get(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
request["Authorization"] = "token #{BUGSNAG_AUTH_TOKEN}"
http.request(request)
end
def get_project
response = my_get("https://api.bugsnag.com/account/projects")
parsed_body = JSON.parse(response.body)
parsed_body.find {|project| project["name"] == PROJECT_NAME}
end
def get_unresolved_issues(project_id, count = 0, url = "/errors?per_page=100")
response = my_get("https://api.bugsnag.com/projects/#{project_id}#{url}")
parsed_body = JSON.parse(response.body)
count += parsed_body.select{|error| error["resolved"] == false}.count
link_header = LinkHeader.parse(response["Link"]).to_a
if !link_header.empty?
next_page_ar = link_header.find {|link| link[1][0][1] == "next"}
if next_page_ar
next_page = next_page_ar[0]
next_page.slice!("https://api.bugsnag.com/projects/#{project_id}")
get_unresolved_issues(project_id, count, next_page)
end
end
count
end
SCHEDULER.every '30m', :first_in => 0 do |job|
project = get_project
count = get_unresolved_issues(project["id"])
send_event('bugsnag', { current: count })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment