Skip to content

Instantly share code, notes, and snippets.

@anderm3
Forked from jwalton/REAMDE.md
Last active March 28, 2017 20:00
Show Gist options
  • Save anderm3/7379d1bc4b492f2bc69ef4d95712efb6 to your computer and use it in GitHub Desktop.
Save anderm3/7379d1bc4b492f2bc69ef4d95712efb6 to your computer and use it in GitHub Desktop.
Pingdom widget for Dashing
class Dashing.Pingdom extends Dashing.Widget
<h1 class="title" data-bind="title"></h1>
<ul>
<li class="check" data-foreach-check="checks" data-bind-data-state="check.state">
<span class="checkName" data-bind="check.name"></span><span class="checkPing" data-bind="check.lastRepsonseTime"></span>
</li>
</ul>
require "rest-client"
require "cgi"
require "json"
api_key = ENV['PINGDOM_API_KEY'] || ''
user = ENV['PINGDOM_USER'] || ''
password = ENV['PINGDOM_PASSWORD'] || ''
limit_tags = ENV['PINGDOM_TAGS'] || ''
SCHEDULER.every '1m', :first_in => 0 do
# Get checks
url = "https://#{CGI::escape user}:#{CGI::escape password}@api.pingdom.com/api/2.0/checks?tags=#{CGI::escape limit_tags}"
response = RestClient.get(url, {"App-Key" => api_key})
response = JSON.parse(response.body, :symbolize_names => true)
if response[:checks]
checks = response[:checks].map { |check|
if check[:status] == 'up'
state = 'up'
last_response_time = "#{check[:lastresponsetime]}ms"
else
state = 'down'
last_response_time = "DOWN"
end
{ name: check[:name], state: state, lastRepsonseTime: last_response_time }
}
else
checks = [name: "pingdom", state: "down", lastRepsonseTime: "-"]
end
checks.sort_by { |check| check['name'] }
send_event('pingdom', { checks: checks })
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #FFF400;
$text-color: #000000;
// ----------------------------------------------------------------------------
// Widget-clock styles
// ----------------------------------------------------------------------------
.widget-pingdom {
background-color: $background-color;
color: $text-color;
.check {
float: left;
padding: 4px 0px;
width:100%
}
.check[data-state="up"] {
}
.check[data-state="down"] {
background-color: #B72126;
}
.check span {
padding: 0px 4px;
}
.checkName {
float: left;
font-weight: bold
}
.checkPing {
float: right
}
}

Description

Simple Dashing widget (and associated job) to display Pingdom checks.

##Dependencies

rest-client

Add it to dashing's gemfile:

gem 'rest-client'

and run bundle install. Everything should work now :)

##Usage

To use this widget, copy pingdom.html, pingdom.coffee, and pingdom.scss into the /widgets/pingdom directory. Put the pingdom.rb file in your /jobs folder.

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

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="pingdom" data-view="Pingdom" data-title="Pingdom" data-cols="1"></div>
</li>

##Settings

You'll need to add your pingdom API key and login settings. You can either add it straight to the source code on lines 4-6 of pingdom.rb, or set the variables in the ENV. For heroku, you can do this with

heroku config:set PINGDOM_API_KEY=
heroku config:set PINGDOM_USER=
heroku config:set PINGDOM_PASSWORD=
heroku config:set PINGDOM_TAGS=

Pingdom is checked every minute, but you can change that by editing the job schedule.

Contributions

This has been extracted from a dashboard for the UK Ministry of Justice, with minimal generalising. Feel free to submit patches to @james.

Modified by @jwalton to use rest-client instead of pingdom-client.

@anderm3 Added support for limiting Pingdom API response by tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment