]> pere.pagekite.me Git - homepage.git/blob - linux/check_gdth_raid
Nytt bokforslag.
[homepage.git] / linux / check_gdth_raid
1 #!/usr/bin/perl
2 #
3 # Author: Petter Reinholdtsen
4 # Date: 2006-05-15
5 # License: GPL
6 #
7 # Nagios module to report the RAID status from the gdth linux kernel
8 # module.
9 #
10 # Based on documentation found in
11 # <URL:http://nagiosplug.sourceforge.net/developer-guidelines.html>
12
13 use strict;
14 use warnings;
15
16 use Getopt::Long;
17
18 my $verbose;
19 my $help;
20 my $RC = 0;
21
22 sub usage {
23 print "Usage: $0 [-h|--help]\n";
24 print " Reports the gdth status as found in /proc/scsi/gdth/*\n"
25 }
26
27 my $result = GetOptions ("help" => \$help, "verbose+" => \$verbose);
28
29 if ($help) {
30 usage();
31 exit 0;
32 }
33
34 if ( ! -d "/proc/scsi/gdth" ) {
35 print "No gdth status file found, /proc/scsi/gdth/ missing";
36 exit 3;
37 }
38
39 chdir "/proc/scsi/gdth";
40
41 my $RESULT = "";
42
43 # Looking for this text block:
44 # Logical Drives:
45 # Number: 0 Status: ok
46 # Capacity [MB]: 17333 Type: RAID-1
47 # Slave Number: 15 Status: ok
48 # Missing Drv.: 0 Invalid Drv.: 0
49 # To Array Drv.: --
50 for my $controller (<*>) {
51 open(INFO, "< $controller") || die "Unable to read from $controller";
52 # Have to use 'cat', as redirect into egrep didn't work with the
53 # file in /proc/.
54 while (<INFO>) {
55 chomp;
56 last if (/Array Drives:/); # Stop after the Logical Drive block
57 if (m/^\s+Number:\s+(\d+)\s+Status:\s+(\S+)$/) {
58 my ($num, $status) = ($1,$2);
59 if ("ok" ne $status) {
60 $RC = 2;
61 $RESULT="$RESULT ID $controller volume $num($status)";
62 # print "Gdth RAID controller $controller volume $num ($status) NOT OK\n"
63 } else {
64 # print "Gdth RAID controller $controller volume $num OK\n"
65 }
66 }
67 }
68 close(INFO);
69 }
70 if ( 0 == "$RC" ) {
71 print "gdth RAID OK\n";
72 } else {
73 print "gdth RAID $RESULT NOT OK\n";
74 }
75 exit $RC;