diff --git a/CHANGELOG.md b/CHANGELOG.md index 5973c0c..c7350a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins Which is based on [Keep A Changelog](http://keepachangelog.com/) ## [Unreleased] +### Added +- add option to run binaries with `sudo` +- add option to check-raid to specify the path to MegaCli binary ## [2.0.3] - 2019-02-17 ### Fixed diff --git a/bin/check-raid.rb b/bin/check-raid.rb index 199a66c..ae5a0bb 100755 --- a/bin/check-raid.rb +++ b/bin/check-raid.rb @@ -18,6 +18,12 @@ # gem: sensu-plugin # # USAGE: +# Use `--sudo true` option if the binaries require root permissions. +# +# Create a file named /etc/sudoers.d/sensu-check-raid +# and list all allowed commands with the correct path and options: +# Example: +# sensu ALL=(ALL) NOPASSWD: /usr/sbin/megacli -AdpAllInfo -aALL -NoLog # # NOTES: # @@ -38,6 +44,20 @@ class CheckRaid < Sensu::Plugin::Check::CLI long: '--log VALUE', boolean: true, default: false + + option :sudo, + description: 'Uses sudo to run commands', + short: '-s VALUE', + long: '--sudo VALUE', + boolean: true, + default: false + + option :megacli, + description: 'the MegaCli executable', + short: '-m CMD', + long: '--megacli CMD', + default: '/usr/sbin/megacli' + # Check software raid # def check_software_raid @@ -57,7 +77,7 @@ def check_software_raid # def check_hp return unless File.exist?('/usr/bin/cciss_vol_status') - contents = `/usr/bin/cciss_vol_status /dev/sg0` + contents = `#{@cmd_prefix}/usr/bin/cciss_vol_status /dev/sg0` c = contents.lines.grep(/status\: OK\./) # #YELLOW if c.empty? @@ -71,7 +91,7 @@ def check_hp # def check_adaptec return unless File.exist?('/usr/StorMan/arcconf') - contents = `/usr/StorMan/arcconf GETCONFIG 1 AL` + contents = `#{@cmd_prefix}/usr/StorMan/arcconf GETCONFIG 1 AL` mg = contents.lines.grep(/Controller Status/) # #YELLOW @@ -106,11 +126,11 @@ def check_adaptec # Check Megaraid # def check_mega_raid - return unless File.exist?('/usr/sbin/megacli') + return unless File.exist?(config[:megacli]) contents = if config[:log] - `/usr/sbin/megacli -AdpAllInfo -aALL` + `#{@cmd_prefix}#{config[:megacli]} -AdpAllInfo -aALL` else - `/usr/sbin/megacli -AdpAllInfo -aALL -NoLog` + `#{@cmd_prefix}#{config[:megacli]} -AdpAllInfo -aALL -NoLog` end failed = contents.lines.grep(/(Critical|Failed) Disks\s+\: 0/) degraded = contents.lines.grep(/Degraded\s+\: 0/) @@ -125,6 +145,7 @@ def check_mega_raid # Main function # def run + @cmd_prefix = config[:sudo] ? 'sudo ' : '' check_software_raid unless `lspci`.lines.grep(/RAID/).empty? check_hp