96862e1c323edaad5bc89a9742c99368448101a5
1 #!/usr/bin/perl
2 # cm@financial.com 07/2002
3 use strict;
4 use Net::SNMP;
6 if ($#ARGV ne 3) {
7 print "Worng number of Arguments\n";
8 exit 1;
9 }
12 my ($host, $device, $warnpercent, $errpercent) = @ARGV;
13 if ($warnpercent >= $errpercent) {
14 print "Errorratio must be higher then Warnratio!\n";
15 exit 1;
16 }
18 my ($session, $error) = Net::SNMP->session(
19 -hostname => $host,
20 -nonblocking => 0x0,
21 -username => 'XXXXX',
22 -authpassword => 'XXXXXXXX',
23 -authprotocol => 'md5',
24 -version => '3',
25 );
27 if ($@) {
28 print "SNMP-Error occured";
29 exit 1;
30 }
31 my $result=undef;
34 my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device";
35 my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device";
36 #my $deviceName=".1.3.6.1.2.1.25.3.7.1.2.1536.$device";
37 my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device";
38 my @OID=($deviceSize, $deviceUsed, $deviceName);
39 $result = $session->get_request(
40 -varbindlist => \@OID,
41 );
43 if (!defined($result)) {
44 printf("ERROR: %s.\n", $session->error);
45 $session->close;
46 exit 1;
47 }
49 my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
51 if ($ratio > $errpercent){
52 printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
53 exit 2;
54 }
55 if ($ratio > $warnpercent){
56 printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
57 exit 1;
58 }
60 printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
61 exit 0;