4
0

check_temp_cpq 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/perl
  2. #
  3. #
  4. # check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical]
  5. #
  6. # NetSaint host script to get the disk usage from NT snmp
  7. #
  8. # Changes and Modifications
  9. # =========================
  10. # 3-Aug-2000 - Xavier Dusart
  11. # Created
  12. # 2003 - Rainer Duffner
  13. # Note: CPQ starts numbering sensors etc. with "1"
  14. BEGIN {
  15. if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
  16. $runtimedir = $1;
  17. $PROGNAME = $2;
  18. }
  19. }
  20. require 5.004;
  21. use POSIX;
  22. #use strict;
  23. use Getopt::Std ;
  24. use BER;
  25. require 'SNMP_Session.pm';
  26. use vars qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME);
  27. use lib $main::runtimedir;
  28. use utils qw($TIMEOUT %ERRORS &print_revision &usage &support );
  29. use snmputil qw(%CPQ_LOCALE %CPQ_FAN_PRESENT %CPQ_FAN_OVERALL_COND %CPQ_FAN_SPEED);
  30. delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
  31. getopts('H:p:C:s:w:c:hV') ;
  32. my $ip_address=undef ;
  33. if ($opt_h) {&help();}
  34. if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA
  35. -Z0-9]*)*)$/) {
  36. $ip_address = $opt_H ;
  37. }
  38. else {
  39. usage();
  40. print "IP-Address format wrong\n";
  41. exit $ERRORS{'UNKNOWN'};
  42. }
  43. #if ($opt_p =~ m/^[0-9]
  44. my $port = $opt_p;
  45. my $community = $opt_C;
  46. my $sensor = $opt_s ;
  47. my $warning = $opt_w;
  48. my $critical = $opt_c;
  49. my $temperature_locale_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,3,0,$sensor );
  50. # not used for the moment - gives no usable output
  51. # if reused, enter at end of list to avoid renumbering !
  52. my $temperature_celsius_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,4,0,$sensor );
  53. my $temperature_threshold_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,5,0,$sensor );
  54. my $temperature_condition_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,6,0,$sensor );
  55. my $count=1 ;
  56. my $label ;
  57. my @r_array=();
  58. my $q ;
  59. my $diff ;
  60. $warning=$warning/100 ;
  61. $crititcal=$critical/100 ;
  62. # get temperature, temperature_threshold bfore shutdown
  63. my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ;
  64. if ($session->get_request_response ($temperature_celsius_oid, $temperature_threshold_oid, $temperature_condition_oid, $temperature_locale_oid )) {
  65. (my $bindings) = $session->decode_get_response ($session->{pdu_buffer});
  66. while ($bindings ne '') {
  67. ($binding, $bindings) = &decode_sequence ($bindings) ;
  68. ($oid,$value) = &decode_by_template ($binding,"%O%@");
  69. $r_array[$count]=&pretty_print($value);
  70. $count++;
  71. }
  72. } else {
  73. print "No response from agent\n";
  74. exit $ERRORS{'CRITICAL'};
  75. }
  76. $result_celsius=$r_array[1];
  77. $result_threshold=$r_array[2];
  78. $result_condition=$r_array[3];
  79. $result_locale=$r_array[4];
  80. if ($result_celsius < 0) {
  81. print "Result is negative - Sensor unavailable ?\n";
  82. exit $ERRORS{'UNKNOWN'};
  83. }
  84. if ($result_threshold==0) {
  85. print "Division by zero \n";
  86. exit $ERRORS{'CRITICAL'};
  87. }
  88. if ($result_condition=="2") {
  89. $result_condition="OK";
  90. }
  91. else {
  92. $result_condition=$result_condition." (other)";
  93. }
  94. $q=$result_celsius/$result_threshold ;
  95. $diff=$result_threshold-$result_celsius ;
  96. if ( $q > $critical ) {
  97. print "Sensor ". $sensor . " (".$CPQ_LOCALE{$result_locale}.") - Critical: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ;
  98. exit $ERRORS{'CRITICAL'} ;
  99. }
  100. elsif ( $q > $warning ) {
  101. print "Sensor ". $sensor . " (".$CPQ_LOCALE{$result_locale}.") - Warning: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ;
  102. exit $ERRORS{'WARNING'} ;
  103. }
  104. else {
  105. print "Sensor " .$sensor. " (".$CPQ_LOCALE{$result_locale}.") - OK: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ;
  106. exit $ERRORS{'OK'} ;
  107. }
  108. sub print_usage () {
  109. print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> [-w <warn>] [-c <crit>]\n";
  110. }
  111. sub print_help () {
  112. print_revision($PROGNAME,'$Revision: 1113 $\n ');
  113. print "Copyright (c) 2003 Rainer Duffner\n ";
  114. print_usage();
  115. print "\n";
  116. print "<host> = IP-Address or DNS-Name of the W2K-Server\n";
  117. print "<port> = SNMP-Port (normaly 161)\n";
  118. print "<community> = SNMP v1 community\n";
  119. print "<sensornumber> = Sensornumber (1, 2, 3 etc.)\n";
  120. print "<warn> = report warning when more than <warn> % of the temperature is reached defaults to 80\n";
  121. print "<crit> = report critical when more than <crit> % of the temperature is reached defaults to 90\n";
  122. }
  123. sub version () {
  124. print_revision($PROGNAME,'$Revision: 1113 $ ');
  125. exit $ERRORS{'OK'};
  126. }
  127. sub help () {
  128. print_help();
  129. exit $ERRORS{'OK'};
  130. }