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