Class: LogStash::Outputs::Circonus

Inherits:
Base show all
Defined in:
lib/logstash/outputs/circonus.rb

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#receive(event) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/logstash/outputs/circonus.rb', line 50

def receive(event)
  # TODO (lusis)
  # batch and flush
  return unless output?(event)
 
  annotation_event = Hash[*@annotation.collect{|k,v| [event.sprintf(k),event.sprintf(v)]}.flatten]
  @logger.warn("Annotation event", :data => annotation_event)

  annotation_array = []
  annotation_path = "#{@uri.path}annotation"
  @logger.warn("Annotation path", :data => annotation_path)
  request = Net::HTTP::Post.new(annotation_path)
  annotation_event['start'] = event["@timestamp"].to_i unless annotation_event['start']
  annotation_event['stop'] = event["@timestamp"].to_i unless annotation_event['stop']
  @logger.warn("Annotation event", :data => annotation_event)
  annotation_array << annotation_event
  begin
    request.set_form_data(:annotations => annotation_array.to_json)
    @logger.warn(annotation_event)
    request.add_field("X-Circonus-Auth-Token", "#{@api_token}")
    request.add_field("X-Circonus-App-Name", "#{event.sprintf(@app_name)}")
    response = @client.request(request)
    @logger.warn("Circonus convo", :request => request.inspect, :response => response.inspect)
    raise unless response.code == '200'
  rescue Exception => e
    @logger.warn("Unhandled exception", :request => request.inspect, :response => response.inspect, :exception => e.inspect)
  end
end

#registerObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/outputs/circonus.rb', line 38

def register
  require "net/https"
  require "uri"
  @url = "https://circonus.com/api/json/"
  @uri = URI.parse(@url)
  @client = Net::HTTP.new(@uri.host, @uri.port)
  @client.use_ssl = true
  @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
  
end