bin/check-raid.rb in sensu-plugins-raid-checks-2.0.0 vs bin/check-raid.rb in sensu-plugins-raid-checks-2.0.1

- old
+ new

@@ -1,6 +1,8 @@ #! /usr/bin/env ruby +# frozen_string_literal: true + # # check-raid # # DESCRIPTION: # Generic raid check @@ -36,100 +38,95 @@ long: '--log VALUE', boolean: true, default: false # Check software raid # - def check_software - if File.exist?('/proc/mdstat') - contents = File.read('/proc/mdstat') - mg = contents.lines.grep(/active|blocks/) - unless mg.empty? - sg = mg.to_s.lines.grep(/\]\(F\)|[\[U]_/) - unless sg.empty? # rubocop:disable UnlessElse - warning 'Software RAID warning' - else - ok 'Software RAID OK' - end - end + def check_software_raid + return unless File.exist?('/proc/mdstat') + contents = File.read('/proc/mdstat') + mg = contents.lines.grep(/active|blocks/) + return unless mg.empty? + sg = mg.to_s.lines.grep(/\]\(F\)|[\[U]_/) + if sg.empty? + ok 'Software RAID OK' + else + warning 'Software RAID warning' end end # Check HP raid # def check_hp - if File.exist?('/usr/bin/cciss_vol_status') - contents = `/usr/bin/cciss_vol_status /dev/sg0` - c = contents.lines.grep(/status\: OK\./) - # #YELLOW - unless c.empty? # rubocop:disable UnlessElse - ok 'HP RAID OK' - else - warning 'HP RAID warning' - end + return unless File.exist?('/usr/bin/cciss_vol_status') + contents = `/usr/bin/cciss_vol_status /dev/sg0` + c = contents.lines.grep(/status\: OK\./) + # #YELLOW + if c.empty? + warning 'HP RAID warning' + else + ok 'HP RAID OK' end end # Check Adaptec raid controllers # def check_adaptec - if File.exist?('/usr/StorMan/arcconf') - contents = `/usr/StorMan/arcconf GETCONFIG 1 AL` + return unless File.exist?('/usr/StorMan/arcconf') + contents = `/usr/StorMan/arcconf GETCONFIG 1 AL` - mg = contents.lines.grep(/Controller Status/) - # #YELLOW - unless mg.empty? # rubocop:disable UnlessElse - sg = mg.to_s.lines.grep(/Optimal/) - warning 'Adaptec Physical RAID Controller Failure' if sg.empty? - else - warning 'Adaptec Physical RAID Controller Status Read Failure' - end + mg = contents.lines.grep(/Controller Status/) + # #YELLOW + if mg.empty? + warning 'Adaptec Physical RAID Controller Status Read Failure' + else + sg = mg.to_s.lines.grep(/Optimal/) + warning 'Adaptec Physical RAID Controller Failure' if sg.empty? + end - mg = contents.lines.grep(/Status of logical device/) - # #YELLOW - unless mg.empty? # rubocop:disable UnlessElse - sg = mg.to_s.lines.grep(/Optimal/) - warning 'Adaptec Logical RAID Controller Failure' if sg.empty? - else - warning 'Adaptec Logical RAID Controller Status Read Failure' - end + mg = contents.lines.grep(/Status of logical device/) + # #YELLOW + if mg.empty? + warning 'Adaptec Logical RAID Controller Status Read Failure' + else + sg = mg.to_s.lines.grep(/Optimal/) + warning 'Adaptec Logical RAID Controller Failure' if sg.empty? + end - mg = contents.lines.grep(/S\.M\.A\.R\.T\. /) - # #YELLOW - unless mg.empty? # rubocop:disable UnlessElse - sg = mg.to_s.lines.grep(/No/) - warning 'Adaptec S.M.A.R.T. Disk Failed' if sg.empty? - else - warning 'Adaptec S.M.A.R.T. Status Read Failure' - end - - ok 'Adaptec RAID OK' + mg = contents.lines.grep(/S\.M\.A\.R\.T\. /) + # #YELLOW + if mg.empty? + warning 'Adaptec S.M.A.R.T. Status Read Failure' + else + sg = mg.to_s.lines.grep(/No/) + warning 'Adaptec S.M.A.R.T. Disk Failed' if sg.empty? end + + ok 'Adaptec RAID OK' end # Check Megaraid # def check_mega_raid - if File.exist?('/usr/sbin/megacli') - contents = if config[:log] - `/usr/sbin/megacli -AdpAllInfo -aALL` - else - `/usr/sbin/megacli -AdpAllInfo -aALL -NoLog` - end - failed = contents.lines.grep(/(Critical|Failed) Disks\s+\: 0/) - degraded = contents.lines.grep(/Degraded\s+\: 0/) - # #YELLOW - unless failed.empty? || degraded.empty? # rubocop:disable UnlessElse - ok 'MegaRaid RAID OK' - else - warning 'MegaRaid RAID warning' - end + return unless File.exist?('/usr/sbin/megacli') + contents = if config[:log] + `/usr/sbin/megacli -AdpAllInfo -aALL` + else + `/usr/sbin/megacli -AdpAllInfo -aALL -NoLog` + end + failed = contents.lines.grep(/(Critical|Failed) Disks\s+\: 0/) + degraded = contents.lines.grep(/Degraded\s+\: 0/) + # #YELLOW + if failed.empty? || degraded.empty? + warning 'MegaRaid RAID warning' + else + ok 'MegaRaid RAID OK' end end # Main function # def run - check_software + check_software_raid unless `lspci`.lines.grep(/RAID/).empty? check_hp check_adaptec check_mega_raid