checkciscotemp.pl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/usr/bin/perl -wT
  2. # check_ciscotemp.pl
  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. # Nagios pluging to check inlet and outlet temperatures on
  22. # Cisco router platforms which support environmental monitoring
  23. # (7200, 7500, GSR12000...)
  24. ####################################
  25. # default temperature thresholds are 30C for inlet, 40C outlet.
  26. # if input or output is less than thresholds, returns OK
  27. # if equal to (the temps don't change that rapidly) returns WARNING
  28. # if greater than threshold, returns CRITICAL
  29. # if undetermined, or cannot access environmental, returns UNKNOWN
  30. # (in accordance with the plugin coding guidelines)
  31. ####################################
  32. use Net::SNMP;
  33. use Getopt::Long;
  34. &Getopt::Long::config('auto_abbrev');
  35. my $status;
  36. my $response = "";
  37. my $timeout = 10;
  38. my $community = "public";
  39. my $port = 161;
  40. my $INTAKE_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.1";
  41. my $OUTLET_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.3";
  42. my $in_temp;
  43. my $out_temp;
  44. my $inlet_thresh = 30;
  45. my $outlet_thresh = 40;
  46. my %STATUSCODE = ( 'UNKNOWN' => '-1',
  47. 'OK' => '0',
  48. 'WARNING' => '1',
  49. 'CRITICAL' => '2');
  50. my $state = "UNKNOWN";
  51. $SIG{'ALRM'} = sub {
  52. print "ERROR: No snmp response from $hostname (sigALRM)\n";
  53. exit($STATUSCODE{"UNKNOWN"});
  54. };
  55. Getopt::Long::Configure('bundling');
  56. $status = GetOptions
  57. ("community=s", \$community,
  58. "C=s", \$community,
  59. "H=s", \$hostname,
  60. "hostname=s", \$hostname,
  61. "port=i", \$port,
  62. "timeout=i", \$timeout,
  63. "c=s", \$critical_vals,
  64. "w=s", \$warning_vals,
  65. "ithresh=i", \$inlet_thresh,
  66. "othresh=i", \$outlet_thresh);
  67. if($status == 0) {
  68. &show_help;
  69. }
  70. unless (defined($hostname)) {
  71. $hostname = shift || &show_help;
  72. }
  73. if (defined($critical_vals)) {
  74. if ($critical_vals =~ m/^([0-9]+)[,:]([0-9]+)$/) {
  75. ($inlet_thresh,$outlet_thresh) = ($1, $2);
  76. } else {
  77. die "Cannot Parse Critical Thresholds\n";
  78. }
  79. }
  80. if (defined($warning_vals)) {
  81. if ($warning_vals =~ m/^([0-9]+)[:,]([0-9]+)$/) {
  82. ($inlet_warn,$outlet_warn) = ($1, $2);
  83. } else {
  84. die "Cannot Parse Warning Thresholds\n";
  85. }
  86. }else{
  87. $inlet_warn=$inlet_thresh;
  88. $outlet_warn=$outlet_thresh;
  89. }
  90. alarm($timeout);
  91. $in_temp = &SNMPGET($INTAKE_TEMP);
  92. $out_temp = &SNMPGET($OUTLET_TEMP);
  93. if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {
  94. $state = "OK";
  95. }
  96. elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {
  97. if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
  98. $state = "CRITICAL";
  99. }
  100. else {
  101. $state = "WARNING";
  102. }
  103. }
  104. elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
  105. $state = "CRITICAL";
  106. }
  107. else {
  108. $state = "WARNING";
  109. }
  110. print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n";
  111. exit($STATUSCODE{$state});
  112. sub show_help {
  113. printf("\nPerl envmon temperature plugin for Nagios\n");
  114. printf("Usage:\n");
  115. printf("
  116. check_ciscotemp [options] <hostname>
  117. Options:
  118. -C snmp-community
  119. -p snmp-port
  120. -i input temperature threshold
  121. -o output temperature threshold
  122. ");
  123. printf("Copyright (C)2000 Leland E. Vandervort\n");
  124. printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");
  125. printf("This program is licensed under the terms of the\n");
  126. printf("GNU General Public License\n(check source code for details)\n\n\n");
  127. exit($STATUSCODE{"UNKNOWN"});
  128. }
  129. sub SNMPGET {
  130. $OID = shift;
  131. ($session,$error) = Net::SNMP->session(
  132. Hostname => $hostname,
  133. Community => $community,
  134. Port => $port
  135. );
  136. if(!defined($session)) {
  137. printf("$state %s\n", $error);
  138. exit($STATUSCODE{$state});
  139. }
  140. if(!defined($response = $session->get_request($OID))) {
  141. printf("$state %s\n", $session->error());
  142. $session->close();
  143. exit($STATUSCODE{$state});
  144. }
  145. $session->close();
  146. return($response->{$OID});
  147. }