Skip to content

Instantly share code, notes, and snippets.

@codingfoo
Last active February 12, 2016 03:44
Show Gist options
  • Save codingfoo/5535577 to your computer and use it in GitHub Desktop.
Save codingfoo/5535577 to your computer and use it in GitHub Desktop.
Sensu Widget for Dashing

Description

Simple Dashing job to send sensu client history checks to dashing widgets.

##Dependencies

##Usage

Put the sensu.rb file in your /jobs folder.

Add a snippet, like the one below, to the dashboard layout file for each client/check combination. Customize it to work for the particular client and check:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="sensuclientname-sensucheckname" data-view="Text" data-title="sensu check" data-text="Waiting For Data"></div>
</li>

##Settings

Checks are fetched every 3 minutes, but you can change that by editing the job schedule.

Change the SENSU_API_ENDPOINT if dashing is not running on the same host as the sensu api server.

require 'net/http'
require 'json'
SENSU_API_ENDPOINT = 'http://localhost:4567'
STATUS_MESSAGE = { '0' => 'OK', '1' => 'WARNING', '2' => 'CRITICAL' }
STATUS_COLOR = { '0' => '#96bf48', '1' => '#FFFF00', '2' => '#FF0000' }
SCHEDULER.every '3m', :first_in => 0 do |job|
uri = URI.parse(SENSU_API_ENDPOINT)
http = Net::HTTP.new(uri.host, uri.port)
response = http.request(Net::HTTP::Get.new("/clients"))
clients = JSON.parse(response.body)
clients.each do |client|
response = http.request(Net::HTTP::Get.new("/clients/#{client['name']}/history"))
checks = JSON.parse(response.body)
checks.each do |check|
next if check['check'] == 'keepalive' #TODO: incorporate keepalive into check success criteria
id = "#{client['name']}-#{check['check']}"
status = "#{check['last_status']}"
message = STATUS_MESSAGE[status]
send_event(id, text: message)
end
end
end
@JSzaszvari
Copy link

There is nothing in here that actually changes the STATUS_COLOR on the dash.

The variables are set, but nothing ever happens with them

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