bin/check-instance-events.rb in sensu-plugins-aws-6.0.0 vs bin/check-instance-events.rb in sensu-plugins-aws-6.0.1
- old
+ new
@@ -11,11 +11,11 @@
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
-# gem: aws-sdk-v1
+# gem: aws-sdk
# gem: sensu-plugin
#
# USAGE:
# #YELLOW
#
@@ -119,21 +119,25 @@
# ]
useful_events =
i[:events].reject { |x| (x[:code] =~ /system-reboot|instance-reboot|instance-stop|system-maintenance/) && (x[:description] =~ /\[Completed\]|\[Canceled\]/) }
unless useful_events.empty?
+ name = ''
if config[:include_name]
- name = ''
begin
instance_desc = ec2.describe_instances(instance_ids: [i[:instance_id]])
- name = instance_desc[:reservation_index][i[:instance_id]][:instances_set][0][:tag_set].select { |tag| tag[:key] == 'Name' }[0][:value]
+ name_tag = instance_desc.reservations[0].instances[0].tags.find { |tag| tag[:key] == 'Name' }
+ name = name_tag.nil? ? '' : name_tag.value
rescue => e
puts "Issue getting instance details for #{i[:instance_id]} (#{r}). Exception = #{e}"
end
- event_instances << "#{name} (#{i[:instance_id]} #{r}) (#{i[:events][0][:code]}) #{i[:events][0][:description]}"
- else
- event_instances << "#{i[:instance_id]} (#{r}) (#{i[:events][0][:code]}) #{i[:events][0][:description]}"
end
+
+ event_instances << if name.empty?
+ "#{i[:instance_id]} (#{r}) (#{i[:events][0][:code]}) #{i[:events][0][:description]}"
+ else
+ "#{name} (#{i[:instance_id]} #{r}) (#{i[:events][0][:code]}) #{i[:events][0][:description]}"
+ end
end
end
rescue => e
unknown "An error occurred processing AWS EC2 API (#{r}): #{e.message}"
end