Sha256: 27338d4eb95706a5d00cd96b6ca440209b2e61db121a3237fa8c1f29f46cf6a1

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

#!/usr/bin/env ruby
#
# Copyright 2011 Sonian, Inc <chefs@sonian.net>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'librato/metrics'

class LibratoMetrics < Sensu::Handler
  # override filters from Sensu::Handler. not appropriate for metric handlers
  def filter; end

  def handle
    hostname = @event['client']['name'].split('.').first
    # #YELLOW
    check_name = @event['check']['name'].gsub(%r{[ \.]}, '_') # rubocop:disable RegexpLiteral
    metric = "sensu.events.#{hostname}.#{check_name}.occurrences"
    value = @event['action'] == 'create' ? @event['occurrences'] : 0

    Librato::Metrics.authenticate settings['librato']['email'], settings['librato']['api_key']

    begin
      timeout(3) do
        Librato::Metrics.submit metric.to_sym => { type: :counter, value: value, source: 'sensu' }
      end
    rescue Timeout::Error
      puts "librato -- timed out while sending metric #{metric}"
    rescue => error
      puts "librato -- failed to send metric #{metric} : #{error}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-librato-0.0.1 bin/handler-librato-occurrences.rb