bin/handler-ec2_node.rb in sensu-plugins-aws-1.1.0 vs bin/handler-ec2_node.rb in sensu-plugins-aws-1.2.0
- old
+ new
@@ -1,8 +1,10 @@
#!/usr/bin/env ruby
#
# CHANGELOG:
+# * 0.6.0:
+# - Fixed ec2_node_should_be_deleted to account for an empty insances array
# * 0.5.0:
# - Adds configuration to filter by state reason
# * 0.4.0:
# - Adds ability to specify a list of states an individual client can have in
# EC2. If none is specified, it filters out 'terminated' and 'stopped'
@@ -128,10 +130,10 @@
def ec2_node_should_be_deleted?
ec2 = Aws::EC2::Client.new(region: region)
states = @event['client']['ec2_states'] || settings['ec2_node']['ec2_states'] || ['shutting-down', 'terminated', 'stopping', 'stopped']
begin
instances = ec2.describe_instances(instance_ids: [@event['client']['name']]).reservations[0]
- if instances.nil?
+ if instances.nil? || instances.empty?
true
else
instance = instances.instances[0]
state_reason = instance.state_reason.code
state = instance.state.name