Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Last active August 29, 2015 14:17
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 camillebaldock/f8a5d9487a6ecb019b88 to your computer and use it in GitHub Desktop.
Save camillebaldock/f8a5d9487a6ecb019b88 to your computer and use it in GitHub Desktop.
Dashing Gemnasium widget

Description

A Dashing widget for displaying the number of alerts in Gemnasium. If there are any updates availables, the widget will flash orange with the number of possible updates. If there are any security alerts, the widget will flash red with the number of alerts.

See a live demo here.

Usage

Setup the following environment variables:

Dependencies

rest-client

Add it to your Dashing application's Gemfile:

gem 'rest-client'

and run bundle install.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="gemnasium" data-view="Number" data-title="Gemnasium" style="background-color:#FFFF00"></div>
</li>
require 'rest_client'
SCHEDULER.every "30m", first_in: 0 do
response = RestClient.get "https://X:#{ENV["GEMNASIUM_TOKEN"]}@api.gemnasium.com/v1/projects"
results = JSON.parse(response.to_str)
colours = results["owned"].select do |result|
result["monitored"]
end.map do |monitored|
monitored["color"]
end
reds = colours.select { |colour| colour == "red" }
if reds.count > 0
send_event('gemnasium', { current: reds.count, "background-color" => 'red' })
else
yellows = colours.select { |colour| colour == "yellow" }
if yellows.count > 0
send_event('gemnasium', { current: yellows.count, "background-color" => 'yellow' })
else
send_event('gemnasium', { "background-color" => 'green' })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment