Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 26 additions & 5 deletions bin/check-raid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand All @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand Down Expand Up @@ -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/)
Expand All @@ -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
Expand Down