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
|