Skip to content

Instantly share code, notes, and snippets.

@Flo3561
Forked from ChrisCrewdson/README.md
Last active October 4, 2020 01:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flo3561/9664be31e6cd9f53abc909b8c4b3b567 to your computer and use it in GitHub Desktop.
Save Flo3561/9664be31e6cd9f53abc909b8c4b3b567 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. This version is compatible with the current Uptime Robot APIv2 (https://uptimerobot.com/api).

##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>
<p class="updated-at" data-bind="updatedAtMessage"></p>
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']
monitors = raw_monitors.map { |monitor|
{
friendlyname: monitor['friendly_name'],
status: 'S' << monitor['status'].to_s
}
}
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 3, 2018

How do I get this to work with Api v2? It throws an error up for me:

rufus-scheduler intercepted an error:
job:
Rufus::Scheduler::EveryJob "5m" {:first_in=0}
ArgumentError :api_key is required.

I have inserted my API key on the appropriate line "apiKey = ENV['UPTIMEROBOT_APIKEY']"

Please advise, many thanks.

@PipeItToDevNull
Copy link

PipeItToDevNull commented Jul 2, 2018

@vxrdanny

Two issues I had, the RB and a stupid case issue. Pay special attention to cases in "div data-id="uptimerobot" data-view="Uptimerobot"" One Uptime is capital, one is lowercase.

I fixed this, I modified the RB as below (per the API page):

``
require 'uptimerobot'

SCHEDULER.every '5m', :first_in => 0 do |job|
client = UptimeRobot::Client.new(api_key: 'API_KEY_HERE')

raw_monitors = client.getMonitors['monitors']

monitors = raw_monitors.map { |monitor|
{
friendlyname: monitor['friendly_name'],
status: 'S' << monitor['status'].to_s
}
}

send_event('uptimerobot', { monitors: monitors } )
end
``

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