Sha256: 58cbbf14118366826efbcb6b6cdc3730bb815319ad1b86a11b6c6c6f63b485b2

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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 '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.2 bin/handler-librato-occurrences.rb