check_linux_raid.pl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. last;
  36. } elsif (/recovery = (.*?)\s/) {
  37. $recovery = $1;
  38. ($finish) = /finish=(.*?min)/;
  39. last;
  40. }
  41. } else {
  42. if (/$ARGV[0]/) {
  43. $found = 1;
  44. if (/active/) {
  45. $active = 1;
  46. }
  47. }
  48. }
  49. }
  50. my $msg = "FAILURE";
  51. my $code = "UNKNOWN";
  52. if ($status =~ /_/) {
  53. if ($recovery) {
  54. $msg = sprintf "%s status=%s, recovery=%s, finish=%s\n",
  55. $ARGV[0], $status, $recovery, $finish;
  56. $code = "WARNING";
  57. } else {
  58. $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
  59. $code = "CRITICAL";
  60. }
  61. } elsif ($status =~ /U+/) {
  62. $msg = sprintf "%s status=%s\n", $ARGV[0], $status;
  63. $code = "OK";
  64. } else {
  65. if ($active) {
  66. $msg = sprintf "%s active with no status information.\n",
  67. $ARGV[0];
  68. $code = "OK";
  69. } else {
  70. $msg = sprintf "%s does not exist.\n", $ARGV[0];
  71. $code = "CRITICAL";
  72. }
  73. }
  74. print $code, " ", $msg;
  75. exit ($ERRORS{$code});