summaryrefslogtreecommitdiffstats
path: root/contrib/check_disk_snmp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_disk_snmp.pl')
-rw-r--r--contrib/check_disk_snmp.pl44
1 files changed, 28 insertions, 16 deletions
diff --git a/contrib/check_disk_snmp.pl b/contrib/check_disk_snmp.pl
index 96862e1c..a09343dc 100644
--- a/contrib/check_disk_snmp.pl
+++ b/contrib/check_disk_snmp.pl
@@ -2,25 +2,39 @@
2# cm@financial.com 07/2002 2# cm@financial.com 07/2002
3use strict; 3use strict;
4use Net::SNMP; 4use Net::SNMP;
5use Getopt::Std;
5 6
6if ($#ARGV ne 3) { 7my %opts =(
7 print "Worng number of Arguments\n"; 8 u => 'nobody', # snmp user
9 l => 'authNoPriv', # snmp security level
10 a => 'MD5', # snmp authentication protocol
11 A => 'nopass', # authentication protocol pass phrase.
12 x => 'DES', # privacy protocol
13 m => 'localhost', # host
14 d => 1, # devicenumber
15 w => 70, # warnratio
16 c => 85, # critical ratio
17 h => 0,
18 );
19
20getopts('m:u:l:a:A:x:d:w:c:h',\%opts);
21
22if ( $opts{'h'} ) {
23 print "Usage: $0 [ -u <username> ] [ -l <snmp security level>] [ -a <snmp authentication protocol> ] [ -A <authentication protocol pass phrase> ] [ -x <snmp privacy protocol> ] [ -m <hostname>] [ -d <devicenumber> ] [ -w <warning ratio> ] [ -c <critical ratio ]\n";
8 exit 1; 24 exit 1;
9} 25}
10 26
11 27if ($opts{'w'} >= $opts{'c'}) {
12my ($host, $device, $warnpercent, $errpercent) = @ARGV;
13if ($warnpercent >= $errpercent) {
14 print "Errorratio must be higher then Warnratio!\n"; 28 print "Errorratio must be higher then Warnratio!\n";
15 exit 1; 29 exit 1;
16} 30}
17 31
18my ($session, $error) = Net::SNMP->session( 32my ($session, $error) = Net::SNMP->session(
19 -hostname => $host, 33 -hostname => $opts{'m'},
20 -nonblocking => 0x0, 34 -nonblocking => 0x0,
21 -username => 'XXXXX', 35 -username => $opts{'u'},
22 -authpassword => 'XXXXXXXX', 36 -authpassword => $opts{'A'},
23 -authprotocol => 'md5', 37 -authprotocol => $opts{'a'},
24 -version => '3', 38 -version => '3',
25 ); 39 );
26 40
@@ -31,10 +45,9 @@ if ($@) {
31my $result=undef; 45my $result=undef;
32 46
33 47
34my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device"; 48my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$opts{'d'}";
35my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device"; 49my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$opts{'d'}";
36#my $deviceName=".1.3.6.1.2.1.25.3.7.1.2.1536.$device"; 50my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$opts{'d'}";
37my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device";
38my @OID=($deviceSize, $deviceUsed, $deviceName); 51my @OID=($deviceSize, $deviceUsed, $deviceName);
39$result = $session->get_request( 52$result = $session->get_request(
40 -varbindlist => \@OID, 53 -varbindlist => \@OID,
@@ -48,15 +61,14 @@ if (!defined($result)) {
48 61
49my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize}; 62my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
50 63
51if ($ratio > $errpercent){ 64if ($ratio > $opts{'c'}){
52 printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); 65 printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
53 exit 2; 66 exit 2;
54} 67}
55if ($ratio > $warnpercent){ 68if ($ratio > $opts{'w'}){
56 printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); 69 printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
57 exit 1; 70 exit 1;
58} 71}
59 72
60printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); 73printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
61exit 0; 74exit 0;
62