Hi All:
I am new to ruby so I am stuck on a piece of code. I am trying to
create a plugin check (see below).
The end result if a failed drive or drives are present to print the
following:
Failed Drive: 1I:1:2, 1E:3:24
However, due to the way I wrote the code, it’s only including the first
drive. I would appreciate any tips on what I should be doing! 
def check_array
slots=%x[/usr/sbin/hpacucli controller all show]
slots.each_line do |s|
s =~ /([Slot ][\d]{1,2})/
no = $1
no = no.lstrip if no
drives=%x[/usr/sbin/hpacucli controller slot=#{no} physicaldrive
all show]
drives.each_line do |line|
drive =[]
f =
/([0-9]{1,2}[a-zA-Z]{1,2}:[0-9]{1,2}:[0-9]{1,2})(.)Failed(.)/.match(line)
drive << f.captures[0] if f
end
critical “Failed Drive: #{drive}”
end
Am 30.07.2013 14:40, schrieb Jenn Fo:
drive. I would appreciate any tips on what I should be doing! 
drive =[]
f =
/([0-9]{1,2}[a-zA-Z]{1,2}:[0-9]{1,2}:[0-9]{1,2})(.)Failed(.)/.match(line)
drive << f.captures[0] if f
end
critical “Failed Drive: #{drive}”
end
The problem is that you reset `drive’ to an empty array in
each iteration.
Regards,
Marcus
unknown wrote in post #1117123:
Am 30.07.2013 14:40, schrieb Jenn Fo:
drive. I would appreciate any tips on what I should be doing! 
drive =[]
f =
/([0-9]{1,2}[a-zA-Z]{1,2}:[0-9]{1,2}:[0-9]{1,2})(.)Failed(.)/.match(line)
drive << f.captures[0] if f
end
critical “Failed Drive: #{drive}”
end
The problem is that you reset `drive’ to an empty array in
each iteration.
Regards,
Marcus
Edited because I think I got it 
Ah! I think I got it:
def check_array
slots=%x[/usr/sbin/hpacucli controller all show]
drive = []
slots.each_line do |s|
s =~ /([Slot ][\d]{1,2})/
no = $1
no = no.lstrip if no
drives=%x[/usr/sbin/hpacucli controller slot=#{no} physicaldrive
all show]
drives.each_line do |line|
f =
/([0-9]{1,2}[a-zA-Z]{1,2}:[0-9]{1,2}:[0-9]{1,2})(.)Failed(.)/.match(line)
drive.push f if f
end
end
puts “#{drive.join(’,’)}”
end
I just need to fix my reg expression 
On Tue, Jul 30, 2013 at 3:02 PM, Jenn Fo [email protected] wrote:
The problem is that you reset `drive’ to an empty array in
each iteration.
Regards,
Marcus
Ah! How should I do it correctly?
Initialize drive to an empty array before the loop.
Jesus.