check_fan_cpq_present 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_f $opt_h $PROGNAME);
  26. use lib $main::runtimedir;
  27. use utils qw($TIMEOUT %ERRORS &print_revision &usage &support);
  28. use snmputil qw(%CPQ_LOCALE %CPQ_FAN_PRESENT %CPQ_FAN_OVERALL_COND %CPQ_FAN_SPEED);
  29. delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
  30. getopts('H:p:C:f: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 $fan = $opt_f ;
  46. #my $err_counter=0 ;
  47. #my $err_status="";
  48. my $fan_locale_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,3,0,$fan );
  49. # not used for the moment - gives no usable output
  50. # if reused, enter at end of list to avoid renumbering !
  51. my $fan_present_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,4,0,$fan );
  52. my $fan_speed_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,6,0,$fan );
  53. my $fan_condition_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,9,0,$fan );
  54. my $count=1 ;
  55. my $label ;
  56. my @r_array=();
  57. my $q ;
  58. my $diff ;
  59. $warning=$warning/100 ;
  60. $crititcal=$critical/100 ;
  61. # get temperature, temperature_threshold bfore shutdown
  62. my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ;
  63. if ($session->get_request_response ($fan_present_oid, $fan_locale_oid, $fan_speed_oid, $fan_condition_oid )) {
  64. (my $bindings) = $session->decode_get_response ($session->{pdu_buffer});
  65. while ($bindings ne '') {
  66. ($binding, $bindings) = &decode_sequence ($bindings) ;
  67. ($oid,$value) = &decode_by_template ($binding,"%O%@");
  68. $r_array[$count]=&pretty_print($value);
  69. $count++;
  70. }
  71. } else {
  72. print "No response from agent\n";
  73. exit $ERRORS{'CRITICAL'};
  74. }
  75. $result_fan_present= $r_array[1];
  76. $result_fan_locale= $r_array[2];
  77. $result_fan_speed= $r_array[3];
  78. $result_fan_condition=$r_array[4];
  79. if ( $result_fan_present != 3 || $result_fan_speed !=2 ) {
  80. print "Fan ". $fan . " ".$CPQ_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - Critical: Fan ".$CPQ_FAN_PRESENT{$result_fan_present}.". Speed: ". $CPQ_FAN_SPEED{$result_fan_speed}.". Overall condition: ". $CPQ_FAN_OVERALL_COND{$result_fan_condition} ."\n" ;
  81. exit $ERRORS{'CRITICAL'} ;
  82. }
  83. else {
  84. print "Fan " .$fan . " ".$CPQ_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - OK: Fan ".$CPQ_FAN_PRESENT{$result_fan_present}.". Speed: ". $CPQ_FAN_SPEED{$result_fan_speed}.". Overall condition: ". $CPQ_FAN_OVERALL_COND{$result_fan_condition} ."\n" ;
  85. exit $ERRORS{'OK'} ;
  86. }
  87. sub print_usage () {
  88. print "Usage: $PROGNAME -H <host> -p <port> -C <community> -f <fannumber>\n";
  89. }
  90. sub print_help () {
  91. print_revision($PROGNAME,'$Revision: 1113 $\n ');
  92. print "Copyright (c) 2003 Rainer Duffner\n ";
  93. print_usage();
  94. print "\n";
  95. print "<host> = IP-Address or DNS-Name of the W2K-Server\n";
  96. print "<port> = SNMP-Port (normaly 161)\n";
  97. print "<community> = SNMP v1 community\n";
  98. print "<fannumber> = Fannumber (1, 2, 3 etc.)\n";
  99. }
  100. sub version () {
  101. print_revision($PROGNAME,'$Revision: 1113 $ ');
  102. exit $ERRORS{'OK'};
  103. }
  104. sub help () {
  105. print_help();
  106. exit $ERRORS{'OK'};
  107. }