Skip to content

Instantly share code, notes, and snippets.

@pepitooo
Last active November 1, 2022 20:29
Show Gist options
  • Save pepitooo/4801f31b66981889bd550ba093755501 to your computer and use it in GitHub Desktop.
Save pepitooo/4801f31b66981889bd550ba093755501 to your computer and use it in GitHub Desktop.
Ping widget for smashing (dashing)

preview

preview

description

Simple widget to ping a host and get color feedback, green => online red => offline

dependencies

net-ping

Add it to dashing's gemfile:

gem 'net-ping'

usage

To use this widget : create a directory /widgets/ping copy ping.html, ping.coffee, and ping.scss into the /widgets/ping directory. copy ping.rb into the jobs directory. add config.yml into the app root directory

ping:
  id:
    ip: IP
    name: HOST_NAME

id I choose to be a number, but need to match with what there is in dashboard.erb

setup

you can add many widget ping as you want, by modifing the list of hosts in config.yml and copy pasting the widget in the dashboard.erb if you have a lot of ping to do, you should consider increasing the screduler time inside jobs.rb specially if you have a lot of offline hosts

ping:
1:
ip: 192.168.1.45
name: surveillance
2:
ip: 192.168.1.46
name: host_slave
3:
ip: 192.168.1.47
name: host_master
<!-- for 3 ping widgets, for more copy paste a li tag and increment the data-id -->
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="ping_1" data-view="Ping" data-unordered="true"></div>
</li>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="ping_2" data-view="Ping" data-unordered="true"></div>
</li>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="ping_3" data-view="Ping" data-unordered="true"></div>
</li>
class Dashing.Ping extends Dashing.Widget
<ul>
<li data-bind-class="status">
<h1 class="title" data-bind="hostname"></h1>
<h4 data-bind="host"></h4>
</li>
<p class="updated-at" data-bind="updatedAtMessage"></p>
</ul>
require 'net/ping'
settings = YAML.load_file(File.join(File.expand_path('./.'), 'config.yml'))
tirs_settings = settings['ping']
settings['ping'].each do |_id, host|
SCHEDULER.every '10s', :first_in => 0 do
status = up?(host['ip']) ? "green" : "red"
send_event("ping_#{_id}", {status: status, host: host['ip'], hostname: host['name']})
end
end
$background: #444;
$text: #fff;
$success: #86d751;
$warning: #edde43;
$failure: #e3394f;
$error: #f75f00;
.widget-ping {
li {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding-top: 25px;
h3 {
font-size: 60px;
font-weight: bold;
}
h4 {
font-size: 20px;
font-weight: bold;
text-transform: uppercase;
}
p &.updated-at {
font-size: 10px;
}
&.green {
background-color: $success;
p {
&.updated-at {
color: lighten($success, 20%);
}
}
}
&.yellow {
background-color: $warning;
p {
&.updated-at {
color: lighten($warning, 20%);
}
}
}
&.red {
background-color: $failure;
p {
&.updated-at {
color: lighten($failure, 20%);
}
}
}
&.error {
background-color: $error;
p {
&.updated-at {
color: lighten($error, 20%);
}
}
}
}
}
@jon-rse
Copy link

jon-rse commented Nov 1, 2022

def up?(host)
        check = Net::Ping::External.new(host)
        check.ping? 
end

is missing from ping.rb (it was in a previous revision). Add it back to get this widget to work.

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