Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Last active October 27, 2016 08:54
Show Gist options
  • Save tolleiv/c695b22a12259f0809f8 to your computer and use it in GitHub Desktop.
Save tolleiv/c695b22a12259f0809f8 to your computer and use it in GitHub Desktop.
Puppet Radiator Dashing Widget

Puppet Radiator Widget

This is a Dashing widget and all components needed to port the original radiator information into an Dashing Widget.

##Usage

To use this widget, copy puppet_radiator.html, puppet_radiator.coffee, and puppet_radiator.scss into the /widgets/puppet_radiator directory. Put the puppet_radiator.rb file in your /jobs folder. Or simply run dashing install c695b22a12259f0809f8 to let dashing do that for you.

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="2">
   <div data-id="puppet_nodes" data-view="PuppetRadiator" data-title="Puppet"></div>
 </li>

##Settings

In order to use your puppet server you've to adjust the puppet_url setting in the puppet_radiator.rb.

##Preview Puppet Radiator Dashing Widget

class Dashing.PuppetRadiator extends Dashing.Widget
ready: ->
# Nothing
<h1 class="title" data-bind="title"></h1>
<ul>
<li data-foreach-item="items" data-bind-class="item.label | downcase | prepend 'state-'">
<a data-bind-href="item.link">
<span class="label" data-bind="item.label"></span>
<span class="value" data-bind="item.value"></span>
</a>
</li>
</ul>
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'rexml/document'
include REXML
require 'open-uri'
puppet_url = "http://puppet.example.com:3000"
SCHEDULER.every '1m' do
ppfile = open("#{puppet_url}/radiator") {|f| f.read }
xmldoc = Document.new(ppfile)
values = []
%w(unresponsive failed pending changed unchanged unreported).each do |state|
value = XPath.first(xmldoc, "//*[contains(@class,'#{state}')]//span[contains(@class,'count')]/text()")
values.push({label: state.capitalize, value: value, link: "#{puppet_url}/nodes/#{state}"}) # if value.to_s.to_i > 0
end
send_event("puppet_nodes", items: values)
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #303030;
// $background-color: #8e938c;
//$background-color: rgba(0,0,0, 0.3);
$value-color: #fff;
$value-failed-color: #cc2211;
$value-unresponsive-color: #888888;
$value-pending-color: #ee7722;
$value-changed-color: #006699;
$value-unchanged-color: #009933;
$value-unreported-color: #aaaaaa;
$label-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-list styles
// ----------------------------------------------------------------------------
.widget.widget-puppet-radiator {
vertical-align: top;
background-color: $background-color;
padding:12px 12px;
ul {
text-align: left;
color: $label-color;
font-size:18px;
margin-bottom: 30px;
}
li {
margin-bottom: 5px;
border-bottom: 1px solid #333;
}
li:last-child {
border: none;
}
.list-nostyle {
list-style: none;
}
.label {
// color: $label-color;
font-weight: bold;
}
.value {
float: right;
margin-left: 12px;
font-weight: bold;
// color: $value-color;
}
.state-changed {
color: $value-changed-color;
}
.state-failed {
color: $value-failed-color;
}
.state-unresponsive {
color: $value-unresponsive-color;
}
.state-unreported {
color: $value-unreported-color;
}
.state-unchanged {
color: $value-unchanged-color;
}
.state-pending {
color: $value-pending-color;
}
.updated-at {
// color: rgba(0, 0, 0, 0.3);
}
.more-info {
color: $moreinfo-color;
}
}
@MelanieGault
Copy link

Hi,
This work seems to be what I'm looking for, but it does not seems to work on puppet 2015.x.
What is your puppet version please ?

Thanks !

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