check_linux_raid.pl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl -w
  2. # Copyright (c) 2002 ISOMEDIA, Inc.
  3. # Written by Steve Milton
  4. # Released under the GNU Public License
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # Usage: check_raid <raid-name>
  21. # Example: check_raid md0
  22. # WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
  23. use strict;
  24. my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2);
  25. open (MDSTAT, "</proc/mdstat") or die "Failed to open /proc/mdstat";
  26. my $found = 0;
  27. my $status = "";
  28. my $recovery = "";
  29. my $finish = "";
  30. my $active = "";
  31. while(<MDSTAT>) {
  32. if ($found) {
  33. if (/(\[[_U]+\])/) {
  34. $status = $1;
  35. } elsif (/recovery = (.*?)\s/) {
  36. $recovery = $1;
  37. ($finish) = /finish=(.*?min)/;
  38. }
  39. } else {
  40. if (/$ARGV[0]/) {
  41. $found = 1;
  42. if (/active/) {
  43. $active = 1;
  44. }
  45. }
  46. }
  47. }
  48. my $msg = "FAILURE";
  49. my $code = "UNKNOWN";
  50. if ($status =~ /_/) {
  51. if ($recovery) {
  52. $msg = sprintf "%s status=%s, recovery=%s, finish=%s\n",
  53. $ARGV[0], $status, $recovery, $finish;
  54. $code = "WARNING";
  55. } else {
  56. $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
  57. $code = "CRITICAL";
  58. }
  59. } elsif ($status =~ /U+/) {
  60. $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
  61. $code = "OK";
  62. } else {
  63. if ($active) {
  64. $msg = sprintf "%s active with no status information.\n",
  65. $ARGV[0];
  66. $code = "OK";
  67. } else {
  68. $msg = sprintf "%s does not exist.\n", $ARGV[0];
  69. $code = "CRITICAL";
  70. }
  71. }
  72. print $code, " ", $msg;
  73. exit ($ERRORS{$code});