Skip to content

Instantly share code, notes, and snippets.

@ChrisCrewdson
Last active October 3, 2020 20:05
Show Gist options
  • Save ChrisCrewdson/0b13460565762293cab7 to your computer and use it in GitHub Desktop.
Save ChrisCrewdson/0b13460565762293cab7 to your computer and use it in GitHub Desktop.
Uptime Robot Dashing Widget

Simple Uptime Robot Dashing widget

Description

Dashing widget to display a short list of Uptime Robot monitors.

##Usage

Add this to your Gemfile and run bundle install:

gem 'uptimerobot'

The files uptimerobot.coffee, uptimerobot.html and uptimerobot.scss go in the /widget/uptimerobot directory.

The uptimerobot.rb goes into the /jobs directory.

Put the following in your dashboard.erb file to make it show up in your dashboard:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="uptimerobot" data-view="Uptimerobot"></div>
</li>

##Settings (uptimerobot.rb)

You will need to provide an API key from Uptime Robot API

class Dashing.Uptimerobot extends Dashing.Widget
<h1>Server status</h1>
<ul>
<li class="monitor" data-foreach-monitor="monitors" data-bind-class="monitor.status">
<span data-bind="monitor.friendlyname"></span>
</li>
</ul>
require 'uptimerobot'
apiKey = ENV['UPTIMEROBOT_APIKEY']
SCHEDULER.every '5m', :first_in => 0 do |job|
client = UptimeRobot::Client.new(apiKey: apiKey)
raw_monitors = client.getMonitors['monitors']['monitor']
monitors = raw_monitors.map { |monitor|
{
friendlyname: monitor['friendlyname'],
status: 'S' << monitor['status']
}
}
send_event('uptimerobot', { monitors: monitors } )
end
// 0 - paused
// 1 - not checked yet
// 2 - up
// 8 - seems down
// 9 - down
$S0-color: rgba(128, 128, 128, 0.5);
$S1-color: rgba(200, 255, 200, 0.5);
$S2-color: rgba(50, 205, 50, 0.5);
$S8-color: rgba(255, 50, 50, 0.5);
$S9-color: rgba(255, 50, 50, 0.5);
.widget-uptimerobot {
background: linear-gradient(to bottom, #3b4248 0%,#2a2f34 40%,#222529 100%);
.S0 {
background: $S0-color;
}
.S1 {
background: $S1-color;
}
.S2 {
background: $S2-color;
}
.S8 {
background: $S8-color;
}
.S9 {
background: $S9-color;
}
}
@vxrdanny
Copy link

vxrdanny commented May 7, 2018

hi @Flo3561, the link doesn't work and I can't get this to work - can you help please?

@h-evers
Copy link

h-evers commented Mar 21, 2019

The correct link is https://gist.github.com/Flo3561/9664be31e6cd9f53abc909b8c4b3b567 and there's a little bug (at least with current dependencies): you have to change the API keys id in the constructor to

client = UptimeRobot::Client.new(api_key: apiKey)

It's an underscore...

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