Class: LogStash::Outputs::Datadog
- Defined in:
- lib/logstash/outputs/datadog.rb
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported
Methods included from Config::Mixin
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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/logstash/outputs/datadog.rb', line 55 def receive(event) return unless output?(event) dd_event = Hash.new dd_event['title'] = event.sprintf(@title) dd_event['text'] = event.sprintf(@text) dd_event['source_type_name'] = @source_type_name dd_event['alert_type'] = @alert_type if @alert_type dd_event['priority'] = @priority if @priority if @date_happened dd_event['date_happened'] = event.sprintf(@date_happened) else dd_event['date_happened'] = event["@timestamp"].to_i end if @dd_tags tagz = @dd_tags.collect {|x| event.sprintf(x) } else tagz = event["tags"] end dd_event['tags'] = tagz if tagz @logger.debug("DataDog event", :dd_event => dd_event) request = Net::HTTP::Post.new("#{@uri.path}?api_key=#{@api_key}") begin request.body = dd_event.to_json request.add_field("Content-Type", 'application/json') response = @client.request(request) @logger.info("DD 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 |
#register ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/logstash/outputs/datadog.rb', line 43 def register require "net/https" require "uri" @url = "https://app.datadoghq.com/api/v1/events" @uri = URI.parse(@url) @client = Net::HTTP.new(@uri.host, @uri.port) @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_NONE @logger.debug("Client", :client => @client.inspect) end |