Talk:Gmirror

 use strict; use warnings;
 * 1) !/usr/bin/perl

use lib "/usr/local/libexec/nagios"; use utils qw(%ERRORS);

my $result = `/sbin/gmirror status`; $result =~ m/(DEGRADED|COMPLETE)/g; my $status = $1; my $rebuild = ($result =~ m/(\w\w\d \(\d\d?\%\))/); $result =~ m/(\w\w\d \(\d\d?\%\))/; my $progress = $1;

if ($status =~ /COMPLETE/){ print "Raid Optimal\n"; exit $ERRORS{'OK'}; } elsif (($status =~ /DEGRADED/) and ($rebuild == 1)) { print "Raid Reconstructing: $progress\n"; exit $ERRORS{'WARNING'}; } else { print "Raid Critical!\n"; exit $ERRORS{'CRITICAL'}; } 


 * 1) !/bin/sh


 * 1) raid_status - check the state of the RAID.


 * 1) This script works for various types of RAID devices.  (Currently, 3Ware,
 * 2) gmirror, BSd 'ar0' raids, zpool)
 * 3) WARNING: Install the proper CLI program for your 3ware card, if you use 3ware.


 * 1) Set up a cronjob like this:
 * 2) */16 * * * * /home/rudy/bin/raid_status CRON


 * 1) Copyright (c) 2006, Rudy Rucker All rights reserved.
 * 2) Redistribution and use of script, with or without modification, is
 * 3) permitted provided that the following condition is met:
 * 4)    Redistributions of source code must retain the above copyright
 * 5)    notice, this list of conditions and the following disclaimer.
 * 6) THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * 7) ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * 8) IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * 9) ARE DISCLAIMED.


 * 1) --- Change Log
 * 2) Mon Oct 11 15:20:37 PDT 2004 - rudy
 * 3)  Original script.
 * 4) Tue Feb  7 01:28:07 PST 2006 - rudy
 * 5)  Added 9500 and 9550 support
 * 6) Fri Jun  9 10:38:33 PDT 2006 - rudy
 * 7)  works for 'ar' and 'tw' mirrored arrays
 * 8) Tue Sep 12 10:23:13 PDT 2006 - rudy
 * 9)  Added gmirror and realized that not all 3ware's are the same...
 * 10) Fri Jan 18 00:46:13 PST 2008 - rudy
 * 11)  going to add support for multiple geom mirrors. gm0s1, gm0s2, etc...
 * 12) Fri Jan 18 01:03:25 PST 2008 - rudy
 * 13)  added zpool status checking.  untested  :)
 * 14) Fri Jan 18 01:23:54 PST 2008
 * 15)  can check machines with multiple array types... got zfs and gmirror?
 * 16)  tested a machine with zfs and gmirror

MODE=$1

TWCLI="/usr/local/bin/tw_cli" GMIRROR="/sbin/gmirror" ATACONTROL="/sbin/atacontrol"

AWK="/usr/bin/awk" GREP="/usr/bin/grep" MAIL="/usr/bin/mail" SORT="/usr/bin/sort" ZPOOL="/sbin/zpool"

EMAIL="noc@example.com"

STATUS="none_tested"

report_status { # Okay, we checked the raid status and know what the return code should be. if [ "$STATUS" = "$VALID" ]; then if [ "$MODE" != "CRON" ]; then echo "OK condition"; $ESTATUS_CMD echo fi else # ERROR! Either print to TTY or send an email, based on MODE (which is arg[1]) if [ "$MODE" = "CRON" ]; then $ESTATUS_CMD | $MAIL -s "[ERROR] Raid array on $HOST returned $STATUS" $EMAIL else echo "ERROR condition" $ESTATUS_CMD fi fi       STATUS="UNKNOWN" }

if [ -c /dev/twed0 ] && [ -x $TWCLI ]; then # Tested: 3ware card ... 8000 series STATUS=`$TWCLI info c0 u0 | $GREP "^Status" | $AWK {'print $2'}`; VALID='OK' ESTATUS_CMD="$TWCLI info c0 u0"; # double check the 3ware output incase it returned nada... # Umm... this is the only raid card I have witness this bug if [ "X$STATUS" = "X" ]; then sleep 1; STATUS=`$TWCLI info c0 u0 | $GREP "^Status" | $AWK {'print $2'}`; fi report_status elif [ -c /dev/da0 ] && [ -x $TWCLI ]; then # Note, there are plenty of other device names that use da0... # if you have the TWCLI installed, assume da0 is a RAID. # Tested: 3ware 9550SX, 9500S, 9650 STATUS=`$TWCLI info c0 | $GREP "^u0" | $AWK '{print $3}'`; VALID='OK' ESTATUS_CMD="$TWCLI info c0 u0" report_status fi if [ -d /dev/mirror ] && [ -x $GMIRROR ]; then # gmirror /dev/mirror/gm0 gm0s1 gm0s2 etc... # the 'sort -u' allows this to test multiple arrays. Neat hack. :)	STATUS=`$GMIRROR status | $GREP "^mirror" | $AWK {'print $2'} | $SORT -u`;	VALID='COMPLETE'	ESTATUS_CMD="$GMIRROR list";       report_status fi if [ -c /dev/ar0 ] && [ -x $ATACONTROL ]; then	# Motherboard promise and others	STATUS=`$ATACONTROL status ar0 | $GREP "status" | $AWK -F 'status: ' '{print $2}'`;	VALID='READY'	ESTATUS_CMD="/sbin/atacontrol status ar0"        report_status fi if [ -c /dev/zfs ] && [ -x $ZPOOL ]; then	# Tested:  zpool mirror on FreeBSD 7.0	STATUS=`$ZPOOL status -x`;	VALID='all pools are healthy'	ESTATUS_CMD="$ZPOOL status -v";        report_status fi if  [ "$STATUS" = "none_tested" ]; then	echo "Unknown Raid type.... ";	if [ -x $TWCLI ]; then		echo " + found $TWCLI";	else		echo " - can't exec $TWCLI";	fi	if [ -x $ATACONTROL ]; then		echo " + found $ATACONTROL";	else		echo " - can't exec $ATACONTROL";	fi	if [ -x $ZPOOL ]; then		echo " + found $ZPOOL";	else		echo " - can't exec $ZPOOL"; fi if [ -x $GMIRROR ]; then echo " + found $GMIRROR"; else echo " - can't exec $GMIRROR"; fi exit; fi
 * 1) if this is not a 3ware card, check the atacontol

