Skip to content

Instantly share code, notes, and snippets.

@brucemartins
Forked from codingfoo/Readme.md
Last active August 29, 2015 14:10
Show Gist options
  • Save brucemartins/2de7a062cb8762921233 to your computer and use it in GitHub Desktop.
Save brucemartins/2de7a062cb8762921233 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment