check_temp_fsc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. BEGIN {
  14. if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
  15. $runtimedir = $1;
  16. $PROGNAME = $2;
  17. }
  18. }
  19. require 5.004;
  20. use POSIX;
  21. #use strict;
  22. use Getopt::Std ;
  23. use BER;
  24. require 'SNMP_Session.pm';
  25. use vars qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME);
  26. use lib $main::runtimedir;
  27. use utils qw($TIMEOUT %ERRORS &print_revision &usage &support);
  28. use snmputil qw(%FSC_LOCALE %FSC_TEMP_CONDITION);
  29. delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
  30. getopts('H:p:C:s:w:c:hV') ;
  31. my $ip_address=undef ;
  32. if ($opt_h) {&help();}
  33. if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA
  34. -Z0-9]*)*)$/) {
  35. $ip_address = $opt_H ;
  36. }
  37. else {
  38. usage();
  39. print "IP-Address format wrong\n";
  40. exit $ERRORS{'UNKNOWN'};
  41. }
  42. #if ($opt_p =~ m/^[0-9]
  43. my $port = $opt_p;
  44. my $community = $opt_C;
  45. my $sensor = $opt_s ;
  46. #my $warning = $opt_w;
  47. #my $critical = $opt_c;
  48. my $temperature_locale_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,4,0,$sensor-1 );
  49. # not used for the moment - gives no usable output
  50. # if reused, enter at end of list to avoid renumbering !
  51. my $temperature_celsius_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,11,0,$sensor-1 );
  52. my $temperature_warning_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,6,0,$sensor-1 );
  53. my $temperature_critical_oid =encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,8,0,$sensor-1 );
  54. my $temperature_condition_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,3,0,$sensor-1 );
  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_warning_oid, $temperature_critical_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_warning=$r_array[2];
  78. $result_critical=$r_array[3];
  79. $result_condition=$r_array[4];
  80. $result_locale=$r_array[5];
  81. if ($result_celsius < 0) {
  82. print "Result is negative - Sensor unavailable ?\n";
  83. exit $ERRORS{'UNKNOWN'};
  84. }
  85. if ($result_warning==0) {
  86. print "Division by zero \n";
  87. exit $ERRORS{'CRITICAL'};
  88. }
  89. if ($result_critical==0) {
  90. print "Division by zero \n";
  91. exit $ERRORS{'CRITICAL'};
  92. }
  93. # $q=$result_celsius/$result_threshold ;
  94. $diff=$result_critical-$result_celsius ;
  95. if ( $result_celsius > $result_critical ) {
  96. print "Sensor ". $sensor . " (".$FSC_LOCALE{$result_locale}.") - Critical: ".$result_celsius." °C - Crit-Threshold:".$result_critical." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition} ."\n" ;
  97. exit $ERRORS{'CRITICAL'} ;
  98. }
  99. elsif ( $result_celsius > $result_warning ) {
  100. print "Sensor ". $sensor . " (".$FSC_LOCALE{$result_locale}.") - Warning: ".$result_celsius." °C - Crit-Threshold:".$result_warning." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition}."\n" ;
  101. exit $ERRORS{'WARNING'} ;
  102. }
  103. else {
  104. print "Sensor " .$sensor. " (".$FSC_LOCALE{$result_locale}.") - OK: ".$result_celsius." °C - Warn-Threshold:".$result_warning." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition} ."\n" ;
  105. exit $ERRORS{'OK'} ;
  106. }
  107. sub print_usage () {
  108. print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> \n";
  109. }
  110. sub print_help () {
  111. print_revision($PROGNAME,'$Revision: 1113 $\n ');
  112. print "Copyright (c) 2003 Rainer Duffner\n ";
  113. print_usage();
  114. print "\n";
  115. print "<host> = IP-Address or DNS-Name of the W2K-Server\n";
  116. print "<port> = SNMP-Port (normaly 161)\n";
  117. print "<community> = SNMP v1 community\n";
  118. print "<drvnumber> = Sensornumber (1, 2, 3 etc.)\n";
  119. }
  120. sub version () {
  121. print_revision($PROGNAME,'$Revision: 1113 $ ');
  122. exit $ERRORS{'OK'};
  123. }
  124. sub help () {
  125. print_help();
  126. exit $ERRORS{'OK'};
  127. }