4 # check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical]
6 # NetSaint host script to get the disk usage from NT snmp
8 # Changes and Modifications
9 # =========================
10 # 3-Aug-2000 - Xavier Dusart
12 # 2003 - Rainer Duffner
13 # Note: CPQ starts numbering sensors etc. with "1"
16 if ($0 =~ m/^(.*?)[\/\\]([^\
/\\]+)$/) {
29 require 'SNMP_Session.pm';
30 use vars
qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME);
31 use lib $main::runtimedir;
32 use utils qw($TIMEOUT %ERRORS &print_revision &usage &support );
34 use snmputil qw(%CPQ_LOCALE %CPQ_FAN_PRESENT %CPQ_FAN_OVERALL_COND %CPQ_FAN_SPEED);
36 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
39 getopts
('H:p:C:s:w:c:hV') ;
41 my $ip_address=undef ;
43 if ($opt_h) {&help
();}
45 if ($opt_H =~ m
/^([0-9]+\
.[0-9]+\
.[0-9]+\
.[0-9]+|[a
-zA
-Z
][-a
-zA
-Z0
-9]*(\
.[a
-zA
-Z
][-a
-zA
47 $ip_address = $opt_H ;
51 print "IP-Address format wrong\n";
52 exit $ERRORS{'UNKNOWN'};
55 #if ($opt_p =~ m/^[0-9]
59 my $community = $opt_C;
65 my $critical = $opt_c;
68 my $temperature_locale_oid = encode_oid
(1,3,6,1,4,1,232,6,2,6,8,1,3,0,$sensor );
69 # not used for the moment - gives no usable output
70 # if reused, enter at end of list to avoid renumbering !
71 my $temperature_celsius_oid = encode_oid
(1,3,6,1,4,1,232,6,2,6,8,1,4,0,$sensor );
72 my $temperature_threshold_oid = encode_oid
(1,3,6,1,4,1,232,6,2,6,8,1,5,0,$sensor );
73 my $temperature_condition_oid = encode_oid
(1,3,6,1,4,1,232,6,2,6,8,1,6,0,$sensor );
79 $warning=$warning/100 ;
80 $crititcal=$critical/100 ;
83 # get temperature, temperature_threshold bfore shutdown
84 my $session=SNMP_Session
->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ;
86 if ($session->get_request_response ($temperature_celsius_oid, $temperature_threshold_oid, $temperature_condition_oid, $temperature_locale_oid )) {
87 (my $bindings) = $session->decode_get_response ($session->{pdu_buffer
});
88 while ($bindings ne '') {
89 ($binding, $bindings) = &decode_sequence
($bindings) ;
90 ($oid,$value) = &decode_by_template
($binding,"%O%@");
91 $r_array[$count]=&pretty_print
($value);
95 print "No response from agent\n";
96 exit $ERRORS{'CRITICAL'};
98 $result_celsius=$r_array[1];
99 $result_threshold=$r_array[2];
100 $result_condition=$r_array[3];
101 $result_locale=$r_array[4];
103 if ($result_celsius < 0) {
104 print "Result is negative - Sensor unavailable ?\n";
105 exit $ERRORS{'UNKNOWN'};
107 if ($result_threshold==0) {
108 print "Division by zero \n";
109 exit $ERRORS{'CRITICAL'};
112 if ($result_condition=="2") {
113 $result_condition="OK";
116 $result_condition=$result_condition." (other)";
118 $q=$result_celsius/$result_threshold ;
119 $diff=$result_threshold-$result_celsius ;
122 if ( $q > $critical ) {
123 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" ;
124 exit $ERRORS{'CRITICAL'} ;
126 elsif ( $q > $warning ) {
127 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" ;
128 exit $ERRORS{'WARNING'} ;
131 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" ;
137 print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> [-w <warn>] [-c <crit>]\n";
141 print_revision
($PROGNAME,'$Revision$\n ');
142 print "Copyright (c) 2003 Rainer Duffner\n ";
145 print "<host> = IP-Address or DNS-Name of the W2K-Server\n";
146 print "<port> = SNMP-Port (normaly 161)\n";
147 print "<community> = SNMP v1 community\n";
148 print "<sensornumber> = Sensornumber (1, 2, 3 etc.)\n";
149 print "<warn> = report warning when more than <warn> % of the temperature is reached defaults to 80\n";
150 print "<crit> = report critical when more than <crit> % of the temperature is reached defaults to 90\n";
154 print_revision
($PROGNAME,'$Revision$ ');