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
The problem is that you reset `drive' to an empty array in
each iteration.
Regards,
Marcus
路路路
Am 30.07.2013 14:40, schrieb Jenn Fo:
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
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.
Initialize drive to an empty array before the loop.
Jesus.
路路路
On Tue, Jul 30, 2013 at 3:02 PM, Jenn Fo <lists@ruby-forum.com> wrote:
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.