Class: LogStash::Outputs::Itda

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/itda.rb

Overview

Using hashes: # [source,ruby] # This plugin can be used to send all logstash data into BMC TrueSight IT Data Analytics. # To sue this plugin, an HTTP/HTTPS collector should be created in the ITDA instance, and # this configuration should point to the same. # The various properties supported are - # ———————————- # match => { # “host” => “<hostname>/<ipaddress>” # “port” => “nnnn” # “api_key” => “<key>” # “protocol” => “http/https” # “messageonly” => “true/false” # } # ———————————-

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



41
42
43
44
45
46
47
48
49
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
# File 'lib/logstash/outputs/itda.rb', line 41

def receive(event)

  event.remove('@timestamp')
  event.remove('@version')

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

  @logger.debug("ITDA event", :itda_event => event)

  begin
    if @messageonly
      message = event.remove('message')
      @logger.debug("ITDA message", :itda_message => message)

      request.body = message
      request.add_field("Content-Type", 'text/plain')
    else
      request.body = LogStash::Json.dump(event)
      request.add_field("Content-Type", 'application/json')
    end
    response = @client.request(request)
    @logger.warn("ITDA 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

  return "Event received"
end

#registerObject



31
32
33
34
35
36
37
38
# File 'lib/logstash/outputs/itda.rb', line 31

def register
  require "net/http"
  require "uri"
  @url = "#{@protocol}://#{@host}:#{@port}/"
  @uri = URI.parse(@url)
  @client = Net::HTTP.new(@uri.host, @uri.port)

end