bin/handler-ses.rb in sensu-plugins-aws-9.0.1 vs bin/handler-ses.rb in sensu-plugins-aws-10.0.0
- old
+ new
@@ -9,11 +9,11 @@
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
require 'sensu-handler'
-require 'aws-sdk-v1'
+require 'aws-sdk'
class SESNotifier < Sensu::Handler
def event_name
@event['client']['name'] + '/' + @event['check']['name']
end
@@ -50,23 +50,10 @@
end
end
mail_to
end
- def use_ami_role
- use_ami_role = settings['ses']['use_ami_role']
- use_ami_role.nil? ? true : use_ami_role
- end
-
- def aws_access_key
- settings['ses']['access_key'] || ''
- end
-
- def aws_access_secret
- settings['ses']['secret_key'] || ''
- end
-
def region
settings['ses']['region'] || 'us-east-1'
end
def handle
@@ -86,26 +73,30 @@
"#{action_to_string} - #{event_name}: #{status_to_string}"
else
"#{action_to_string} - #{event_name}: #{@event['check']['notification']}"
end
- if use_ami_role
- AWS.config(region: region)
- else
- AWS.config(access_key_id: aws_access_key,
- secret_access_key: aws_access_secret,
- region: region)
- end
+ message = {
+ subject: {
+ data: subject
+ },
+ body: {
+ text: {
+ data: body
+ }
+ }
+ }
- ses = AWS::SimpleEmailService.new
+ ses = Aws::SES::Client.new(region: region)
begin
- timeout 10 do
+ Timeout.timeout(10) do
ses.send_email(
- subject: subject,
- from: mail_from,
- to: [mail_to.split(',')],
- body_text: body
+ source: mail_from,
+ destination: {
+ to_addresses: mail_to.split(',')
+ },
+ message: message
)
puts 'mail -- sent alert for ' + event_name + ' to ' + mail_to.to_s
end
rescue Timeout::Error