diff options
| author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
|---|---|---|
| committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
| commit | 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch) | |
| tree | 1c2b6b21704a294940f87c7892676998d8371707 /web/attachments/154512-check_linux_raid.pl | |
| download | site-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz | |
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts,
and configuration files.
Diffstat (limited to 'web/attachments/154512-check_linux_raid.pl')
| -rw-r--r-- | web/attachments/154512-check_linux_raid.pl | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/web/attachments/154512-check_linux_raid.pl b/web/attachments/154512-check_linux_raid.pl new file mode 100644 index 0000000..a7a948a --- /dev/null +++ b/web/attachments/154512-check_linux_raid.pl | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | #!/usr/bin/perl -w | ||
| 2 | |||
| 3 | # Copyright (c) 2002 ISOMEDIA, Inc. | ||
| 4 | # Written by Steve Milton | ||
| 5 | # Released under the GNU Public License | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License as published by | ||
| 9 | # the Free Software Foundation; either version 2 of the License, or | ||
| 10 | # (at your option) any later version. | ||
| 11 | # | ||
| 12 | # This program is distributed in the hope that it will be useful, | ||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | # GNU General Public License for more details. | ||
| 16 | # | ||
| 17 | # You should have received a copy of the GNU General Public License | ||
| 18 | # along with this program; if not, write to the Free Software | ||
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | # | ||
| 21 | # Usage: check_raid <raid-name> | ||
| 22 | # Example: check_raid md0 | ||
| 23 | # WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use Getopt::Long qw(:config no_ignore_case); | ||
| 27 | |||
| 28 | my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2); | ||
| 29 | |||
| 30 | my $mdstat = "/proc/mdstat"; | ||
| 31 | my $verbose = 0; | ||
| 32 | |||
| 33 | GetOptions('mdstat=s' => \$mdstat, | ||
| 34 | 'v|verbose+' => \$verbose, | ||
| 35 | 'h|help' => sub { usage(); exit $ERRORS{'UNKNOWN'}; }, | ||
| 36 | 'V|version' => sub { version(); exit $ERRORS{'UNKNOWN'}; }); | ||
| 37 | |||
| 38 | # die with an error if we're not on Linux | ||
| 39 | if ($^O ne 'linux') { | ||
| 40 | print "This plugin only applicable on Linux.\n"; | ||
| 41 | exit $ERRORS{'UNKNOWN'}; | ||
| 42 | } | ||
| 43 | |||
| 44 | my $mddev = shift; | ||
| 45 | |||
| 46 | open (MDSTAT, "<$mdstat") or die "Failed to open $mdstat"; | ||
| 47 | my $found = 0; | ||
| 48 | my $status = ""; | ||
| 49 | my $recovery = ""; | ||
| 50 | my $finish = ""; | ||
| 51 | my $speed = ""; | ||
| 52 | my $active = ""; | ||
| 53 | while(<MDSTAT>) { | ||
| 54 | chomp; | ||
| 55 | if ($found) { | ||
| 56 | if (/(\[[_U]+\])/) { | ||
| 57 | $status = $1; | ||
| 58 | } elsif (/recovery *= *([^ ]+)/) { | ||
| 59 | $recovery = $1; | ||
| 60 | ($finish) = /finish= *([^ ]+)/; | ||
| 61 | ($speed) = /speed= *([^ ]+)/; | ||
| 62 | } elsif (/^[^ \t]/) { | ||
| 63 | last; | ||
| 64 | } | ||
| 65 | } else { | ||
| 66 | if (/^$mddev\s*:/) { | ||
| 67 | $found = 1; | ||
| 68 | if (/active/) { | ||
| 69 | $active = 1; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | my $msg = "FAILURE"; | ||
| 76 | my $code = "UNKNOWN"; | ||
| 77 | if ($status =~ /_/) { | ||
| 78 | if ($recovery) { | ||
| 79 | $msg = "$mddev status=$status, recovery=$recovery, finish=$finish, speed=$speed", | ||
| 80 | $code = "WARNING"; | ||
| 81 | } else { | ||
| 82 | $msg = "$mddev status=$status"; | ||
| 83 | $code = "CRITICAL"; | ||
| 84 | } | ||
| 85 | } elsif ($status =~ /U+/) { | ||
| 86 | $msg = "$mddev status=$status"; | ||
| 87 | $code = "OK"; | ||
| 88 | } else { | ||
| 89 | if ($active) { | ||
| 90 | $msg = "$mddev active with no status information"; | ||
| 91 | $code = "OK"; | ||
| 92 | } else { | ||
| 93 | $msg = "$mddev does not exist"; | ||
| 94 | $code = "CRITICAL"; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | print "RAID $code: $msg\n"; | ||
| 99 | exit ($ERRORS{$code}); | ||
| 100 | |||
| 101 | sub usage { | ||
| 102 | print qq{usage: | ||
| 103 | check_linux_raid.pl [--mdstat=</proc/mdstat>] <md-device> | ||
| 104 | e.g. | ||
| 105 | check_linux_raid.pl md0 | ||
| 106 | }; | ||
| 107 | } | ||
| 108 | |||
| 109 | sub version { | ||
| 110 | print "check_linux_raid.pl 1.1\n"; | ||
| 111 | } | ||
