Skip to content

Commit cf54bb4

Browse files
Sean Smithmajormoses
authored andcommitted
Fix Logic Error in MegaRAID Checks
Fixes #13. Parses output to retrieve list of virtual drives, checks drives for errors.
1 parent 74cf34f commit cf54bb4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
55
Which is based on [Keep A Changelog](http://keepachangelog.com/)
66

77
## [Unreleased]
8+
### Fixed
9+
- `check-megaraid-sas-status.rb`: Fixed logic error in which it was assumed that all virtual drives were in sequential order. Also fixed pattern matching when parsing individual drive status.
810

911
## [2.0.2] - 2018-04-18
1012
### Fixed

bin/check-megaraid-sas-status.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ class CheckMegaRAID < Sensu::Plugin::Check::CLI
5353
def run
5454
have_error = false
5555
error = ''
56-
# get number of virtual drives
57-
`#{config[:megaraidcmd]} -LDGetNum -a#{config[:controller]} `
58-
(0..$CHILD_STATUS.exitstatus - 1).each do |i|
56+
# get list of virtual drives
57+
stdout = `#{config[:megaraidcmd]} -LDInfo -LALL -a#{config[:controller]} `.split("\n")
58+
virtual_drives = []
59+
stdout.each do |line|
60+
if line =~ /^Virtual Drive:/
61+
virtual_drives << line.gsub(/^Virtual Drive: (\d+) .*$/, '\1')
62+
end
63+
end
64+
virtual_drives.each do |i|
5965
# and check them in turn
6066
stdout = `#{config[:megaraidcmd]} -LDInfo -L#{i} -a#{config[:controller]} `
61-
unless Regexp.new('State\s*:\s*Optimal').match?(stdout)
67+
unless Regexp.new(/State\s+:\s+Optimal/).match(stdout)
6268
error = sprintf '%svirtual drive %d: %s ', error, i, stdout[/State\s*:\s*.*/].split(':')[1] # rubocop:disable Style/FormatString
6369
have_error = true
6470
end

0 commit comments

Comments
 (0)