check_netapp.pl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/usr/bin/perl -wT
  2. # check_netapp
  3. #
  4. # Copyright (C) 2000 Leland E. Vandervort <leland@mmania.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (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
  13. # of 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 (or with Nagios); if not, write to the
  18. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. # Boston, MA 02111-1307, USA
  20. ####################################
  21. # checks for overtemperature, fans, psu, and nfs operations/second on
  22. # Network Appliance Filers.
  23. # Returns:
  24. # OK if temp, fans, psu OK and Ops/Sec below warning and critical
  25. # Thresholds (default is warning=3500, critical=5000)
  26. # ** Note: See the specifications for your Filer model for
  27. # the thresholds !
  28. # Returns Warning if NFS Ops/Sec is above warning threshold
  29. # (default 3500, or specified by -o command line option)
  30. # Returns Critical if NFS Ops/Sec is above critical threshold
  31. # ( -m option, or default 5000), or if overtem, psufault, or
  32. # fanfault detected.
  33. #
  34. ####################################
  35. # Notes on operational limits for NetApp Filers:
  36. # Platform Maximum Ops/Second (recommended)
  37. # -------------------------------------------------------------
  38. # F230 1000
  39. # F740 5500
  40. # F760 9000
  41. ####################################
  42. use Net::SNMP;
  43. use Getopt::Long;
  44. &Getopt::Long::config('auto_abbrev');
  45. my $status;
  46. my $response = "";
  47. my $TIMEOUT = 10;
  48. my $community = "public";
  49. my $port = 161;
  50. my $opsthresh = "3500";
  51. my $critical = "5000";
  52. my $status_string = "";
  53. my %OIDLIST = (
  54. overtemp => '1.3.6.1.4.1.789.1.2.4.1.0',
  55. failedfan => '1.3.6.1.4.1.789.1.2.4.2.0',
  56. failedpsu => '1.3.6.1.4.1.789.1.2.4.4.0',
  57. nfsops => '1.3.6.1.4.1.789.1.2.2.1.0'
  58. );
  59. my %STATUSCODE = ( 'UNKNOWN' => '-1',
  60. 'OK' => '0',
  61. 'WARNING' => '1',
  62. 'CRITICAL' => '2');
  63. my $state = "UNKNOWN";
  64. $SIG{'ALRM'} = sub {
  65. print "ERROR: No snmp response from $hostname (sigALRM)\n";
  66. exit($STATUSCODE{"UNKNOWN"});
  67. };
  68. alarm($TIMEOUT);
  69. sub get_nfsops {
  70. my $nfsops_start = &SNMPGET($OIDLIST{nfsops});
  71. sleep(1);
  72. my $nfsops_end = &SNMPGET($OIDLIST{nfsops});
  73. my $nfsopspersec = $nfsops_end - $nfsops_start;
  74. return($nfsopspersec);
  75. }
  76. sub show_help {
  77. printf("\nPerl NetApp filer plugin for Nagios\n");
  78. printf("Usage:\n");
  79. printf("
  80. check_netapp [options] <hostname>
  81. Options:
  82. -c snmp-community
  83. -p snmp-port
  84. -o Operations per second warning threshold
  85. -m Operations per second critical threshold
  86. ");
  87. printf("Copyright (C)2000 Leland E. Vandervort\n");
  88. printf("check_netapp comes with absolutely NO WARRANTY either implied or explicit\n");
  89. printf("This program is licensed under the terms of the\n");
  90. printf("GNU General Public License\n(check source code for details)\n\n\n");
  91. exit($STATUSCODE{"UNKNOWN"});
  92. }
  93. $status = GetOptions( "community=s", \$community,
  94. "port=i", \$port,
  95. "opsthresh=i", \$opsthresh,
  96. "maxops=i", \$critical );
  97. if($status == 0) {
  98. &show_help;
  99. }
  100. sub SNMPGET {
  101. $OID = shift;
  102. ($session,$error) = Net::SNMP->session(
  103. Hostname => $hostname,
  104. Community => $community,
  105. Port => $port
  106. );
  107. if(!defined($session)) {
  108. printf("$state %s\n", $error);
  109. exit($STATUSCODE{$state});
  110. }
  111. if(!defined($response = $session->get_request($OID))) {
  112. printf("$state %s\n", $session->error());
  113. $session->close();
  114. exit($STATUSCODE{$state});
  115. }
  116. $session->close();
  117. return($response->{$OID});
  118. }
  119. $hostname = shift || &show_help;
  120. my $tempcheck = &SNMPGET($OIDLIST{overtemp});
  121. if($tempcheck == 1) {
  122. $state = "OK";
  123. $status_string .= "Temp OK ";
  124. }
  125. else {
  126. $state = "CRITICAL";
  127. $status_string .= "Temp CRIT";
  128. }
  129. foreach $element ('failedfan','failedpsu') {
  130. my $my_return = &SNMPGET($OIDLIST{$element});
  131. if(($my_return =~ /no/) || ($my_return == 0)) {
  132. $status_string .= "$element = $my_return ";
  133. $state = "OK";
  134. }
  135. else {
  136. $status_string .= "$element = $my_return ";
  137. $state = "CRITICAL";
  138. }
  139. }
  140. my $tmp_opssec = &get_nfsops();
  141. if ($tmp_opssec >= $critical) {
  142. $state = "CRITICAL";
  143. }
  144. elsif ($tmp_opssec >= $opsthresh) {
  145. $state = "WARNING";
  146. }
  147. else {
  148. $state = "OK";
  149. }
  150. $status_string .= "Ops\/Sec = $tmp_opssec ";
  151. print "$state $status_string\n";
  152. exit($STATUSCODE{$state});