Class: LogStash::Outputs::Boundary

Inherits:
Base show all
Defined in:
lib/logstash/outputs/boundary.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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/logstash/outputs/boundary.rb', line 70

def receive(event)
  return unless output?(event)

  boundary_event = Hash.new
  boundary_keys = ['type', 'subtype', 'creation_time', 'end_time', 'links', 'tags', 'loc']

  boundary_event['start_time'] = event.sprintf(@start_time) if @start_time
  boundary_event['end_time'] = event.sprintf(@end_time) if @end_time
  boundary_event['type'] = event.sprintf(@btype) if @btype
  boundary_event['subtype'] = event.sprintf(@bsubtype) if @bsubtype
  boundary_event['tags'] = @btags.collect { |x| event.sprintf(x) } if @btags

  if @auto
    boundary_fields = event['@fields'].select { |k| boundary_keys.member? k }
    boundary_event = boundary_fields.merge boundary_event
  end

  boundary_event = {
    'type' => event.sprintf("%{message}"),
    'subtype' => event.sprintf("%{type}"),
    'start_time' => event["@timestamp"].to_i,
    'end_time' => event["@timestamp"].to_i,
    'links' => [],
    'tags' => event["tags"],
  }.merge boundary_event

  request = Net::HTTP::Post.new(@uri.path)
  request.basic_auth(@api_key, '')

  @logger.debug("Boundary event", :boundary_event => boundary_event)

  begin
    request.body = boundary_event.to_json
    request.add_field("Content-Type", 'application/json')
    response = @client.request(request)
    @logger.warn("Boundary convo", :request => request.inspect, :response => response.inspect)
    raise unless response.code == '201'
  rescue Exception => e
    @logger.warn(
      "Unhandled exception",
      :request => request.inspect,
      :response => response.inspect,
      :exception => e.inspect
    )
  end
end

#registerObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/logstash/outputs/boundary.rb', line 58

def register
  require "net/https"
  require "uri"
  @url = "https://api.boundary.com/#{@org_id}/annotations"
  @uri = URI.parse(@url)
  @client = Net::HTTP.new(@uri.host, @uri.port)
  @client.use_ssl = true
  # Boundary cert doesn't verify
  @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
end