Class: LogStash::Outputs::OpsGenie

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

Overview

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.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



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
116
# 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

#registerObject



69
70
71
72
73
74
75
76
# 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