Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 122 lines (105 sloc) 3.189 kb
#!/usr/bin/env ruby
# == Synopsis
#
# Check linux raid using mdadm
#
# == Usage
#
# check_raid [md device]
#
# == License
#
# This script was developed by Tangeis, LLC and Kinetic Web
# Solutions, LLC. It's released undere the MIT License in the hopes
# that it be found useful and that we make some small contribution
# to a culture of software which has been so helpful to us.
#
# Feel free to pass comments along to alibby at tangeis dot com.
#
# The MIT License
#
# Copyright (c) 2007 Tangeis LLC and Kinetic Web Solutions.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
require 'getoptlong'
begin
require 'rdoc/ri/ri_paths'
require 'rdoc/usage'
rescue Exception => e
# Do nothing
end
require 'ostruct'
class String
def to_assign_method_name
self.downcase.strip.gsub(/\s+/,'_') + "="
end
end
class RaidStat < OpenStruct
def initialize(dev)
super()
IO.popen("/sbin/mdadm --detail #{dev}") { |io|
read_entry io
}
raise Exception.new("mdadm call failed....") if $? && $?.exitstatus != 0
end
def read_entry(io)
io.each_line do |line|
next unless line.length > 0
case line
when /^\s+([^:]+):(.*)/
self.send($1.to_assign_method_name,$2.strip)
when /^(\/.*):$/
self.device=$1
end
end
end
end
device = ARGV.shift
unless device
puts "WARNING: plugin usage error: suplly device!"
exit 3
end
begin
raid = RaidStat.new(device)
rescue Exception => e
puts "WARNING: Failed to get raid status for device: #{e}"
exit 3
end
labels = %w/OK WARNING CRITICAL UNKNOWN/
status = 0
if raid.state =~ /^clean|active/ && raid.failed_devices.to_i > 0
status = 1
elsif raid.state =~ /^clean, degraded/
status = 1
elsif raid.state =~ /^clean|active/
status = 0
elsif raid.state =~ /recovering/ && raid.failed_devices.to_i > 0
status = 1
elsif raid.state =~ /recovering/
status = 0
elsif raid.failed_devices.to_i > 0
status = 2
elsif raid.state =~ /degraded/
status = 1
else
status = 3
end
puts "#{labels[status]}: #{raid.device}: State => #{raid.state} #{raid.rebuild_status} - Failed Devices => #{raid.failed_devices}"
exit status
Jump to Line
Something went wrong with that request. Please try again.