class LogStash::Outputs::OpsGenie

For more information about the api requests and their contents, please refer to Alert API(“www.opsgenie.com/docs/web-api/alert-api”) support doc.

Public Instance Methods

receive(event) click to toggle source
# File lib/logstash/outputs/opsgenie.rb, line 79
def receive(event)
  alert = {
    :apiKey => @api_key
  }
  case @opsgenie_action
  when 'create'
    action_path = @create_action_url
    alert[:message] = event.sprintf(@message)
    alert[:teams] = @teams if @teams
    alert[:actions] = @actions if @actions
    alert[:description] = event.sprintf(@description) if @description
    alert[:recipients] = @recipients if @recipients
    alert[:tags] = @tags if @tags
    alert[:details] = {}
    @details.each do |key, value|
      alert[:details]["#{key}"] = event.sprintf(value)
    end
  when 'close'
    action_path = @close_action_url
  when 'acknowledge'
    action_path = @acknowledge_action_url
  when 'note'
    action_path = @note_action_url
  end

  alert['alias'] = event.sprintf(@alert_alias) if @alert_alias
  alert['id'] = event.sprintf(@alert_id) if @alert_id

  begin
    request = Net::HTTP::Post.new(action_path)
    request.body = LogStash::Json.dump(alert)
    @logger.debug('OpsGenie Request', :request => request.inspect)
    response = @client.request(request)
    @logger.debug('OpsGenie Response', :response => response.body)
  rescue Exception => e
    @logger.error('OpsGenie Unhandled exception', :og_error => e.backtrace)
  end
end
register() click to toggle source
# File lib/logstash/outputs/opsgenie.rb, line 69
def register
  opsgenie_uri = URI.parse(@opsgenie_base_url)
  @client = Net::HTTP.new(opsgenie_uri.host, opsgenie_uri.port)
  if opsgenie_uri.scheme == 'https'
    @client.use_ssl = true
    @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end