Skip to content

Instantly share code, notes, and snippets.

@dyson
Forked from camillebaldock/README.md
Created November 29, 2015 12:32
Show Gist options
  • Save dyson/c18b2b7fd0a0864e0b73 to your computer and use it in GitHub Desktop.
Save dyson/c18b2b7fd0a0864e0b73 to your computer and use it in GitHub Desktop.
Dashing Statuscake widget

Description

A Dashing widget for displaying the number of websites down according to StatusCake.

See a live demo here.

Usage

Setup the following environment variables:

  • STATUSCAKE_USERNAME: as specified here
  • STATUSCAKE_KEY: get your API key here

See instructions here to learn how to setup your token and client ID.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="statuscake" data-view="Number" data-title="Monitoring" style="background-color:#3ADF00"></div>
</li>
require 'json'
username = ENV["STATUSCAKE_USERNAME"]
key = ENV["STATUSCAKE_KEY"]
SCHEDULER.every "1h" do
items=[]
is_down=0
status='ok'
response = Net::HTTP.get_response(URI('https://www.statuscake.com/API/Tests/?Username='+username+'&API='+key))
all_tests = JSON.parse(response.body)
test_ids = all_tests.map do |site_test|
site_test["TestID"]
end
test_ids.each do |testid|
response = Net::HTTP.get_response(URI("https://www.statuscake.com/API/Tests/Details/?TestID=#{testid}&Username=#{username}&API=#{key}"))
website = JSON.parse(response.body)
if website['Status']!='Up'
items << { site: website['WebsiteName'], status: website['Status'], lasttest: website['LastTested'] }
status='warning'
end
end
send_event('statuscake', { current: items.count, status: 'danger' })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment