File:Check raid

From RARForge
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Check_raid(file size: 2 KB, MIME type: application/x-perl)

Warning: This file type may contain malicious code. By executing it, your system may be compromised.

<source lang=perl>

  1. !/usr/bin/perl -w

use strict;

my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2);

open (MDSTAT, "</proc/mdstat") or die "Failed to open /proc/mdstat"; my $srch = $ARGV[0]; my $found = 0; my $status = ""; my $recovery = ""; my $check = ""; my $finish = ""; my $speed = ""; my $y = ""; my $y2 = ""; while(<MDSTAT>) {

   if (/^$srch\s/) {
       $found = 1;
       $y = <MDSTAT>;
       $y .= <MDSTAT>;
   }

}

if ($found) {

   if ($y =~ /(\[[_U]+\])/) {
       $status = $1;
   }
   if ($y =~ /recovery\s+=\s+(.*?)\s/) {  # recovery =  9.5% (14730216/153918464) finish=211.1min
       $recovery = $1;
       ($finish) = $y =~ /finish=([^\s]+)/;
       ($speed) = $y =~ /speed=([^\s]+)/;
   }
   if ($y =~ /check\s+=\s+(.*?)\s/) {  # recovery =  9.5% (14730216/153918464) finish=211.1min
       $check = $1;
       ($finish) = $y =~ /finish=([^\s]+)/;
       ($speed) = $y =~ /speed=([^\s]+)/;
   }

}

my $msg = "FAILURE"; my $code = "UNKNOWN"; if ($status =~ /_/ || $check) {

   if ($recovery) {
       my $MBs = $speed;
       if ($speed =~ /(\d+)/) {
           $MBs = sprintf("%.2f",$1/1024) . ' MB/s';
       }
       $msg = sprintf "%s status=%s, recovery=%s, finish=%s speed=%s\n", $ARGV[0], $status, $recovery, $finish, $MBs;
       $code = "WARNING";
   } elsif ($check) {
       my $MBs = $speed;
       if ($speed =~ /(\d+)/) {
           $MBs = sprintf("%.2f",$1/1024) . ' MB/s';
       }
       $msg = sprintf "%s status=%s, check=%s, finish=%s speed=%s\n", $ARGV[0], $status, $recovery, $finish, $MBs;
       $code = "OK";
   } else {
       $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
       $code = "CRITICAL";
   }

} elsif ($status =~ /U+/) {

   $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
   $code = "OK";

} else {

   if ($found) {
       $msg = sprintf "%s\n", $ARGV[0];
       $code = "OK";
   } else {
       $msg = sprintf "%s does not exist.\n", $ARGV[0];
       $code = "CRITICAL";
   }

}

print $code, ": ", $msg; exit ($ERRORS{$code}); </source>

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeDimensionsUserComment
current23:50, 1 March 2013 (2 KB)Robertr (talk | contribs)

The following page uses this file: