checkciscotemp.pl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. die "Cannot Parse Critical Thresholds\n"
  75. unless (split(/:/,$critical_vals)>=2);
  76. ($inlet_thresh,$outlet_thresh) = @_
  77. }
  78. die unless(defined($inlet_thresh) && defined($outlet_thresh));
  79. if (defined($warning_vals)) {
  80. die "Cannot Parse Critical Thresholds\n"
  81. unless (split(/:/,$warning_vals)>=2);
  82. ($inlet_warn,$outlet_warn) = @_;
  83. }else{
  84. $inlet_warn=$inlet_thresh;
  85. $outlet_warn=$outlet_thresh;
  86. }
  87. alarm($timeout);
  88. $in_temp = &SNMPGET($INTAKE_TEMP);
  89. $out_temp = &SNMPGET($OUTLET_TEMP);
  90. if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {
  91. $state = "OK";
  92. }
  93. elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {
  94. if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
  95. $state = "CRITICAL";
  96. }
  97. else {
  98. $state = "WARNING";
  99. }
  100. }
  101. elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
  102. $state = "CRITICAL";
  103. }
  104. else {
  105. $state = "WARNING";
  106. }
  107. print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n";
  108. exit($STATUSCODE{$state});
  109. sub show_help {
  110. printf("\nPerl envmon temperature plugin for Nagios\n");
  111. printf("Usage:\n");
  112. printf("
  113. check_ciscotemp [options] <hostname>
  114. Options:
  115. -C snmp-community
  116. -p snmp-port
  117. -i input temperature threshold
  118. -o output temperature threshold
  119. ");
  120. printf("Copyright (C)2000 Leland E. Vandervort\n");
  121. printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");
  122. printf("This program is licensed under the terms of the\n");
  123. printf("GNU General Public License\n(check source code for details)\n\n\n");
  124. exit($STATUSCODE{"UNKNOWN"});
  125. }
  126. sub SNMPGET {
  127. $OID = shift;
  128. ($session,$error) = Net::SNMP->session(
  129. Hostname => $hostname,
  130. Community => $community,
  131. Port => $port
  132. );
  133. if(!defined($session)) {
  134. printf("$state %s\n", $error);
  135. exit($STATUSCODE{$state});
  136. }
  137. if(!defined($response = $session->get_request($OID))) {
  138. printf("$state %s\n", $session->error());
  139. $session->close();
  140. exit($STATUSCODE{$state});
  141. }
  142. $session->close();
  143. return($response->{$OID});
  144. }